home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / RADIANCE / SRC / COMMON / BADARG.C next >
C/C++ Source or Header  |  1993-10-07  |  880b  |  47 lines

  1. /* Copyright (c) 1991 Regents of the University of California */
  2.  
  3. #ifndef lint
  4. static char SCCSid[] = "@(#)badarg.c 2.1 11/12/91 LBL";
  5. #endif
  6.  
  7. /*
  8.  * Check argument list against format string.
  9.  */
  10.  
  11. #include <ctype.h>
  12.  
  13. #define NULL        0
  14.  
  15. int
  16. badarg(ac, av, fl)        /* check argument list */
  17. int    ac;
  18. register char    **av;
  19. register char    *fl;
  20. {
  21.     register int  i;
  22.  
  23.     if (fl == NULL)
  24.         fl = "";        /* no arguments? */
  25.     for (i = 1; *fl; i++,av++,fl++) {
  26.         if (i > ac || *av == NULL)
  27.             return(-1);
  28.         switch (*fl) {
  29.         case 's':        /* string */
  30.             if (**av == '\0' || isspace(**av))
  31.                 return(i);
  32.             break;
  33.         case 'i':        /* integer */
  34.             if (!isintd(*av, " \t\r\n"))
  35.                 return(i);
  36.             break;
  37.         case 'f':        /* float */
  38.             if (!isfltd(*av, " \t\r\n"))
  39.                 return(i);
  40.             break;
  41.         default:        /* bad call! */
  42.             return(-1);
  43.         }
  44.     }
  45.     return(0);        /* all's well */
  46. }
  47.