From 7caac67689d1cb5667b56c8652c3e73ac39c0fac Mon Sep 17 00:00:00 2001 From: Joseph Montanaro Date: Mon, 26 Jul 2021 20:54:13 -0700 Subject: [PATCH] configurable output dir --- counts.txt | 0 dictionary.txt | 0 passphrase.nimble | 18 +++--------------- src/process.nim | 14 +++++++++++++- 4 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 counts.txt delete mode 100644 dictionary.txt diff --git a/counts.txt b/counts.txt deleted file mode 100644 index e69de29..0000000 diff --git a/dictionary.txt b/dictionary.txt deleted file mode 100644 index e69de29..0000000 diff --git a/passphrase.nimble b/passphrase.nimble index fabdfc4..5e47488 100644 --- a/passphrase.nimble +++ b/passphrase.nimble @@ -26,25 +26,13 @@ proc runCmd(command: string, input = "", cache = ""): string = quit(exitCode) result = output -proc pathExists(filename: string): bool = - let (output, code) = gorgeEx("ls " & filename) - return code == 0 - task(dictionary, "Generate dictionary from BNC XML files"): - if not pathExists("BNC"): - quit("Cannot build dictionary: BNC data files not found.", 1) echo "Building dictionary" - echo runCmd("nim c --run --threads:on -d:release -d:lto src/process.nim") - - -task(showexec, "this is a test"): - let (output, exitCode) = gorgeEx("ls BNC") - echo output - echo exitCode - + let output = runCmd("nim c --run --threads:on -d:release -d:lto src/process.nim BNC/2554/download/Texts src/") + echo output.strip().splitlines()[^1] before(build): - if not pathExists("src/dictionary.txt"): + if not dirExists("src/dictionary.txt"): dictionaryTask() diff --git a/src/process.nim b/src/process.nim index 4b1bffb..c4badb7 100644 --- a/src/process.nim +++ b/src/process.nim @@ -51,6 +51,9 @@ when isMainModule: paramStr(1) else: r"../BNC/2554/download/Texts/" + + if not dirExists(basePath): + quit("Could not locate datafiles: directory " & basePath & " does not exist.") var paths: seq[string] for path in walkDirRec(basePath): @@ -76,6 +79,15 @@ when isMainModule: counts.inc(word, count) counts.sort() - save(counts, "dictionary.txt", "counts.txt") + let outPath = + if paramCount() > 1: + paramStr(2) + else: + "." + + let + dPath = joinPath(outPath, "dictionary.txt") + cPath = joinPath(outPath, "counts.txt") + save(counts, dPath, cPath) echo "Done. Finished in ", (getMonoTime() - start).inMilliseconds.float / 1000, " seconds."