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