raz / commit 5b0b3f89

commit
5b0b3f891508e711d76fcc1d8ef8c557f80a9336
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
52ee177d
Files.argCount: the number of arguments, beside Files.arg

patch · log

2 files changed, +10 -1

doc/raz-lib.md (history) modified +1 -0

@@ -1107,6 +1107,7 @@
11071107
11081108 ```
11091109 module Files;
1110+proc argCount*: INT; (* how many arguments there are, the program's name included *)
11101111 proc arg*(i: INT): []const U8; (* argument i; 0 is the program's name; "" if there is none *)
11111112 proc read*(path: []const U8; var b: Buf.Buf): BOOL; (* the whole file added to b *)
11121113 proc load*(path: []const U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)

lib/Files.raz (history) modified +9 -1

@@ -7,6 +7,13 @@
77 import Sys, Buf, Heap, Rt;
88 import SYSTEM;
99
10+(* The number of arguments, the program's name included; argument i
11+ exists for i below it. *)
12+proc argCount*: INT;
13+begin
14+ return ARGC();
15+end;
16+
1017 (* Argument i, a C string, as a slice; empty if there is no argument i,
1118 as for i below 0 or from ARGC() on. *)
1219 proc arg*(i: INT): []const U8;
@@ -327,7 +334,8 @@
327334 if load("/tmp/raz-files-test", b) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end;
328335 if load("/", b) # -21 then Rt.stop("Files.load: a directory"); end;
329336 if read("/", b) or (b.len # 6) then Rt.stop("Files.read: a directory"); end;
330- if (LEN(arg(ARGC())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end;
337+ if (argCount() < 1) or (LEN(arg(0)) = 0) then Rt.stop("Files.argCount"); end;
338+ if (LEN(arg(argCount())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end;
331339 Buf.done(b);
332340 testPipe;
333341 testTree;