| 1 |
(* Args.mod provide access to command line arguments. |
| 2 |
|
| 3 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
Under Section 7 of GPL version 3, you are granted additional |
| 19 |
permissions described in the GCC Runtime Library Exception, version |
| 20 |
3.1, as published by the Free Software Foundation. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License and |
| 23 |
a copy of the GCC Runtime Library Exception along with this program; |
| 24 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 25 |
<http://www.gnu.org/licenses/>. *) |
| 26 |
|
| 27 |
IMPLEMENTATION MODULE Args ; |
| 28 |
|
| 29 |
|
| 30 |
FROM UnixArgs IMPORT GetArgC, GetArgV ; |
| 31 |
FROM ASCII IMPORT nul ; |
| 32 |
|
| 33 |
|
| 34 |
CONST |
| 35 |
MaxArgs = 255 ; |
| 36 |
MaxString = 4096 ; |
| 37 |
|
| 38 |
|
| 39 |
(* |
| 40 |
Source allows us to examine the ArgV contents. |
| 41 |
*) |
| 42 |
|
| 43 |
VAR |
| 44 |
Source: POINTER TO ARRAY [0..MaxArgs] OF |
| 45 |
POINTER TO ARRAY [0..MaxString] OF CHAR ; |
| 46 |
|
| 47 |
|
| 48 |
(* |
| 49 |
GetArg - returns the nth argument from the command line. |
| 50 |
The success of the operation is returned. |
| 51 |
*) |
| 52 |
|
| 53 |
PROCEDURE GetArg (VAR a: ARRAY OF CHAR; n: CARDINAL) : BOOLEAN ; |
| 54 |
VAR |
| 55 |
i : INTEGER ; |
| 56 |
High, |
| 57 |
j : CARDINAL ; |
| 58 |
BEGIN |
| 59 |
i := VAL (INTEGER, n) ; |
| 60 |
j := 0 ; |
| 61 |
High := HIGH(a) ; |
| 62 |
IF i < GetArgC () |
| 63 |
THEN |
| 64 |
Source := GetArgV () ; |
| 65 |
WHILE (j<High) AND (Source^[i]^[j]#nul) DO |
| 66 |
a[j] := Source^[i]^[j] ; |
| 67 |
INC(j) |
| 68 |
END |
| 69 |
END ; |
| 70 |
IF j<=High |
| 71 |
THEN |
| 72 |
a[j] := nul |
| 73 |
END ; |
| 74 |
RETURN i < GetArgC () |
| 75 |
END GetArg ; |
| 76 |
|
| 77 |
|
| 78 |
(* |
| 79 |
Narg - returns the number of arguments available from |
| 80 |
command line. |
| 81 |
*) |
| 82 |
|
| 83 |
PROCEDURE Narg () : CARDINAL ; |
| 84 |
BEGIN |
| 85 |
RETURN GetArgC () |
| 86 |
END Narg ; |
| 87 |
|
| 88 |
|
| 89 |
END Args. |