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