diff --git a/cat.nim b/cat.nim index 5dd19a9..72d8a3a 100644 --- a/cat.nim +++ b/cat.nim @@ -18,9 +18,8 @@ proc catFile(file:string) = break proc catStdin() = - var line = "" - while stdin.readLine(line): - echo line + for line in lines(stdin): + writeLine(stdout, line) proc main(files:seq[string]) = if files.len == 0: diff --git a/nimbase.nimble b/nimbase.nimble index aab2915..5ce89db 100644 --- a/nimbase.nimble +++ b/nimbase.nimble @@ -8,6 +8,6 @@ requires "nim >= 0.19.0" requires "cligen >= 0.9.19" requires "stint >= 0.0.1" -bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "nl", "pwd", "rm", "seq", "shuf", "sleep", "sub", "tac", "tee", "touch", "true", "yes"] +bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "nl", "pwd", "rev", "rm", "seq", "shuf", "sleep", "sub", "tac", "tee", "touch", "true", "yes"] binDir = "bin" diff --git a/rev.nim b/rev.nim index e69de29..77606f0 100644 --- a/rev.nim +++ b/rev.nim @@ -0,0 +1,26 @@ +import cligen, os, streams, unicode +import common + +proc catFile(file:string) = + if not existsFile(file): + err "rev: " & file & ": No such file or directory" + system.quit 1 + var + f = open(file, fmRead) + for line in lines(f): + writeLine(stdout, reversed(line)) + +proc catStdin() = + for line in lines(stdin): + writeLine(stdout, reversed(line)) + +proc main(files:seq[string]) = + if files.len == 0: + catStdin() + for file in files: + if file == "-": + catStdin() + else: + catFile(file) + +dispatch(main, version=("version", nimbaseVersion)) diff --git a/sleep.nim b/sleep.nim index d7e37c2..cd6928d 100644 --- a/sleep.nim +++ b/sleep.nim @@ -1,6 +1,9 @@ import os, cligen, sequtils import common +proc timeToSecs(time:string): int = + result = 0 + proc main(secs:seq[int]) = sleep(secs.foldl(a + b) * 1000)