home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / daytime / sw.c < prev    next >
C/C++ Source or Header  |  1996-11-18  |  2KB  |  64 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 are 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.     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.     This software was developed with US Government support
  26.     and it may not be sold, restricted or licensed.  You 
  27.     may duplicate this program provided that this notice
  28.     remains in all of the copies, and you may give it to
  29.     others provided they understand and agree to this
  30.     condition.
  31.  
  32.     For questions or additional information, contact:
  33.  
  34.     Judah Levine
  35.     Time and Frequency Division
  36.     NIST/847
  37.     325 Broadway
  38.     Boulder, Colorado 80303
  39.     (303) 492 7785
  40.     jlevine@time_a.timefreq.bldrdoc.gov
  41. */
  42.     long int atol();
  43.     int sscanf();
  44. /*
  45.     either nothing is left or what is left is not
  46.     a switch
  47. */
  48.     if( (argc == 1)  ||  (*argv[1] != '-') )
  49.       {
  50.       *let='\0';
  51.       *val=0;
  52.       return(0);
  53.     }
  54.     *let= *++argv[1];   /*get the letter after the - character*/
  55.     if( *++argv[1]  != 'x')   /*if next char is not x, decode number*/
  56.       *val=atol(argv[1]);
  57.     else
  58.       {
  59.       argv[1]++;    /*skip over x and decode value in hex */
  60.       sscanf(argv[1]," %lx ",val);
  61.     }
  62.     return(1);
  63. }
  64.