home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Return options set by string as value (type OPTION);
- ** mask defines which bits can be set, number returns possible numeric
- ** parameter value. Examples of masks, option strings and returned
- ** option bits:
- ** OPTIONA|OPTIONB a OPTIONA
- ** OPTIONA|OPTIONB B OPTIONB
- ** OPTIONA|OPTIONB x OPTERR
- ** OPTIONA|OPTIONB ax OPTIONA|OPTERR
- ** OPTIONA|OPTNUM a OPTIONA
- ** OPTIONA|OPTNUM a31 OPTIONA|OPTNUM (and *number set to 31)
- ** OPTIONA|OPTNUM 14a OPTNUM|OPTERR (and *number set to 14)
- */
-
- #include <ctype.h>
- #include "option.h"
- #include "formatch.h"
-
- OPTION option(string,mask,number)
- char string[];
- OPTION mask;
- unsigned int *number; {
- unsigned register char c;
- int nonum=1;
- OPTION l;
-
- for(l=0L; c=tolower(*string); string++)
- if(islower(c) && ((mask>>(c-'a'))&1) && !(l&OPTNUM))
- l |= 1L<<(c-'a');
- else if(isdigit(c) && mask&OPTNUM) {
- if(nonum) *number=nonum=0;
- *number = *number*10+c-'0';
- l |= OPTNUM;
- } else if(c==*optsepar)
- *optsepar='\0';
- else if(!isspace(c))
- l |= OPTERR;
- return l;
- }
-