Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 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 60... Line 90...
60
#include "gen-errors.h"
90
#include "gen-errors.h"
61
 
91
 
62
/*--------------------------------------------------------------------------*/
92
/*--------------------------------------------------------------------------*/
63
 
93
 
64
void
94
void
65
arg_parse_intern_descriptions PROTO_N ((arg_list))
95
arg_parse_intern_descriptions(ArgListP arg_list)
66
			      PROTO_T (ArgListP arg_list)
-
 
67
{
96
{
68
    while ((arg_list->name != NIL (CStringP)) ||
97
    while ((arg_list->name != NIL(CStringP)) ||
69
	   (arg_list->short_name != '\0')) {
98
	  (arg_list->short_name != '\0')) {
70
	EStringP estring = error_lookup_string (arg_list->u.name);
99
	EStringP estring = error_lookup_string(arg_list->u.name);
71
 
100
 
72
	ASSERT (estring != NIL (EStringP));
101
	ASSERT(estring != NIL(EStringP));
73
	arg_list->u.message = estring;
102
	arg_list->u.message = estring;
74
	arg_list ++;
103
	arg_list++;
75
    }
104
    }
76
}
105
}
77
 
106
 
78
int
107
int
79
arg_parse_arguments PROTO_N ((arg_list, usage, argc, argv))
108
arg_parse_arguments(ArgListP arg_list,			     EStringP usage ,
80
		    PROTO_T (ArgListP arg_list X
-
 
81
			     EStringP usage X
-
 
82
			     int      argc X
109
			     int      argc ,
83
			     char   **argv)
110
			     char   **argv)
