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
Wrap
C/C++ Source or Header
|
2003-12-09
|
1KB
|
43 lines
int sw(argc,argv,let,val)
int argc;
char *argv[];
char *let;
long int *val;
{
/*
this subroutine parses switches on the command line.
switches of the form -<letter><value>. If one is
found, a pointer to the letter is returned in let
and a pointer to the value in val as a long integer.
parameters argc and argv are passed in from the main
calling program.
Note that if argc = 1 then only the command is left and
the line is empty.
if a switch is decoded, the value of the function is 1
otherwise it is zero.
note that a number following the letter is decoded as
a decimal value unless it has a leading x in which case
it is decoded as hexadecimal.
*/
long int atol();
int sscanf();
if( (argc == 1) || (*argv[1] != '-') )
{
*let='\0';
*val=0;
return(0);
}
*let=*++argv[1]; /*get the letter after the - character*/
if( *++argv[1] != 'x') /*if next char is not x, decode number*/
*val=atol(argv[1]);
else
{
argv[1]++; /*skip over x and decode value in hex */
sscanf(argv[1]," %lx ",val);
}
return(1);
}