| 1 |
/* do not edit automatically generated by mc from Args. */ |
| 2 |
/* Args.mod provide access to command line arguments. |
| 3 |
|
| 4 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 5 |
Contributed by Gaius Mulley <[email protected]>. |
| 6 |
|
| 7 |
This file is part of GNU Modula-2. |
| 8 |
|
| 9 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 3, or (at your option) |
| 12 |
any later version. |
| 13 |
|
| 14 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 15 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
General Public License for more details. |
| 18 |
|
| 19 |
Under Section 7 of GPL version 3, you are granted additional |
| 20 |
permissions described in the GCC Runtime Library Exception, version |
| 21 |
3.1, as published by the Free Software Foundation. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License and |
| 24 |
a copy of the GCC Runtime Library Exception along with this program; |
| 25 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 26 |
<http://www.gnu.org/licenses/>. */ |
| 27 |
|
| 28 |
#include "config.h" |
| 29 |
#include "system.h" |
| 30 |
#include <stdbool.h> |
| 31 |
# if !defined (PROC_D) |
| 32 |
# define PROC_D |
| 33 |
typedef void (*PROC_t) (void); |
| 34 |
typedef struct { PROC_t proc; } PROC; |
| 35 |
# endif |
| 36 |
|
| 37 |
#define _Args_C |
| 38 |
|
| 39 |
#include "GArgs.h" |
| 40 |
# include "GUnixArgs.h" |
| 41 |
# include "GASCII.h" |
| 42 |
|
| 43 |
# define MaxArgs 255 |
| 44 |
# define MaxString 4096 |
| 45 |
typedef struct Args__T2_a Args__T2; |
| 46 |
|
| 47 |
typedef Args__T2 *Args__T1; |
| 48 |
|
| 49 |
typedef struct Args__T3_a Args__T3; |
| 50 |
|
| 51 |
struct Args__T2_a { Args__T3 * array[MaxArgs+1]; }; |
| 52 |
struct Args__T3_a { char array[MaxString+1]; }; |
| 53 |
static Args__T1 Source; |
| 54 |
|
| 55 |
/* |
| 56 |
GetArg - returns the nth argument from the command line. |
| 57 |
The success of the operation is returned. |
| 58 |
*/ |
| 59 |
|
| 60 |
extern "C" bool Args_GetArg (char *a, unsigned int _a_high, unsigned int n); |
| 61 |
|
| 62 |
/* |
| 63 |
Narg - returns the number of arguments available from |
| 64 |
command line. |
| 65 |
*/ |
| 66 |
|
| 67 |
extern "C" unsigned int Args_Narg (void); |
| 68 |
|
| 69 |
|
| 70 |
/* |
| 71 |
GetArg - returns the nth argument from the command line. |
| 72 |
The success of the operation is returned. |
| 73 |
*/ |
| 74 |
|
| 75 |
extern "C" bool Args_GetArg (char *a, unsigned int _a_high, unsigned int n) |
| 76 |
{ |
| 77 |
int i; |
| 78 |
unsigned int High; |
| 79 |
unsigned int j; |
| 80 |
|
| 81 |
i = (int ) (n); |
| 82 |
j = 0; |
| 83 |
High = _a_high; |
| 84 |
if (i < (UnixArgs_GetArgC ())) |
| 85 |
{ |
| 86 |
Source = static_cast<Args__T1> (UnixArgs_GetArgV ()); |
| 87 |
while ((j < High) && ((*(*Source).array[i]).array[j] != ASCII_nul)) |
| 88 |
{ |
| 89 |
const_cast<char *>(a)[j] = (*(*Source).array[i]).array[j]; |
| 90 |
j += 1; |
| 91 |
} |
| 92 |
} |
| 93 |
if (j <= High) |
| 94 |
{ |
| 95 |
const_cast<char *>(a)[j] = ASCII_nul; |
| 96 |
} |
| 97 |
return i < (UnixArgs_GetArgC ()); |
| 98 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 99 |
__builtin_unreachable (); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
/* |
| 104 |
Narg - returns the number of arguments available from |
| 105 |
command line. |
| 106 |
*/ |
| 107 |
|
| 108 |
extern "C" unsigned int Args_Narg (void) |
| 109 |
{ |
| 110 |
return UnixArgs_GetArgC (); |
| 111 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 112 |
__builtin_unreachable (); |
| 113 |
} |
| 114 |
|
| 115 |
extern "C" void _M2_Args_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 116 |
{ |
| 117 |
} |
| 118 |
|
| 119 |
extern "C" void _M2_Args_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 120 |
{ |
| 121 |
} |