1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
1.4 |
static const char RCSid[] = "$Id: badarg.c,v 1.3 2003/11/15 17:54:06 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Check argument list against format string. |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include <ctype.h> |
9 |
schorsch |
1.3 |
#include <stdio.h> |
10 |
|
|
|
11 |
|
|
#include "parser.h" |
12 |
greg |
1.1 |
|
13 |
|
|
|
14 |
|
|
int |
15 |
|
|
badarg(ac, av, fl) /* check argument list */ |
16 |
|
|
int ac; |
17 |
|
|
register char **av; |
18 |
|
|
register char *fl; |
19 |
|
|
{ |
20 |
|
|
register int i; |
21 |
|
|
|
22 |
|
|
if (fl == NULL) |
23 |
|
|
fl = ""; /* no arguments? */ |
24 |
|
|
for (i = 1; *fl; i++,av++,fl++) { |
25 |
|
|
if (i > ac || *av == NULL) |
26 |
|
|
return(-1); |
27 |
|
|
switch (*fl) { |
28 |
|
|
case 's': /* string */ |
29 |
|
|
if (**av == '\0' || isspace(**av)) |
30 |
|
|
return(i); |
31 |
|
|
break; |
32 |
|
|
case 'i': /* integer */ |
33 |
|
|
if (!isintd(*av, " \t\r\n")) |
34 |
|
|
return(i); |
35 |
|
|
break; |
36 |
|
|
case 'f': /* float */ |
37 |
|
|
if (!isfltd(*av, " \t\r\n")) |
38 |
|
|
return(i); |
39 |
|
|
break; |
40 |
|
|
default: /* bad call! */ |
41 |
|
|
return(-1); |
42 |
|
|
} |
43 |
|
|
} |
44 |
|
|
return(0); /* all's well */ |
45 |
|
|
} |