tomwalters@0: /* tomwalters@0: The option type field controls the interpretation and syntax of individual args. tomwalters@0: Option types are specified by OR'ing bit patterns which define the syntax for tomwalters@0: the argument and the operation by which the argument is combined with the tomwalters@0: default value. Additional bits refer to side-effects which are effects a tomwalters@0: specific option may have which are not related to its syntax or its essential tomwalters@0: operation. tomwalters@0: tomwalters@0: Option syntax: tomwalters@0: FLAG_SYNTAX - tomwalters@0: ARG_SYNTAX -[=] tomwalters@0: EQ_SYNTAX [-]= tomwalters@0: ONOFF_SYNTAX -[[=]] tomwalters@0: VAL_SYNTAX -[=] | [-]= tomwalters@0: TOGGLE_SYNTAX - | [-]= tomwalters@0: ALL_SYNTAX -[[=]] | [-]= tomwalters@0: tomwalters@0: Option operations: tomwalters@0: LATCH Copy the argument value. tomwalters@0: AND Turn off, (arg effects default only when default is "on") tomwalters@0: OR Turn on, (arg effects default only when default is "off") tomwalters@0: TOGGLE Invert the current default value (on/off), (unless forced by its value) tomwalters@0: tomwalters@0: Side effects: tomwalters@0: SILENT Don't print help line. tomwalters@0: EXCLUDE Invert all other EXCLUDE arguments with respect to the current one. tomwalters@0: tomwalters@0: Options of EXCLUSIVE type are a set in which one is "on" and the rest "off". tomwalters@0: The value is allowed to be empty or "on", so that an option by itself tomwalters@0: can count as "on". tomwalters@0: tomwalters@0: Options of SILENT type are not printed by standard help, unless specifically tomwalters@0: named (eg help=) or all options are asked for (eg help=all). tomwalters@0: tomwalters@0: tomwalters@0: Some combined option types: tomwalters@0: FLAG Command-line flag: -flag (toggle current default). tomwalters@0: SETFLAG Command-line flag: -flag (toggle current default) or flag=on/off. tomwalters@0: ARG Command-line argument: -argval (latch arg to val). tomwalters@0: EQ Command-line argument: arg=val (latch arg to val). tomwalters@0: VAL Command-line argument, combined style (latch arg to val). tomwalters@0: EX_OR Mutually exclusive option value. Set option value "on", and tomwalters@0: all other EXCLUDE options "off". tomwalters@0: EX_AND Mutually exclusive option value. Set option value "off", and tomwalters@0: all other EXCLUDE options "on". tomwalters@0: EX_TOGGLE Mutually exclusive option value. Set option to given value, tomwalters@0: ("on"/"off") and toggle all other EXCLUDE options ("off"/"on") tomwalters@0: DEBUG Silent toggle (synonymous with STOG). tomwalters@0: STOG Silent toggle. tomwalters@0: SVAL Silent argument (combined-style latch). tomwalters@0: tomwalters@0: tomwalters@0: Summary of main option types: tomwalters@0: tomwalters@0: ------------------------------------------------------------ tomwalters@0: Name Operation Side-effect Purpose tomwalters@0: --------- --------- ----------- -------------------- tomwalters@0: tomwalters@0: (1) With syntax "-" tomwalters@0: tomwalters@0: FLAG toggle Toggle flag default value. tomwalters@0: EX_AND and exclude Set flag off and all others on. tomwalters@0: tomwalters@0: (2) With syntax "- | [-]=on|off" tomwalters@0: tomwalters@0: SETFLAG toggle Set flag on|off. tomwalters@0: EX_OR or exclude Set flag on and all others off. tomwalters@0: EX_TOGGLE toggle exclude Set flag on|off and all others off|on. tomwalters@0: DEBUG toggle silent Set flag silently tomwalters@0: STOG toggle silent " " " tomwalters@0: tomwalters@0: (3) With syntax "-[=] | [-]=" tomwalters@0: tomwalters@0: VAL latch Latch arg to value. tomwalters@0: SVAL latch silent Latch arg to value silently. tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: /* option syntax (base types) */ tomwalters@0: tomwalters@0: #define FLAG_SYNTAX ( 1 ) /* - */ tomwalters@0: #define ARG_SYNTAX ( 2 ) /* -[=] */ tomwalters@0: #define EQ_SYNTAX ( 4 ) /* [-]= */ tomwalters@0: tomwalters@0: /* operations between vals */ tomwalters@0: tomwalters@0: #define LATCH ( 8 ) tomwalters@0: #define AND ( 16 ) tomwalters@0: #define OR ( 32 ) tomwalters@0: #define TOGGLE ( 64 ) tomwalters@0: tomwalters@0: /* side-effects */ tomwalters@0: tomwalters@0: #define SILENT ( 128 ) tomwalters@0: #define EXCLUDE ( 256 ) tomwalters@0: tomwalters@0: /* option syntax combinations */ tomwalters@0: tomwalters@0: #define ONOFF_SYNTAX ( FLAG_SYNTAX | ARG_SYNTAX ) tomwalters@0: #define TOGGLE_SYNTAX ( FLAG_SYNTAX | EQ_SYNTAX ) tomwalters@0: #define VAL_SYNTAX ( ARG_SYNTAX | EQ_SYNTAX ) tomwalters@0: #define ALL_SYNTAX ( FLAG_SYNTAX | ARG_SYNTAX | EQ_SYNTAX ) tomwalters@0: tomwalters@0: /* combined option types */ tomwalters@0: tomwalters@0: #define FLAG ( TOGGLE | FLAG_SYNTAX ) tomwalters@0: #define SETFLAG ( TOGGLE | TOGGLE_SYNTAX ) tomwalters@0: #define ARG ( LATCH | ARG_SYNTAX ) tomwalters@0: #define EQ ( LATCH | EQ_SYNTAX ) tomwalters@0: #define VAL ( LATCH | VAL_SYNTAX ) tomwalters@0: tomwalters@0: #define EX_OR ( EXCLUDE | OR | TOGGLE_SYNTAX ) tomwalters@0: #define EX_AND ( EXCLUDE | AND | FLAG_SYNTAX ) tomwalters@0: #define EX_TOGGLE ( EXCLUDE | TOGGLE | TOGGLE_SYNTAX ) tomwalters@0: #define DEBUG ( SILENT | SETFLAG ) tomwalters@0: #define STOG ( SILENT | SETFLAG ) tomwalters@0: #define SVAL ( SILENT | VAL ) tomwalters@0: tomwalters@0: /* bit-testing operations */ tomwalters@0: tomwalters@0: #define and(x1,x2) ( (x1)&(x2) ) tomwalters@0: #define bitset(x,bits) ( and(x,bits) ? 1 : 0 ) tomwalters@0: #define bitsset(x,bits) ( ( and(x,bits) == bits ) ? 1 : 0 ) tomwalters@0: tomwalters@0: /* error flags */ tomwalters@0: tomwalters@0: #define UNKNOWN ( -1 ) tomwalters@0: #define AMBIGUOUS ( -2 ) tomwalters@0: #define BADVAL ( -3 ) tomwalters@0: tomwalters@0: /* options structure */ tomwalters@0: tomwalters@0: typedef struct { tomwalters@0: char *name ; /* option name */ tomwalters@0: char *dflt ; /* default value (string) */ tomwalters@0: char **val ; /* pointer to current value (string) */ tomwalters@0: char *help ; /* help message (max 15 chars) */ tomwalters@0: unsigned int type ; /* type of option (syntax, operation, side-effect) */ tomwalters@0: } Options ; tomwalters@0: tomwalters@0: tomwalters@0: /* datatype list */ tomwalters@0: tomwalters@0: static char *datatype[] = { tomwalters@0: "char" , tomwalters@0: "short" , tomwalters@0: "int" , tomwalters@0: "float" , tomwalters@0: "double", tomwalters@0: "ASCII" , tomwalters@0: "ascii" , tomwalters@0: ( char * ) 0 } ; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* tomwalters@0: types of helpopts tomwalters@0: tomwalters@0: helpopts standard usage, exit when done tomwalters@0: helpopts1 standard usage, supplied function for exit or additional help tomwalters@0: helpopts2 supplied usage and function for exit or additional help tomwalters@0: helpopts3 supplied usage, exit when done tomwalters@0: */ tomwalters@0: tomwalters@0: #define helpopts(helpstr,prog,applic,option) gethelp( helpstr, prog, applic, (char *)0, option, exit ) tomwalters@0: #define helpopts1(helpstr,prog,applic,option,tail) gethelp( helpstr, prog, applic, (char *)0, option, tail ) tomwalters@0: #define helpopts2(helpstr,prog,applic,usage,option,tail) gethelp( helpstr, prog, applic, usage, option, tail ) tomwalters@0: #define helpopts3(helpstr,prog,applic,usage,option) gethelp( helpstr, prog, applic, usage, option, exit ) tomwalters@0: tomwalters@0: tomwalters@0: /* option syntax (for help messages) */ tomwalters@0: tomwalters@0: static char Flag_Syntax[] = "-" ; tomwalters@0: static char Arg_Syntax[] = "-[=]" ; tomwalters@0: static char Eq_Syntax[] = "[-]=" ; tomwalters@0: static char Onoff_Syntax[] = "-[[=]]" ; tomwalters@0: static char Val_Syntax[] = "-[=] | [-]=" ; tomwalters@0: static char Toggle_Syntax[] = "- | [-]=on|off" ; tomwalters@0: static char All_Syntax[] = "-[[=]] | [-]=" ; tomwalters@0: tomwalters@0: static char onstr[] = "on" ; tomwalters@0: static char offstr[] = "off" ; tomwalters@0: tomwalters@0: tomwalters@0: /* External declarations for variables and functions defined in options.c */ tomwalters@0: tomwalters@0: int LINE_LENGTH ; tomwalters@0: int PRECISION ; /* for printf */ tomwalters@0: int FIELDWIDTH ; /* for printf */ tomwalters@0: tomwalters@0: int ison() ; tomwalters@0: int isoff() ; tomwalters@0: int ismin() ; tomwalters@0: int ismax() ; tomwalters@0: tomwalters@0: int isopt() ; tomwalters@0: int optindex() ; tomwalters@0: int whichopt() ; tomwalters@0: char *optdflt() ; tomwalters@0: char *checksyntax() ; tomwalters@0: tomwalters@0: int getopts() ; tomwalters@0: int getvals() ; tomwalters@0: int selector() ; tomwalters@0: int range() ; tomwalters@0: int seekstart() ; tomwalters@0: int typeindex() ; tomwalters@0: int databytes() ; tomwalters@0: tomwalters@0: float check_overflow() ; tomwalters@0: tomwalters@0: FILE *openopts() ; tomwalters@0: FILE *fropen() ; tomwalters@0: tomwalters@0: tomwalters@0: int exit() ;