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