diff options
author | Andreas Rumpf <andreasrumpf@noname> | 2009-09-15 23:22:22 +0200 |
---|---|---|
committer | Andreas Rumpf <andreasrumpf@noname> | 2009-09-15 23:22:22 +0200 |
commit | 66a7e3d37c0303997a6b1a3b7ec263dfb8c07748 (patch) | |
tree | 40ae1ab8aeb9086b7310ea73ab8a2ed6b597f88b /lib/system/sysio.nim | |
parent | 300430fbba28b408f7ac86ca46b03d9d50839399 (diff) | |
download | Nim-66a7e3d37c0303997a6b1a3b7ec263dfb8c07748.tar.gz |
added tools and web dirs
Diffstat (limited to 'lib/system/sysio.nim')
-rwxr-xr-x[-rw-r--r--] | lib/system/sysio.nim | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index c9db48d51..8b6d0e285 100644..100755 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -18,7 +18,7 @@ proc fputs(c: cstring, f: TFile) {.importc: "fputs", noDecl.} proc fgets(c: cstring, n: int, f: TFile): cstring {.importc: "fgets", noDecl.} -proc fgetc(stream: TFile): int {.importc: "fgetc", nodecl.} +proc fgetc(stream: TFile): cint {.importc: "fgetc", nodecl.} proc ungetc(c: cint, f: TFile) {.importc: "ungetc", nodecl.} proc putc(c: Char, stream: TFile) {.importc: "putc", nodecl.} proc fprintf(f: TFile, frmt: CString) {.importc: "fprintf", nodecl, varargs.} @@ -36,11 +36,9 @@ var proc rawReadLine(f: TFile, result: var string) = # of course this could be optimized a bit; but IO is slow anyway... # and it was difficult to get this CORRECT with Ansi C's methods - var - c: cint setLen(result, 0) # reuse the buffer! while True: - c = fgetc(f) + var c = fgetc(f) if c < 0'i32: break # EOF if c == 10'i32: break # LF if c == 13'i32: # CR @@ -68,6 +66,8 @@ proc write(f: TFile, c: Char) = putc(c, f) proc write(f: TFile, a: openArray[string]) = for x in items(a): write(f, x) +#{.error: "for debugging.".} + proc readFile(filename: string): string = var f: TFile try: @@ -85,11 +85,9 @@ proc readFile(filename: string): string = proc EndOfFile(f: TFile): bool = # do not blame me; blame the ANSI C standard this is so brain-damaged - var - c: int - c = fgetc(f) + var c = fgetc(f) ungetc(c, f) - return c == -1 + return c == -1'i32 proc writeln[Ty](f: TFile, x: Ty) = write(f, x) |