Line -... |
Line 1... |
- |
|
1 |
/*
|
- |
|
2 |
* Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
|
- |
|
3 |
* All rights reserved.
|
- |
|
4 |
*
|
- |
|
5 |
* Redistribution and use in source and binary forms, with or without
|
- |
|
6 |
* modification, are permitted provided that the following conditions are met:
|
- |
|
7 |
*
|
- |
|
8 |
* 1. Redistributions of source code must retain the above copyright notice,
|
- |
|
9 |
* this list of conditions and the following disclaimer.
|
- |
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
- |
|
11 |
* this list of conditions and the following disclaimer in the documentation
|
- |
|
12 |
* and/or other materials provided with the distribution.
|
- |
|
13 |
* 3. Neither the name of The TenDRA Project nor the names of its contributors
|
- |
|
14 |
* may be used to endorse or promote products derived from this software
|
- |
|
15 |
* without specific, prior written permission.
|
- |
|
16 |
*
|
- |
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
- |
|
18 |
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
- |
|
19 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
- |
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
- |
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
- |
|
22 |
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
- |
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
- |
|
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
- |
|
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
- |
|
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
- |
|
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
- |
|
28 |
*
|
- |
|
29 |
* $Id$
|
- |
|
30 |
*/
|
1 |
/*
|
31 |
/*
|
2 |
Crown Copyright (c) 1997
|
32 |
Crown Copyright (c) 1997
|
3 |
|
33 |
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
34 |
This TenDRA(r) Computer Program is subject to Copyright
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
35 |
owned by the United Kingdom Secretary of State for Defence
|
6 |
acting through the Defence Evaluation and Research Agency
|
36 |
acting through the Defence Evaluation and Research Agency
|
7 |
(DERA). It is made available to Recipients with a
|
37 |
(DERA). It is made available to Recipients with a
|
8 |
royalty-free licence for its use, reproduction, transfer
|
38 |
royalty-free licence for its use, reproduction, transfer
|
9 |
to other parties and amendment for any purpose not excluding
|
39 |
to other parties and amendment for any purpose not excluding
|
10 |
product development provided that any such use et cetera
|
40 |
product development provided that any such use et cetera
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
41 |
shall be deemed to be acceptance of the following conditions:-
|
12 |
|
42 |
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
43 |
(1) Its Recipients shall ensure that this Notice is
|
14 |
reproduced upon any copies or amended versions of it;
|
44 |
reproduced upon any copies or amended versions of it;
|
15 |
|
45 |
|
16 |
(2) Any amended version of it shall be clearly marked to
|
46 |
(2) Any amended version of it shall be clearly marked to
|
17 |
show both the nature of and the organisation responsible
|
47 |
show both the nature of and the organisation responsible
|
18 |
for the relevant amendment or amendments;
|
48 |
for the relevant amendment or amendments;
|
19 |
|
49 |
|
20 |
(3) Its onward transfer from a recipient to another
|
50 |
(3) Its onward transfer from a recipient to another
|
21 |
party shall be deemed to be that party's acceptance of
|
51 |
party shall be deemed to be that party's acceptance of
|
22 |
these conditions;
|
52 |
these conditions;
|
23 |
|
53 |
|
24 |
(4) DERA gives no warranty or assurance as to its
|
54 |
(4) DERA gives no warranty or assurance as to its
|
25 |
quality or suitability for any purpose and DERA accepts
|
55 |
quality or suitability for any purpose and DERA accepts
|
26 |
no liability whatsoever in relation to any use to which
|
56 |
no liability whatsoever in relation to any use to which
|
27 |
it may be put.
|
57 |
it may be put.
|
28 |
*/
|
58 |
*/
|
Line 108... |
Line 138... |
108 |
* AT_FOLLOWING
|
138 |
* AT_FOLLOWING
|
109 |
*
|
139 |
*
|
110 |
* This is the type of an option with one following argument. The procedure
|
140 |
* This is the type of an option with one following argument. The procedure
|
111 |
* will be called with the option that was selected, the error closure, the
|
141 |
* will be called with the option that was selected, the error closure, the
|
112 |
* option closure, and the argument to the option.
|
142 |
* option closure, and the argument to the option.
|
113 |
*
|
143 |
*
|
114 |
* AT_EMPTY
|
144 |
* AT_EMPTY
|
115 |
*
|
145 |
*
|
116 |
* This is the type of an option with no argument. The procedure will be
|
146 |
* This is the type of an option with no argument. The procedure will be
|
117 |
* called with the option that was selected, the error closure, and the option
|
147 |
* called with the option that was selected, the error closure, and the option
|
118 |
* closure.
|
148 |
* closure.
|
Line 122... |
Line 152... |
122 |
* This is the type of an option with two following arguments. The procedure
|
152 |
* This is the type of an option with two following arguments. The procedure
|
123 |
* will be called with the option that was selected, the error closure, the
|
153 |
* will be called with the option that was selected, the error closure, the
|
124 |
* option closure, and the arguments to the option.
|
154 |
* option closure, and the arguments to the option.
|
125 |
*
|
155 |
*
|
126 |
* AT_FOLLOWING3
|
156 |
* AT_FOLLOWING3
|
127 |
*
|
157 |
*
|
128 |
* This is the type of an option with three following arguments. The
|
158 |
* This is the type of an option with three following arguments. The
|
129 |
* procedure will be called with the option that was selected, the error
|
159 |
* procedure will be called with the option that was selected, the error
|
130 |
* closure, the option closure, and the arguments to the option.
|
160 |
* closure, the option closure, and the arguments to the option.
|
131 |
*
|
161 |
*
|
132 |
* Note that if a matched option is a short option, then the current position
|
162 |
* Note that if a matched option is a short option, then the current position
|
133 |
* is passed to the option handling procedure as the option name. For long
|
163 |
* is passed to the option handling procedure as the option name. For long
|
134 |
* options, the entire option string is passed. If the handler is interested
|
164 |
* options, the entire option string is passed. If the handler is interested
|
135 |
* in the option name, it should check the start of this string: if it is '-'
|
165 |
* in the option name, it should check the start of this string: if it is '-'
|
136 |
* or '+' it should be a long option; otherwise it should be a short option.
|
166 |
* or '+' it should be a long option; otherwise it should be a short option.
|
137 |
*
|
167 |
*
|
138 |
** Type: ArgProcP
|
168 |
** Type: ArgProcP
|
139 |
** Repr: void (*) (CStringP, ArgUsageP, GenericP, ...)
|
169 |
** Repr: void (*) (CStringP, ArgUsageP, GenericP, ...)
|
140 |
*
|
170 |
*
|
141 |
* This is the type of a procedure to be called to parse a complex option.
|
171 |
* This is the type of a procedure to be called to parse a complex option.
|
142 |
* Because of union initialisation problems, the latter arguments of this
|
172 |
* Because of union initialisation problems, the latter arguments of this
|
143 |
* function are untyped.
|
173 |
* function are untyped.
|
144 |
*
|
174 |
*
|
145 |
** Type: ArgListT
|
175 |
** Type: ArgListT
|
146 |
** Type: ArgListP
|
176 |
** Type: ArgListP
|
147 |
** Repr: <private>
|
177 |
** Repr: <private>
|
148 |
*
|
178 |
*
|
149 |
* This is the type of an entry in an option list. A vector of such entries
|
179 |
* This is the type of an entry in an option list. A vector of such entries
|
150 |
* should be passed to the ``arg_parse_arguments'' function, with the last
|
180 |
* should be passed to the ``arg_parse_arguments'' function, with the last
|
151 |
* entry being the ``ARG_PARSE_END_LIST'' macro. Each entry has the following
|
181 |
* entry being the ``ARG_PARSE_END_LIST'' macro. Each entry has the following
|
152 |
* fields: a name field (the name of the option without the leading '--' or
|
182 |
* fields: a name field (the name of the option without the leading '--' or
|
153 |
* '++'), a short name field (a character), a type field (the type of the
|
183 |
* '++'), a short name field (a character), a type field (the type of the
|
Line 170... |
Line 200... |
170 |
* };
|
200 |
* };
|
171 |
*
|
201 |
*
|
172 |
* If an option has only a short form, then the name should be NIL (CStringP);
|
202 |
* If an option has only a short form, then the name should be NIL (CStringP);
|
173 |
* if it has only a long form, then the character should be '\0'. It is
|
203 |
* if it has only a long form, then the character should be '\0'. It is
|
174 |
* illegal for an option to have neither a long form or a short form.
|
204 |
* illegal for an option to have neither a long form or a short form.
|
175 |
*
|
205 |
*
|
176 |
** Type: ArgUsageT
|
206 |
** Type: ArgUsageT
|
177 |
** Type: ArgUsageP
|
207 |
** Type: ArgUsageP
|
178 |
** Repr: struct {CStringP usage; ArgListP arg_list;}
|
208 |
** Repr: struct {CStringP usage; ArgListP arg_list;}
|
179 |
*
|
209 |
*
|
180 |
* This is the type of argument to be passed to ``write_arg_usage''.
|
210 |
* This is the type of argument to be passed to ``write_arg_usage''.
|
181 |
*
|
211 |
*
|
182 |
***=== FUNCTIONS ============================================================
|
212 |
***=== FUNCTIONS ============================================================
|
183 |
*
|
213 |
*
|
184 |
** Function: void arg_parse_intern_descriptions
|
214 |
** Function: void arg_parse_intern_descriptions
|
185 |
* PROTO_S ((ArgListP arg_list))
|
215 |
* (ArgListP arg_list)
|
186 |
** Exceptions: XX_dalloc_no_memory, XX_error_redefined_string
|
216 |
** Exceptions: XX_dalloc_no_memory, XX_error_redefined_string
|
187 |
*
|
217 |
*
|
188 |
* This function should be called on all option lists that the program uses,
|
218 |
* This function should be called on all option lists that the program uses,
|
189 |
* before they are passed to ``arg_parse_arguments''. It replaces the
|
219 |
* before they are passed to ``arg_parse_arguments''. It replaces the
|
190 |
* descrption name with the named string it represents. It should only be
|
220 |
* descrption name with the named string it represents. It should only be
|
191 |
* called once on each list. The named strings used should be interned before
|
221 |
* called once on each list. The named strings used should be interned before
|
192 |
* this function is called.
|
222 |
* this function is called.
|
193 |
*
|
223 |
*
|
194 |
** Function: int arg_parse_arguments
|
224 |
** Function: int arg_parse_arguments
|
195 |
* PROTO_S ((ArgListP arg_list, EStringP usage, int argc,
|
225 |
* (ArgListP arg_list, EStringP usage, int argc,
|
196 |
* char **argv))
|
226 |
* char **argv)
|
197 |
** Exceptions: XX_dalloc_no_memory, XX_ostream_write_error
|
227 |
** Exceptions: XX_dalloc_no_memory, XX_ostream_write_error
|
198 |
*
|
228 |
*
|
199 |
* This function does the argument parsing. The arg_list argument should
|
229 |
* This function does the argument parsing. The arg_list argument should
|
200 |
* specify the valid options for the program. The usage estring should be a
|
230 |
* specify the valid options for the program. The usage estring should be a
|
201 |
* named string, whose content is a summary of the program's usage. The argc
|
231 |
* named string, whose content is a summary of the program's usage. The argc
|
Line 204... |
Line 234... |
204 |
* of the program's argument list (the program name) should not be passed to
|
234 |
* of the program's argument list (the program name) should not be passed to
|
205 |
* this function. The function returns the number of elements of the list
|
235 |
* this function. The function returns the number of elements of the list
|
206 |
* that it parsed.
|
236 |
* that it parsed.
|
207 |
*
|
237 |
*
|
208 |
** Function: void write_arg_usage
|
238 |
** Function: void write_arg_usage
|
209 |
* PROTO_S ((OStreamP ostream, ArgUsageP closure))
|
239 |
* (OStreamP ostream, ArgUsageP closure)
|
210 |
** Exceptions: XX_dalloc_no_memory, XX_ostream_write_error
|
240 |
** Exceptions: XX_dalloc_no_memory, XX_ostream_write_error
|
211 |
*
|
241 |
*
|
212 |
* This function can be used to write out a usage message based upon the usage
|
242 |
* This function can be used to write out a usage message based upon the usage
|
213 |
* information supplied.
|
243 |
* information supplied.
|
214 |
*
|
244 |
*
|
Line 274... |
Line 304... |
274 |
typedef struct ArgUsageT {
|
304 |
typedef struct ArgUsageT {
|
275 |
CStringP usage;
|
305 |
CStringP usage;
|
276 |
struct ArgListT *arg_list;
|
306 |
struct ArgListT *arg_list;
|
277 |
} ArgUsageT, *ArgUsageP;
|
307 |
} ArgUsageT, *ArgUsageP;
|
278 |
|
308 |
|
279 |
typedef void (*ArgProcP) PROTO_S ((CStringP, ArgUsageP, GenericP, ...));
|
309 |
typedef void(*ArgProcP)(CStringP, ArgUsageP, GenericP, ...);
|
280 |
|
310 |
|
281 |
typedef struct ArgListT {
|
311 |
typedef struct ArgListT {
|
282 |
CStringP name;
|
312 |
CStringP name;
|
283 |
char short_name;
|
313 |
char short_name;
|
284 |
ArgTypeT type;
|
314 |
ArgTypeT type;
|
Line 290... |
Line 320... |
290 |
} u;
|
320 |
} u;
|
291 |
} ArgListT, *ArgListP;
|
321 |
} ArgListT, *ArgListP;
|
292 |
|
322 |
|
293 |
/*--------------------------------------------------------------------------*/
|
323 |
/*--------------------------------------------------------------------------*/
|
294 |
|
324 |
|
295 |
extern void arg_parse_intern_descriptions
|
325 |
extern void arg_parse_intern_descriptions(ArgListP);
|
296 |
PROTO_S ((ArgListP));
|
- |
|
297 |
extern int arg_parse_arguments
|
- |
|
298 |
PROTO_S ((ArgListP, EStringP, int, char **));
|
326 |
extern int arg_parse_arguments(ArgListP, EStringP, int, char **);
|
299 |
|
- |
|
300 |
extern void write_arg_usage
|
327 |
extern void write_arg_usage(OStreamP, ArgUsageP);
|
301 |
PROTO_S ((OStreamP, ArgUsageP));
|
- |
|
302 |
|
328 |
|
303 |
/*--------------------------------------------------------------------------*/
|
329 |
/*--------------------------------------------------------------------------*/
|
304 |
|
330 |
|
305 |
#define ARG_PARSE_END_LIST \
|
331 |
#define ARG_PARSE_END_LIST \
|
306 |
{NIL (CStringP), '\0', (ArgTypeT) 0, NIL (ArgProcP), NIL (GenericP), \
|
332 |
{NIL(CStringP), '\0', (ArgTypeT)0, NIL(ArgProcP), NIL(GenericP), \
|
307 |
UB NIL (CStringP) UE}
|
333 |
UB NIL(CStringP)UE}
|
308 |
|
334 |
|
309 |
#endif /* !defined (H_ARG_PARSE) */
|
335 |
#endif /* !defined (H_ARG_PARSE) */
|
310 |
|
336 |
|
311 |
/*
|
337 |
/*
|
312 |
* Local variables(smf):
|
338 |
* Local variables(smf):
|