26 lines
602 B
Nim
26 lines
602 B
Nim
import cligen, os, streams
|
|
import common
|
|
|
|
proc catFile(file:string) =
|
|
if not existsFile(file):
|
|
echo "cat: " & file & ": No such file or directory"
|
|
system.quit 1
|
|
var s = newFileStream(file, fmRead)
|
|
while not s.atEnd:
|
|
write(stdout, s.readChar)
|
|
|
|
proc catStdin() =
|
|
var line = ""
|
|
while stdin.readLine(line):
|
|
echo 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))
|