Add rev utility
This commit is contained in:
parent
33a314f900
commit
3778f7aad6
4 changed files with 32 additions and 4 deletions
26
rev.nim
26
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue