Back to index

radiance  4R0+20100331
badarg.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: badarg.c,v 1.3 2003/11/15 17:54:06 schorsch Exp $";
00003 #endif
00004 /*
00005  * Check argument list against format string.
00006  */
00007 
00008 #include <ctype.h>
00009 #include <stdio.h>
00010 
00011 #include "parser.h"
00012 
00013 
00014 int
00015 badarg(ac, av, fl)          /* check argument list */
00016 int    ac;
00017 register char **av;
00018 register char *fl;
00019 {
00020        register int  i;
00021 
00022        if (fl == NULL)
00023               fl = "";             /* no arguments? */
00024        for (i = 1; *fl; i++,av++,fl++) {
00025               if (i > ac || *av == NULL)
00026                      return(-1);
00027               switch (*fl) {
00028               case 's':            /* string */
00029                      if (**av == '\0' || isspace(**av))
00030                             return(i);
00031                      break;
00032               case 'i':            /* integer */
00033                      if (!isintd(*av, " \t\r\n"))
00034                             return(i);
00035                      break;
00036               case 'f':            /* float */
00037                      if (!isfltd(*av, " \t\r\n"))
00038                             return(i);
00039                      break;
00040               default:             /* bad call! */
00041                      return(-1);
00042               }
00043        }
00044        return(0);           /* all's well */
00045 }