3
Copyright (c) 1987-1999 Massachusetts Institute of Technology
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or (at
8
your option) any later version.
10
This program is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
/* $Id: comlin.c,v 1.9 1999/01/02 06:11:34 cph Exp $
22
* This file contains the scheme command parser.
33
/* Some string utilities */
36
DEFUN (remove_initial_substring, (sub, str),
38
AND register char * str)
40
for ( ; *sub != '\0'; sub++, str++)
44
return ((char *) NULL);
51
DEFUN (STREQUAL, (s1, s2),
53
AND register char * s2)
55
for ( ; *s1 != '\0'; s1++, s2++)
57
if (toupper(*s1) != toupper(*s2))
65
/* Usage information */
68
DEFUN (print_usage_and_exit, (options, val),
69
struct keyword_struct * options
74
fprintf(stderr, "usage: %s", program_name);
76
if ((options[0].type_tag) == LAST_KYWRD)
78
fprintf(stderr, "\n");
82
fprintf(stderr, " [args]\n");
83
fprintf(stderr, " where args are as follows:\n");
86
((options[i].type_tag) != LAST_KYWRD);
89
switch (options[i].type_tag)
92
fprintf(stderr, " %s={true,false}\n",
98
fprintf(stderr, " %s=%s\n",
99
options[i].keyword, options[i].format);
103
fprintf(stderr, " %s=%%s\n",
112
DEFUN (supply, (options, j),
113
struct keyword_struct * options
116
if (options[j].supplied_p != ((boolean *) NULL))
118
if (*(options[j].supplied_p))
121
"parse_keywords: Repeated keyword: %s\n",
123
print_usage_and_exit(&options[0], 1);
127
*(options[j].supplied_p) = true;
135
/* This parser assumes that no keyword is an initial
136
substring of another.
140
DEFUN (parse_keywords,
141
(argc, argv, options, allow_others_p),
144
AND struct keyword_struct * options
145
AND boolean allow_others_p)
147
register int i, j, length;
150
program_name = argv[0];
154
/* Initialize defaults */
157
((options[length].type_tag) != LAST_KYWRD);
160
if (options[length].supplied_p != ((boolean *) NULL))
162
*(options[length].supplied_p) = false;
165
switch (options[length].type_tag)
168
if (options[length].format != BFRMT)
171
"parse_keywords: format (%s) for boolean keyword %s\n",
172
options[length].format,
173
options[length].keyword);
185
if (options[length].format != SFRMT)
188
"parse_keywords: format (%s) for string keyword %s\n",
189
options[length].format,
190
options[length].keyword);
196
fprintf(stderr, "parse_keywords: bad type %d\n",
197
options[length].type_tag);
202
for (i = 0; i < argc; i++)
204
for (j = 0; j < length; j++)
206
argument = remove_initial_substring(options[j].keyword,argv[i]);
207
if (argument != ((char *) NULL))
209
switch (options[j].type_tag)
216
if (*argument != '\0')
218
if (*argument != '=')
221
"parse_keywords: unrecognized parameter: %s\n",
223
print_usage_and_exit(&options[0], 1);
227
argument = &argument[1];
228
if (STREQUAL(argument,"t") || STREQUAL(argument,"true"))
232
else if (STREQUAL(argument,"f") ||
233
STREQUAL(argument,"false") ||
234
STREQUAL(argument,"nil"))
241
"parse_keywords: Invalid boolean value: %s\n",
243
print_usage_and_exit(&options[0], 1);
252
*(BOOLEAN_LVALUE(options[j])) = value;
257
if (*argument != '=')
261
"parse_keywords: %s: %s\n",
262
((*argument == '\0') ?
263
"missing integer value" :
264
"unrecognized parameter"),
266
print_usage_and_exit(&options[0], 1);
270
sscanf(&argument[1], options[j].format, INT_LVALUE(options[j]));
274
if (*argument != '=')
278
"parse_keywords: %s: %s\n",
279
((*argument == '\0') ?
280
"missing floating point value" :
281
"unrecognized parameter"),
283
print_usage_and_exit(&options[0], 1);
287
sscanf(&argument[1], options[j].format, DOUBLE_LVALUE(options[j]));
291
if (*argument != '=')
295
"parse_keywords: %s: %s\n",
296
((*argument == '\0') ?
297
"missing string value" :
298
"unrecognized parameter"),
300
print_usage_and_exit(&options[0], 1);
304
*(STRING_LVALUE(options[j])) = &argument[1];
310
if ((j >= length) && (!allow_others_p))
313
"parse_keywords: unrecognized parameter: %s\n",
315
print_usage_and_exit(&options[0], 1);