annotate tools/options.h @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 The option type field controls the interpretation and syntax of individual args.
tomwalters@0 3 Option types are specified by OR'ing bit patterns which define the syntax for
tomwalters@0 4 the argument and the operation by which the argument is combined with the
tomwalters@0 5 default value. Additional bits refer to side-effects which are effects a
tomwalters@0 6 specific option may have which are not related to its syntax or its essential
tomwalters@0 7 operation.
tomwalters@0 8
tomwalters@0 9 Option syntax:
tomwalters@0 10 FLAG_SYNTAX -<name>
tomwalters@0 11 ARG_SYNTAX -<name>[=]<value>
tomwalters@0 12 EQ_SYNTAX [-]<name>=<value>
tomwalters@0 13 ONOFF_SYNTAX -<name>[[=]<value>]
tomwalters@0 14 VAL_SYNTAX -<name>[=]<value> | [-]<name>=<value>
tomwalters@0 15 TOGGLE_SYNTAX -<name> | [-]<name>=<value>
tomwalters@0 16 ALL_SYNTAX -<name>[[=]<value>] | [-]<name>=<value>
tomwalters@0 17
tomwalters@0 18 Option operations:
tomwalters@0 19 LATCH Copy the argument value.
tomwalters@0 20 AND Turn off, (arg effects default only when default is "on")
tomwalters@0 21 OR Turn on, (arg effects default only when default is "off")
tomwalters@0 22 TOGGLE Invert the current default value (on/off), (unless forced by its value)
tomwalters@0 23
tomwalters@0 24 Side effects:
tomwalters@0 25 SILENT Don't print help line.
tomwalters@0 26 EXCLUDE Invert all other EXCLUDE arguments with respect to the current one.
tomwalters@0 27
tomwalters@0 28 Options of EXCLUSIVE type are a set in which one is "on" and the rest "off".
tomwalters@0 29 The value is allowed to be empty or "on", so that an option <name> by itself
tomwalters@0 30 can count as "on".
tomwalters@0 31
tomwalters@0 32 Options of SILENT type are not printed by standard help, unless specifically
tomwalters@0 33 named (eg help=<name>) or all options are asked for (eg help=all).
tomwalters@0 34
tomwalters@0 35
tomwalters@0 36 Some combined option types:
tomwalters@0 37 FLAG Command-line flag: -flag (toggle current default).
tomwalters@0 38 SETFLAG Command-line flag: -flag (toggle current default) or flag=on/off.
tomwalters@0 39 ARG Command-line argument: -argval (latch arg to val).
tomwalters@0 40 EQ Command-line argument: arg=val (latch arg to val).
tomwalters@0 41 VAL Command-line argument, combined style (latch arg to val).
tomwalters@0 42 EX_OR Mutually exclusive option value. Set option value "on", and
tomwalters@0 43 all other EXCLUDE options "off".
tomwalters@0 44 EX_AND Mutually exclusive option value. Set option value "off", and
tomwalters@0 45 all other EXCLUDE options "on".
tomwalters@0 46 EX_TOGGLE Mutually exclusive option value. Set option to given value,
tomwalters@0 47 ("on"/"off") and toggle all other EXCLUDE options ("off"/"on")
tomwalters@0 48 DEBUG Silent toggle (synonymous with STOG).
tomwalters@0 49 STOG Silent toggle.
tomwalters@0 50 SVAL Silent argument (combined-style latch).
tomwalters@0 51
tomwalters@0 52
tomwalters@0 53 Summary of main option types:
tomwalters@0 54
tomwalters@0 55 ------------------------------------------------------------
tomwalters@0 56 Name Operation Side-effect Purpose
tomwalters@0 57 --------- --------- ----------- --------------------
tomwalters@0 58
tomwalters@0 59 (1) With syntax "-<name>"
tomwalters@0 60
tomwalters@0 61 FLAG toggle Toggle flag default value.
tomwalters@0 62 EX_AND and exclude Set flag off and all others on.
tomwalters@0 63
tomwalters@0 64 (2) With syntax "-<name> | [-]<name>=on|off"
tomwalters@0 65
tomwalters@0 66 SETFLAG toggle Set flag on|off.
tomwalters@0 67 EX_OR or exclude Set flag on and all others off.
tomwalters@0 68 EX_TOGGLE toggle exclude Set flag on|off and all others off|on.
tomwalters@0 69 DEBUG toggle silent Set flag silently
tomwalters@0 70 STOG toggle silent " " "
tomwalters@0 71
tomwalters@0 72 (3) With syntax "-<name>[=]<value> | [-]<name>=<value>"
tomwalters@0 73
tomwalters@0 74 VAL latch Latch arg to value.
tomwalters@0 75 SVAL latch silent Latch arg to value silently.
tomwalters@0 76
tomwalters@0 77 */
tomwalters@0 78
tomwalters@0 79 /* option syntax (base types) */
tomwalters@0 80
tomwalters@0 81 #define FLAG_SYNTAX ( 1 ) /* -<name> */
tomwalters@0 82 #define ARG_SYNTAX ( 2 ) /* -<name>[=]<value> */
tomwalters@0 83 #define EQ_SYNTAX ( 4 ) /* [-]<name>=<value> */
tomwalters@0 84
tomwalters@0 85 /* operations between vals */
tomwalters@0 86
tomwalters@0 87 #define LATCH ( 8 )
tomwalters@0 88 #define AND ( 16 )
tomwalters@0 89 #define OR ( 32 )
tomwalters@0 90 #define TOGGLE ( 64 )
tomwalters@0 91
tomwalters@0 92 /* side-effects */
tomwalters@0 93
tomwalters@0 94 #define SILENT ( 128 )
tomwalters@0 95 #define EXCLUDE ( 256 )
tomwalters@0 96
tomwalters@0 97 /* option syntax combinations */
tomwalters@0 98
tomwalters@0 99 #define ONOFF_SYNTAX ( FLAG_SYNTAX | ARG_SYNTAX )
tomwalters@0 100 #define TOGGLE_SYNTAX ( FLAG_SYNTAX | EQ_SYNTAX )
tomwalters@0 101 #define VAL_SYNTAX ( ARG_SYNTAX | EQ_SYNTAX )
tomwalters@0 102 #define ALL_SYNTAX ( FLAG_SYNTAX | ARG_SYNTAX | EQ_SYNTAX )
tomwalters@0 103
tomwalters@0 104 /* combined option types */
tomwalters@0 105
tomwalters@0 106 #define FLAG ( TOGGLE | FLAG_SYNTAX )
tomwalters@0 107 #define SETFLAG ( TOGGLE | TOGGLE_SYNTAX )
tomwalters@0 108 #define ARG ( LATCH | ARG_SYNTAX )
tomwalters@0 109 #define EQ ( LATCH | EQ_SYNTAX )
tomwalters@0 110 #define VAL ( LATCH | VAL_SYNTAX )
tomwalters@0 111
tomwalters@0 112 #define EX_OR ( EXCLUDE | OR | TOGGLE_SYNTAX )
tomwalters@0 113 #define EX_AND ( EXCLUDE | AND | FLAG_SYNTAX )
tomwalters@0 114 #define EX_TOGGLE ( EXCLUDE | TOGGLE | TOGGLE_SYNTAX )
tomwalters@0 115 #define DEBUG ( SILENT | SETFLAG )
tomwalters@0 116 #define STOG ( SILENT | SETFLAG )
tomwalters@0 117 #define SVAL ( SILENT | VAL )
tomwalters@0 118
tomwalters@0 119 /* bit-testing operations */
tomwalters@0 120
tomwalters@0 121 #define and(x1,x2) ( (x1)&(x2) )
tomwalters@0 122 #define bitset(x,bits) ( and(x,bits) ? 1 : 0 )
tomwalters@0 123 #define bitsset(x,bits) ( ( and(x,bits) == bits ) ? 1 : 0 )
tomwalters@0 124
tomwalters@0 125 /* error flags */
tomwalters@0 126
tomwalters@0 127 #define UNKNOWN ( -1 )
tomwalters@0 128 #define AMBIGUOUS ( -2 )
tomwalters@0 129 #define BADVAL ( -3 )
tomwalters@0 130
tomwalters@0 131 /* options structure */
tomwalters@0 132
tomwalters@0 133 typedef struct {
tomwalters@0 134 char *name ; /* option name */
tomwalters@0 135 char *dflt ; /* default value (string) */
tomwalters@0 136 char **val ; /* pointer to current value (string) */
tomwalters@0 137 char *help ; /* help message (max 15 chars) */
tomwalters@0 138 unsigned int type ; /* type of option (syntax, operation, side-effect) */
tomwalters@0 139 } Options ;
tomwalters@0 140
tomwalters@0 141
tomwalters@0 142 /* datatype list */
tomwalters@0 143
tomwalters@0 144 static char *datatype[] = {
tomwalters@0 145 "char" ,
tomwalters@0 146 "short" ,
tomwalters@0 147 "int" ,
tomwalters@0 148 "float" ,
tomwalters@0 149 "double",
tomwalters@0 150 "ASCII" ,
tomwalters@0 151 "ascii" ,
tomwalters@0 152 ( char * ) 0 } ;
tomwalters@0 153
tomwalters@0 154
tomwalters@0 155
tomwalters@0 156
tomwalters@0 157 /*
tomwalters@0 158 types of helpopts
tomwalters@0 159
tomwalters@0 160 helpopts standard usage, exit when done
tomwalters@0 161 helpopts1 standard usage, supplied function for exit or additional help
tomwalters@0 162 helpopts2 supplied usage and function for exit or additional help
tomwalters@0 163 helpopts3 supplied usage, exit when done
tomwalters@0 164 */
tomwalters@0 165
tomwalters@0 166 #define helpopts(helpstr,prog,applic,option) gethelp( helpstr, prog, applic, (char *)0, option, exit )
tomwalters@0 167 #define helpopts1(helpstr,prog,applic,option,tail) gethelp( helpstr, prog, applic, (char *)0, option, tail )
tomwalters@0 168 #define helpopts2(helpstr,prog,applic,usage,option,tail) gethelp( helpstr, prog, applic, usage, option, tail )
tomwalters@0 169 #define helpopts3(helpstr,prog,applic,usage,option) gethelp( helpstr, prog, applic, usage, option, exit )
tomwalters@0 170
tomwalters@0 171
tomwalters@0 172 /* option syntax (for help messages) */
tomwalters@0 173
tomwalters@0 174 static char Flag_Syntax[] = "-<name>" ;
tomwalters@0 175 static char Arg_Syntax[] = "-<name>[=]<value>" ;
tomwalters@0 176 static char Eq_Syntax[] = "[-]<name>=<value>" ;
tomwalters@0 177 static char Onoff_Syntax[] = "-<name>[[=]<value>]" ;
tomwalters@0 178 static char Val_Syntax[] = "-<name>[=]<value> | [-]<name>=<value>" ;
tomwalters@0 179 static char Toggle_Syntax[] = "-<name> | [-]<name>=on|off" ;
tomwalters@0 180 static char All_Syntax[] = "-<name>[[=]<value>] | [-]<name>=<value>" ;
tomwalters@0 181
tomwalters@0 182 static char onstr[] = "on" ;
tomwalters@0 183 static char offstr[] = "off" ;
tomwalters@0 184
tomwalters@0 185
tomwalters@0 186 /* External declarations for variables and functions defined in options.c */
tomwalters@0 187
tomwalters@0 188 int LINE_LENGTH ;
tomwalters@0 189 int PRECISION ; /* for printf */
tomwalters@0 190 int FIELDWIDTH ; /* for printf */
tomwalters@0 191
tomwalters@0 192 int ison() ;
tomwalters@0 193 int isoff() ;
tomwalters@0 194 int ismin() ;
tomwalters@0 195 int ismax() ;
tomwalters@0 196
tomwalters@0 197 int isopt() ;
tomwalters@0 198 int optindex() ;
tomwalters@0 199 int whichopt() ;
tomwalters@0 200 char *optdflt() ;
tomwalters@0 201 char *checksyntax() ;
tomwalters@0 202
tomwalters@0 203 int getopts() ;
tomwalters@0 204 int getvals() ;
tomwalters@0 205 int selector() ;
tomwalters@0 206 int range() ;
tomwalters@0 207 int seekstart() ;
tomwalters@0 208 int typeindex() ;
tomwalters@0 209 int databytes() ;
tomwalters@0 210
tomwalters@0 211 float check_overflow() ;
tomwalters@0 212
tomwalters@0 213 FILE *openopts() ;
tomwalters@0 214 FILE *fropen() ;
tomwalters@0 215
tomwalters@0 216
tomwalters@0 217 int exit() ;