From 5b0b3f891508e711d76fcc1d8ef8c557f80a9336 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:10:16 +0000 Subject: [PATCH] Files.argCount: the number of arguments, beside Files.arg --- diff --git a/doc/raz-lib.md b/doc/raz-lib.md index ba32914..017a494 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -1107,6 +1107,7 @@ ``` module Files; +proc argCount*: INT; (* how many arguments there are, the program's name included *) proc arg*(i: INT): []const U8; (* argument i; 0 is the program's name; "" if there is none *) proc read*(path: []const U8; var b: Buf.Buf): BOOL; (* the whole file added to b *) proc load*(path: []const U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *) diff --git a/lib/Files.raz b/lib/Files.raz index 8eaa801..a62457a 100644 --- a/lib/Files.raz +++ b/lib/Files.raz @@ -7,6 +7,13 @@ import Sys, Buf, Heap, Rt; import SYSTEM; +(* The number of arguments, the program's name included; argument i + exists for i below it. *) +proc argCount*: INT; +begin + return ARGC(); +end; + (* Argument i, a C string, as a slice; empty if there is no argument i, as for i below 0 or from ARGC() on. *) proc arg*(i: INT): []const U8; @@ -327,7 +334,8 @@ if load("/tmp/raz-files-test", b) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end; if load("/", b) # -21 then Rt.stop("Files.load: a directory"); end; if read("/", b) or (b.len # 6) then Rt.stop("Files.read: a directory"); end; - if (LEN(arg(ARGC())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end; + if (argCount() < 1) or (LEN(arg(0)) = 0) then Rt.stop("Files.argCount"); end; + if (LEN(arg(argCount())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end; Buf.done(b); testPipe; testTree;