84
{
111
{
85
    int       tmp_argc = argc;
112
    int       tmp_argc = argc;
86
    char    **tmp_argv = argv;
113
    char    **tmp_argv = argv;
87
    ArgUsageT closure;
114
    ArgUsageT closure;
88
 
115
 
89
    closure.usage    = error_string_contents (usage);
116
    closure.usage    = error_string_contents(usage);
90
    closure.arg_list = arg_list;
117
    closure.arg_list = arg_list;
91
    while (tmp_argc) {
118
    while (tmp_argc) {
92
	CStringP option = (tmp_argv [0]);
119
	CStringP option = (tmp_argv[0]);
93
	char     c      = (option [0]);
120
	char     c      = (option[0]);
94
 
121
 
95
	if ((((c == '-') && (option [1] == '-')) ||
122
	if ((((c == '-') && (option[1] == '-')) ||
96
	     ((c == '+') && (option [1] == '+'))) && (option [2] == '\0')) {
123
	    ((c == '+') && (option[1] == '+'))) && (option[2] == '\0')) {
97
	    return (argc - tmp_argc + 1);
124
	    return(argc - tmp_argc + 1);
98
	} else if (((c == '-') && (option [1] == '-')) ||
125
	} else if (((c == '-') && (option[1] == '-')) ||
99
		   ((c == '+') && (option [1] == '+'))) {
126
		  ((c == '+') && (option[1] == '+'))) {
100
	    ArgListP tmp_list  = arg_list;
127
	    ArgListP tmp_list  = arg_list;
101
	    ArgListP chosen    = NIL (ArgListP);
128
	    ArgListP chosen    = NIL(ArgListP);
102
	    unsigned matches   = 0;
129
	    unsigned matches   = 0;
103
	    CStringP immediate = NIL (CStringP);
130
	    CStringP immediate = NIL(CStringP);
104
 
131
 
105
	    while ((tmp_list->name != NIL (CStringP)) ||
132
	    while ((tmp_list->name != NIL(CStringP)) ||
106
		   (tmp_list->short_name != '\0')) {
133
		  (tmp_list->short_name != '\0')) {
107
		CStringP opt = (tmp_list->name);
134
		CStringP opt = (tmp_list->name);
108
		CStringP arg = (&(option [2]));
135
		CStringP arg = (& (option[2]));
109
 
136
 
110
		if (opt != NIL (CStringP)) {
137
		if (opt != NIL(CStringP)) {
111
		    char optch;
138
		    char optch;
112
		    char argch;
139
		    char argch;
113
 
140
 
114
		    do {
141
		    do {
115
			optch = (*opt ++);
142
			optch = (*opt++);
116
			argch = (*arg ++);
143
			argch = (*arg++);
117
		    } while (optch && argch && (optch == argch));
144
		    } while (optch && argch && (optch == argch));
118
		    if (optch == argch) {
145
		    if (optch == argch) {
119
			chosen    = tmp_list;
146
			chosen    = tmp_list;
120
			matches   = 1;
147
			matches   = 1;
121
			immediate = (arg - 1);
148
			immediate = (arg - 1);
122
			break;
149
			break;
123
		    } else if ((optch == '\0') &&
150
		    } else if ((optch == '\0') &&
124
			       (((tmp_list->type) == AT_IMMEDIATE) ||
151
			      (((tmp_list->type) == AT_IMMEDIATE) ||
125
				((tmp_list->type) == AT_EITHER))) {
152
				((tmp_list->type) == AT_EITHER))) {
126
			chosen    = tmp_list;
153
			chosen    = tmp_list;
127
			matches   = 1;
154
			matches   = 1;
128
			immediate = (arg - 1);
155
			immediate = (arg - 1);
129
			break;
156
			break;
130
		    } else if (argch == '\0') {
157
		    } else if (argch == '\0') {
131
			chosen = tmp_list;
158
			chosen = tmp_list;
132
			matches ++;
159
			matches++;
133
		    }
160
		    }
134
		}
161
		}
135
		tmp_list ++;
162
		tmp_list++;
136
	    }
163
	    }
137
	    if (matches == 0) {
164
	    if (matches == 0) {
138
		E_arg_parse_unknown_option (option, &closure);
165
		E_arg_parse_unknown_option(option, &closure);
139
		UNREACHED;
166
		UNREACHED;
140
	    } else if (matches > 1) {
167
	    } else if (matches > 1) {
141
		E_arg_parse_ambiguous_option (option, &closure);
168
		E_arg_parse_ambiguous_option(option, &closure);
142
		UNREACHED;
169
		UNREACHED;
143
	    } else {
170
	    } else {
144
		switch (chosen->type) EXHAUSTIVE {
171
		switch (chosen->type)EXHAUSTIVE {
145
		  case AT_SWITCH:
172
		  case AT_SWITCH:
146
		    (*((BoolP) (chosen->closure))) = (c == '-');
173
		   (*((BoolP)(chosen->closure))) = (c == '-');
147
		    break;
174
		    break;
148
		  case AT_NEG_SWITCH:
175
		  case AT_NEG_SWITCH:
149
		    (*((BoolP) (chosen->closure))) = (c == '+');
176
		   (*((BoolP)(chosen->closure))) = (c == '+');
150
		    break;
177
		    break;
151
		  case AT_PROC_SWITCH:
178
		  case AT_PROC_SWITCH:
152
		    (*(chosen->proc)) (option, &closure, chosen->closure,
179
		   (*(chosen->proc))(option, &closure, chosen->closure,
153
				       c == '-');
180
				       c == '-');
154
		    break;
181
		    break;
155
		  case AT_IMMEDIATE:
182
		  case AT_IMMEDIATE:
156
		    if (immediate != NIL (CStringP)) {
183
		    if (immediate != NIL(CStringP)) {
157
			(*(chosen->proc)) (option, &closure, chosen->closure,
184
			(*(chosen->proc))(option, &closure, chosen->closure,
158
					   immediate);
185
					   immediate);
159
		    } else {
186
		    } else {
160
			E_arg_parse_unknown_option (option, &closure);
187
			E_arg_parse_unknown_option(option, &closure);
161
			UNREACHED;
188
			UNREACHED;
162
		    }
189
		    }
163
		    break;
190
		    break;
164
		  case AT_EITHER:
191
		  case AT_EITHER:
165
		    if (immediate != NIL (CStringP)) {
192
		    if (immediate != NIL(CStringP)) {
166
			if (immediate [0] != '\0') {
193
			if (immediate[0]!= '\0') {
167
			    (*(chosen->proc)) (option, &closure,
194
			   (*(chosen->proc))(option, &closure,
168
					       chosen->closure, immediate);
195
					       chosen->closure, immediate);
169
			} else if (tmp_argc > 1) {
196
			} else if (tmp_argc > 1) {
170
			    tmp_argv ++;
197
			    tmp_argv++;
171
			    tmp_argc --;
198
			    tmp_argc--;
172
			    (*(chosen->proc)) (option, &closure,
199
			   (*(chosen->proc))(option, &closure,
173
					       chosen->closure, tmp_argv [0]);
200
					       chosen->closure, tmp_argv[0]);
174
			} else {
201
			} else {
175
			    E_arg_parse_missing_argument (option, &closure);
202
			    E_arg_parse_missing_argument(option, &closure);
176
			    UNREACHED;
203
			    UNREACHED;
177
			}
204
			}
178
		    } else {
205
		    } else {
179
			E_arg_parse_unknown_option (option, &closure);
206
			E_arg_parse_unknown_option(option, &closure);
180
			UNREACHED;
207
			UNREACHED;
181
		    }
208
		    }
182
		    break;
209
		    break;
183
		  case AT_FOLLOWING:
210
		  case AT_FOLLOWING:
184
		    if (tmp_argc > 1) {
211
		    if (tmp_argc > 1) {
185
			tmp_argv ++;
212
			tmp_argv++;
186
			tmp_argc --;
213
			tmp_argc--;
187
			(*(chosen->proc)) (option, &closure, chosen->closure,
214
			(*(chosen->proc))(option, &closure, chosen->closure,
188
					   tmp_argv [0]);
215
					   tmp_argv[0]);
189
		    } else {
216
		    } else {
190
			E_arg_parse_missing_argument (option, &closure);
217
			E_arg_parse_missing_argument(option, &closure);
191
			UNREACHED;
218
			UNREACHED;
192
		    }
219
		    }
193
		    break;
220
		    break;
194
		  case AT_EMPTY:
221
		  case AT_EMPTY:
195
		    (*(chosen->proc)) (option, &closure, chosen->closure);
222
		   (*(chosen->proc))(option, &closure, chosen->closure);
196
		    break;
223
		    break;
197
		  case AT_FOLLOWING2:
224
		  case AT_FOLLOWING2:
198
		    if (tmp_argc > 2) {
225
		    if (tmp_argc > 2) {
199
			tmp_argv += 2;
226
			tmp_argv += 2;
200
			tmp_argc -= 2;
227
			tmp_argc -= 2;
201
			(*(chosen->proc)) (option, &closure, chosen->closure,
228
			(*(chosen->proc))(option, &closure, chosen->closure,
202
					   tmp_argv [-1], tmp_argv [0]);
229
					   tmp_argv[-1], tmp_argv[0]);
203
		    } else {
230
		    } else {
204
			E_arg_parse_missing_argument (option, &closure);
231
			E_arg_parse_missing_argument(option, &closure);
205
			UNREACHED;
232
			UNREACHED;
206
		    }
233
		    }
207
		    break;
234
		    break;
208
		  case AT_FOLLOWING3:
235
		  case AT_FOLLOWING3:
209
		    if (tmp_argc > 3) {
236
		    if (tmp_argc > 3) {
210
			tmp_argv += 3;
237
			tmp_argv += 3;
211
			tmp_argc -= 3;
238
			tmp_argc -= 3;
212
			(*(chosen->proc)) (option, &closure, chosen->closure,
239
			(*(chosen->proc))(option, &closure, chosen->closure,
213
					   tmp_argv [-2], tmp_argv [-1],
240
					   tmp_argv[-2], tmp_argv[-1],
214
					   tmp_argv [0]);
241
					   tmp_argv[0]);
215
		    } else {
242
		    } else {
216
			E_arg_parse_missing_argument (option, &closure);
243
			E_arg_parse_missing_argument(option, &closure);
217
			UNREACHED;
244
			UNREACHED;
218
		    }
245
		    }
219
		    break;
246
		    break;
220
		}
247
		}
221
	    }
248
	    }
222
	} else if (((c == '-') && (option [1] == '+')) ||
249
	} else if (((c == '-') && (option[1] == '+')) ||
223
		   ((c == '+') && (option [1] == '-')) ||
250
		  ((c == '+') && (option[1] == '-')) ||
224
		   ((c == '-') && (option [1] == '\0')) ||
251
		  ((c == '-') && (option[1] == '\0')) ||
225
		   ((c == '+') && (option [1] == '\0'))) {
252
		  ((c == '+') && (option[1] == '\0'))) {
226
	    E_arg_parse_unknown_option (option, &closure);
253
	    E_arg_parse_unknown_option(option, &closure);
227
	    UNREACHED;
254
	    UNREACHED;
228
	} else if ((c == '-') || (c == '+')) {
255
	} else if ((c == '-') || (c == '+')) {
229
	    CStringP opt = &(option [1]);
256
	    CStringP opt = & (option[1]);
230
 
257
 
231
	    while ((opt != NIL (CStringP)) && (*opt != '\0')) {
258
	    while ((opt != NIL(CStringP)) && (*opt != '\0')) {
232
		ArgListP tmp_list = arg_list;
259
		ArgListP tmp_list = arg_list;
233
		ArgListP chosen   = NIL (ArgListP);
260
		ArgListP chosen   = NIL(ArgListP);
234
 
261
 
235
		while ((tmp_list->name != NIL (CStringP)) ||
262
		while ((tmp_list->name != NIL(CStringP)) ||
236
		       (tmp_list->short_name != '\0')) {
263
		      (tmp_list->short_name != '\0')) {
237
		    if (tmp_list->short_name == *opt) {
264
		    if (tmp_list->short_name == *opt) {
238
			chosen = tmp_list;
265
			chosen = tmp_list;
239
			break;
266
			break;
240
		    }
267
		    }
241
		    tmp_list ++;
268
		    tmp_list++;
242
		}
269
		}
243
		if (chosen) {
270
		if (chosen) {
244
		    switch (chosen->type) EXHAUSTIVE {
271
		    switch (chosen->type)EXHAUSTIVE {
245
		      case AT_SWITCH:
272
		      case AT_SWITCH:
246
			(*((BoolP) (chosen->closure))) = (c == '-');
273
			(*((BoolP)(chosen->closure))) = (c == '-');
247
			break;
274
			break;
248
		      case AT_NEG_SWITCH:
275
		      case AT_NEG_SWITCH:
249
			(*((BoolP) (chosen->closure))) = (c == '+');
276
			(*((BoolP)(chosen->closure))) = (c == '+');
250
			break;
277
			break;
251
		      case AT_PROC_SWITCH:
278
		      case AT_PROC_SWITCH:
252
			(*(chosen->proc)) (opt, &closure, chosen->closure,
279
			(*(chosen->proc))(opt, &closure, chosen->closure,
253
					   c == '-');
280
					   c == '-');
254
			break;
281
			break;
255
		      case AT_IMMEDIATE:
282
		      case AT_IMMEDIATE:
256
			(*(chosen->proc)) (opt, &closure, chosen->closure,
283
			(*(chosen->proc))(opt, &closure, chosen->closure,
257
					   opt + 1);
284
					   opt + 1);
258
			opt = NIL (CStringP);
285
			opt = NIL(CStringP);
259
			break;
286
			break;
260
		      case AT_EITHER:
287
		      case AT_EITHER:
261
			if (opt [1] != '\0') {
288
			if (opt[1]!= '\0') {
262
			    (*(chosen->proc)) (opt, &closure, chosen->closure,
289
			   (*(chosen->proc))(opt, &closure, chosen->closure,
263
					       opt + 1);
290
					       opt + 1);
264
			} else if (tmp_argc > 1) {
291
			} else if (tmp_argc > 1) {
265
			    tmp_argv ++;
292
			    tmp_argv++;
266
			    tmp_argc --;
293
			    tmp_argc--;
267
			    (*(chosen->proc)) (opt, &closure, chosen->closure,
294
			   (*(chosen->proc))(opt, &closure, chosen->closure,
268
					       tmp_argv [0]);
295
					       tmp_argv[0]);
269
			} else {
296
			} else {
270
			    E_arg_parse_missing_short_arg (option, opt,
297
			    E_arg_parse_missing_short_arg(option, opt,
271
							   &closure);
298
							   &closure);
272
			    UNREACHED;
299
			    UNREACHED;
273
			}
300
			}
274
			opt = NIL (CStringP);
301
			opt = NIL(CStringP);
275
			break;
302
			break;
276
		      case AT_FOLLOWING:
303
		      case AT_FOLLOWING:
277
			if (tmp_argc > 1) {
304
			if (tmp_argc > 1) {
278
			    tmp_argv ++;
305
			    tmp_argv++;
279
			    tmp_argc --;
306
			    tmp_argc--;
280
			    (*(chosen->proc)) (opt, &closure, chosen->closure,
307
			   (*(chosen->proc))(opt, &closure, chosen->closure,
281
					       tmp_argv [0]);
308
					       tmp_argv[0]);
282
			} else {
309
			} else {
283
			    E_arg_parse_missing_short_arg (option, opt,
310
			    E_arg_parse_missing_short_arg(option, opt,
284
							   &closure);
311
							   &closure);
285
			    UNREACHED;
312
			    UNREACHED;
286
			}
313
			}
287
			break;
314
			break;
288
		      case AT_EMPTY:
315
		      case AT_EMPTY:
289
			(*(chosen->proc)) (opt, &closure, chosen->closure);
316
			(*(chosen->proc))(opt, &closure, chosen->closure);
290
			break;
317
			break;
291
		      case AT_FOLLOWING2:
318
		      case AT_FOLLOWING2:
292
			if (tmp_argc > 2) {
319
			if (tmp_argc > 2) {
293
			    tmp_argv += 2;
320
			    tmp_argv += 2;
294
			    tmp_argc -= 2;
321
			    tmp_argc -= 2;
295
			    (*(chosen->proc)) (opt, &closure, chosen->closure,
322
			   (*(chosen->proc))(opt, &closure, chosen->closure,
296
					       tmp_argv [-1], tmp_argv [0]);
323
					       tmp_argv[-1], tmp_argv[0]);
297
			} else {
324
			} else {
298
			    E_arg_parse_missing_short_arg (option, opt,
325
			    E_arg_parse_missing_short_arg(option, opt,
299
							   &closure);
326
							   &closure);
300
			    UNREACHED;
327
			    UNREACHED;
301
			}
328
			}
302
			break;
329
			break;
303
		      case AT_FOLLOWING3:
330
		      case AT_FOLLOWING3:
304
			if (tmp_argc > 3) {
331
			if (tmp_argc > 3) {
305
			    tmp_argv += 3;
332
			    tmp_argv += 3;
306
			    tmp_argc -= 3;
333
			    tmp_argc -= 3;
307
			    (*(chosen->proc)) (opt, &closure, chosen->closure,
334
			   (*(chosen->proc))(opt, &closure, chosen->closure,
308
					       tmp_argv [-2], tmp_argv [-1],
335
					       tmp_argv[-2], tmp_argv[-1],
309
					       tmp_argv [0]);
336
					       tmp_argv[0]);
310
			} else {
337
			} else {
311
			    E_arg_parse_missing_short_arg (option, opt,
338
			    E_arg_parse_missing_short_arg(option, opt,
312
							   &closure);
339
							   &closure);
313
			    UNREACHED;
340
			    UNREACHED;
314
			}
341
			}
315
			break;
342
			break;
316
		    }
343
		    }
317
		} else {
344
		} else {
318
		    E_arg_parse_unknown_short_opt (option, opt, &closure);
345
		    E_arg_parse_unknown_short_opt(option, opt, &closure);
319
		    UNREACHED;
346
		    UNREACHED;
320
		}
347
		}
321
		if (opt) {
348
		if (opt) {
322
		    opt ++;
349
		    opt++;
323
		}
350
		}
324
	    }
351
	    }
325
	} else {
352
	} else {
326
	    return (argc - tmp_argc);
353
	    return(argc - tmp_argc);
327
	}
354
	}
328
	tmp_argv ++;
355
	tmp_argv++;
329
	tmp_argc --;
356
	tmp_argc--;
330
    }
357
    }
331
    return (argc);
358
    return(argc);
332
}
359
}
333
 
