Add pwd utility and performance to cat
This commit is contained in:
parent
049289f452
commit
2f6f90dce4
4 changed files with 23 additions and 5 deletions
16
cat.nim
16
cat.nim
|
|
@ -3,11 +3,19 @@ import common
|
||||||
|
|
||||||
proc catFile(file:string) =
|
proc catFile(file:string) =
|
||||||
if not existsFile(file):
|
if not existsFile(file):
|
||||||
echo "cat: " & file & ": No such file or directory"
|
err "cat: " & file & ": No such file or directory"
|
||||||
system.quit 1
|
system.quit 1
|
||||||
var s = newFileStream(file, fmRead)
|
const bufSize = 1024
|
||||||
while not s.atEnd:
|
var
|
||||||
write(stdout, s.readChar)
|
f = open(file, fmRead)
|
||||||
|
buffer {.noinit.}: array[bufSize, char]
|
||||||
|
while true:
|
||||||
|
let readBytes = readBuffer(f, addr(buffer[0]), bufSize)
|
||||||
|
if readBytes == 0:
|
||||||
|
break
|
||||||
|
discard writeBuffer(stdout, addr(buffer[0]), readBytes)
|
||||||
|
if readBytes < bufSize:
|
||||||
|
break
|
||||||
|
|
||||||
proc catStdin() =
|
proc catStdin() =
|
||||||
var line = ""
|
var line = ""
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,6 @@
|
||||||
|
|
||||||
const
|
const
|
||||||
nimbaseVersion* = "0.0.1"
|
nimbaseVersion* = "0.0.1"
|
||||||
|
|
||||||
|
proc err*(x:string) =
|
||||||
|
writeLine(stderr, x)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ requires "nim >= 0.19.0"
|
||||||
requires "cligen >= 0.9.19"
|
requires "cligen >= 0.9.19"
|
||||||
requires "stint >= 0.0.1"
|
requires "stint >= 0.0.1"
|
||||||
|
|
||||||
bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "rm", "seq", "sleep", "sub", "tee", "touch", "true", "yes"]
|
bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "pwd", "rm", "seq", "sleep", "sub", "tee", "touch", "true", "yes"]
|
||||||
|
|
||||||
binDir = "bin"
|
binDir = "bin"
|
||||||
|
|
|
||||||
7
pwd.nim
Normal file
7
pwd.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import os, cligen
|
||||||
|
import common
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
echo getCurrentDir()
|
||||||
|
|
||||||
|
dispatch(main, version=("version", nimbaseVersion))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue