Add rev utility

This commit is contained in:
joachimschmidt557 2019-04-03 21:25:10 +02:00
parent 33a314f900
commit 3778f7aad6
4 changed files with 32 additions and 4 deletions

View file

@ -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:

View file

@ -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"

26
rev.nim
View file

@ -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))

View file

@ -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)