home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / autolock / sw.c < prev   
C/C++ Source or Header  |  2003-12-09  |  1KB  |  43 lines

  1. int sw(argc,argv,let,val)
  2. int argc;
  3. char *argv[];
  4. char *let;
  5. long int *val;
  6. {
  7. /*
  8.     this subroutine parses switches on the command line.
  9.     switches of the form -<letter><value>.  If one is
  10.     found, a pointer to the letter is returned in let 
  11.     and a pointer to the value in val as a long integer. 
  12.  
  13.  
  14.     parameters argc and argv are passed in from the main
  15.     calling program.
  16.     Note that if argc = 1 then only the command is left and
  17.     the line is empty.
  18.     if a switch is decoded, the value of the function is 1
  19.     otherwise it is zero.
  20.     
  21.     note that a number following the letter is decoded as
  22.     a decimal value unless it has a leading x in which case
  23.     it is decoded as hexadecimal.
  24. */
  25.     long int atol();
  26.     int sscanf();
  27.     if( (argc == 1)  ||  (*argv[1] != '-') )
  28.       {
  29.       *let='\0';
  30.       *val=0;
  31.       return(0);
  32.     }
  33.     *let=*++argv[1];   /*get the letter after the - character*/
  34.     if( *++argv[1]  != 'x')   /*if next char is not x, decode number*/
  35.       *val=atol(argv[1]);
  36.     else
  37.       {
  38.       argv[1]++;    /*skip over x and decode value in hex */
  39.       sscanf(argv[1]," %lx ",val);
  40.     }
  41.     return(1);
  42. }
  43.