| | @@ -3,10 +3,12 @@ |
| 3 | 3 | module Files; |
| 4 | 4 | import Sys, Buf, Heap, Rt; |
| 5 | 5 | |
| 6 | | -(* Argument i, a C string, as a slice. *) |
| 6 | +(* Argument i, a C string, as a slice; empty if there is no argument i, |
| 7 | + as for i below 0 or from ARGC() on. *) |
| 7 | 8 | proc arg*(i: INT): []U8; |
| 8 | 9 | var s: ^U8; n: INT; |
| 9 | 10 | begin |
| 11 | + if (i < 0) or (i >= ARGC()) then return ""; end; |
| 10 | 12 | s := ARGV()[i]; |
| 11 | 13 | n := 0; |
| 12 | 14 | while s[n] # 0 do INC(n); end; |
| | @@ -65,6 +67,7 @@ |
| 65 | 67 | if load("/tmp/raz-files-test", b) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end; |
| 66 | 68 | if load("/", b) # -21 then Rt.stop("Files.load: a directory"); end; |
| 67 | 69 | if read("/", b) or (b.len # 6) then Rt.stop("Files.read: a directory"); end; |
| 70 | + if (LEN(arg(ARGC())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end; |
| 68 | 71 | Buf.done(b); |
| 69 | 72 | end; |
| 70 | 73 | |