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 2.6 2003/11/14 17:22:06 schorsch Exp $";
00003 #endif
00004 /*
00005  * Check argument list against format string.
00006  *
00007  *  External symbols declared in rtio.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include <ctype.h>
00013 
00014 #include "rtio.h"
00015 
00016 
00017 int
00018 badarg(              /* check argument list */
00019 int    ac,
00020 register char **av,
00021 register char *fl
00022 )
00023 {
00024        register int  i;
00025 
00026        if (fl == NULL)
00027               fl = "";             /* no arguments? */
00028        for (i = 1; *fl; i++,av++,fl++) {
00029               if (i > ac || *av == NULL)
00030                      return(-1);
00031               switch (*fl) {
00032               case 's':            /* string */
00033                      if (**av == '\0' || isspace(**av))
00034                             return(i);
00035                      break;
00036               case 'i':            /* integer */
00037                      if (!isintd(*av, " \t\r\n"))
00038                             return(i);
00039                      break;
00040               case 'f':            /* float */
00041                      if (!isfltd(*av, " \t\r\n"))
00042                             return(i);
00043                      break;
00044               default:             /* bad call! */
00045                      return(-1);
00046               }
00047        }
00048        return(0);           /* all's well */
00049 }