360
 
334
void
361
void
335
write_arg_usage PROTO_N ((ostream, closure))
362
write_arg_usage(OStreamP  ostream,			 ArgUsageP closure)
336
		PROTO_T (OStreamP  ostream X
-
 
337
			 ArgUsageP closure)
-
 
338
{
363
{
339
    CStringP usage    = (closure->usage);
364
    CStringP usage    = (closure->usage);
340
    ArgListP arg_list = (closure->arg_list);
365
    ArgListP arg_list = (closure->arg_list);
341
 
366
 
342
    write_cstring (ostream, usage);
367
    write_cstring(ostream, usage);
343
    while ((arg_list->name != NIL (CStringP)) ||
368
    while ((arg_list->name != NIL(CStringP)) ||
344
	   (arg_list->short_name != '\0')) {
369
	  (arg_list->short_name != '\0')) {
345
	CStringP desc = error_string_contents (arg_list->u.message);
370
	CStringP desc = error_string_contents(arg_list->u.message);
346
 
371
 
347
	if (arg_list->name) {
372
	if (arg_list->name) {
348
	    write_newline (ostream);
373
	    write_newline(ostream);
349
	    write_cstring (ostream, "    {--|++}");
374
	    write_cstring(ostream, "    {--|++}");
350
	    write_cstring (ostream, arg_list->name);
375
	    write_cstring(ostream, arg_list->name);
351
	    write_cstring (ostream, desc);
376
	    write_cstring(ostream, desc);
352
	}
377
	}
353
	if (arg_list->short_name != '\0') {
378
	if (arg_list->short_name != '\0') {
354
	    write_newline (ostream);
379
	    write_newline(ostream);
355
	    write_cstring (ostream, "    {-|+}");
380
	    write_cstring(ostream, "    {-|+}");
356
	    write_char (ostream, arg_list->short_name);
381
	    write_char(ostream, arg_list->short_name);
357
	    write_cstring (ostream, desc);
382
	    write_cstring(ostream, desc);
358
	}
383
	}
359
	arg_list ++;
384
	arg_list++;
360
    }
385
    }
361
}
386
}
362

387

363
/*
388
/*
364
 * Local variables(smf):
389
 * Local variables(smf):