Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / sntp / libopts / autoopts.h
blob38871aed28a8fd796fc7b0bacc9f2323736232b8
1 /* $NetBSD$ */
4 /*
5 * Time-stamp: "2008-11-01 20:08:06 bkorb"
7 * autoopts.h Id: d5e30331d37ca10ec88c592d24d8615dd6c1f0ee
9 * This file defines all the global structures and special values
10 * used in the automated option processing library.
12 * This file is part of AutoOpts, a companion to AutoGen.
13 * AutoOpts is free software.
14 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
16 * AutoOpts is available under any one of two licenses. The license
17 * in use must be one of these two and the choice is under the control
18 * of the user of the license.
20 * The GNU Lesser General Public License, version 3 or later
21 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
23 * The Modified Berkeley Software Distribution License
24 * See the file "COPYING.mbsd"
26 * These files have the following md5sums:
28 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
29 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
30 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
33 #ifndef AUTOGEN_AUTOOPTS_H
34 #define AUTOGEN_AUTOOPTS_H
36 #include "compat/compat.h"
37 #include "ag-char-map.h"
39 #define AO_NAME_LIMIT 127
40 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
42 #ifndef AG_PATH_MAX
43 # ifdef PATH_MAX
44 # define AG_PATH_MAX ((size_t)PATH_MAX)
45 # else
46 # define AG_PATH_MAX ((size_t)4096)
47 # endif
48 #else
49 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
50 # undef AG_PATH_MAX
51 # define AG_PATH_MAX ((size_t)PATH_MAX)
52 # endif
53 #endif
55 #undef EXPORT
56 #define EXPORT
58 #if defined(_WIN32) && !defined(__CYGWIN__)
59 # define DIRCH '\\'
60 #else
61 # define DIRCH '/'
62 #endif
64 #ifndef EX_NOINPUT
65 # define EX_NOINPUT 66
66 #endif
67 #ifndef EX_SOFTWARE
68 # define EX_SOFTWARE 70
69 #endif
70 #ifndef EX_CONFIG
71 # define EX_CONFIG 78
72 #endif
75 * Convert the number to a list usable in a printf call
77 #define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
79 #define NAMED_OPTS(po) \
80 (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
82 #define SKIP_OPT(p) (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
84 typedef int tDirection;
85 #define DIRECTION_PRESET -1
86 #define DIRECTION_PROCESS 1
87 #define DIRECTION_CALLED 0
89 #define PROCESSING(d) ((d)>0)
90 #define PRESETTING(d) ((d)<0)
93 * Procedure success codes
95 * USAGE: define procedures to return "tSuccess". Test their results
96 * with the SUCCEEDED, FAILED and HADGLITCH macros.
98 * Microsoft sticks its nose into user space here, so for Windows' sake,
99 * make sure all of these are undefined.
101 #undef SUCCESS
102 #undef FAILURE
103 #undef PROBLEM
104 #undef SUCCEEDED
105 #undef SUCCESSFUL
106 #undef FAILED
107 #undef HADGLITCH
109 #define SUCCESS ((tSuccess) 0)
110 #define FAILURE ((tSuccess)-1)
111 #define PROBLEM ((tSuccess) 1)
113 typedef int tSuccess;
115 #define SUCCEEDED( p ) ((p) == SUCCESS)
116 #define SUCCESSFUL( p ) SUCCEEDED( p )
117 #define FAILED( p ) ((p) < SUCCESS)
118 #define HADGLITCH( p ) ((p) > SUCCESS)
121 * When loading a line (or block) of text as an option, the value can
122 * be processed in any of several modes:
124 * @table @samp
125 * @item keep
126 * Every part of the value between the delimiters is saved.
128 * @item uncooked
129 * Even if the value begins with quote characters, do not do quote processing.
131 * @item cooked
132 * If the value looks like a quoted string, then process it.
133 * Double quoted strings are processed the way strings are in "C" programs,
134 * except they are treated as regular characters if the following character
135 * is not a well-established escape sequence.
136 * Single quoted strings (quoted with apostrophies) are handled the way
137 * strings are handled in shell scripts, *except* that backslash escapes
138 * are honored before backslash escapes and apostrophies.
139 * @end table
141 typedef enum {
142 OPTION_LOAD_COOKED,
143 OPTION_LOAD_UNCOOKED,
144 OPTION_LOAD_KEEP
145 } tOptionLoadMode;
147 extern tOptionLoadMode option_load_mode;
150 * The pager state is used by optionPagedUsage() procedure.
151 * When it runs, it sets itself up to be called again on exit.
152 * If, however, a routine needs a child process to do some work
153 * before it is done, then 'pagerState' must be set to
154 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
155 * to run the pager program before its time.
157 typedef enum {
158 PAGER_STATE_INITIAL,
159 PAGER_STATE_READY,
160 PAGER_STATE_CHILD
161 } tePagerState;
163 extern tePagerState pagerState;
165 typedef enum {
166 ENV_ALL,
167 ENV_IMM,
168 ENV_NON_IMM
169 } teEnvPresetType;
171 typedef enum {
172 TOPT_UNDEFINED = 0,
173 TOPT_SHORT,
174 TOPT_LONG,
175 TOPT_DEFAULT
176 } teOptType;
178 typedef struct {
179 tOptDesc* pOD;
180 tCC* pzOptArg;
181 tAoUL flags;
182 teOptType optType;
183 } tOptState;
184 #define OPTSTATE_INITIALIZER(st) \
185 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
187 #define TEXTTO_TABLE \
188 _TT_( LONGUSAGE ) \
189 _TT_( USAGE ) \
190 _TT_( VERSION )
191 #define _TT_(n) \
192 TT_ ## n ,
194 typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
196 #undef _TT_
198 typedef struct {
199 tCC* pzStr;
200 tCC* pzReq;
201 tCC* pzNum;
202 tCC* pzFile;
203 tCC* pzKey;
204 tCC* pzKeyL;
205 tCC* pzBool;
206 tCC* pzNest;
207 tCC* pzOpt;
208 tCC* pzNo;
209 tCC* pzBrk;
210 tCC* pzNoF;
211 tCC* pzSpc;
212 tCC* pzOptFmt;
213 tCC* pzTime;
214 } arg_types_t;
216 #define AGALOC( c, w ) ao_malloc((size_t)c)
217 #define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c)
218 #define AGFREE(_p) do{void*X=(void*)_p;ao_free(X);}while(0)
219 #define AGDUPSTR( p, s, w ) (p = ao_strdup(s))
221 static void *
222 ao_malloc( size_t sz );
224 static void *
225 ao_realloc( void *p, size_t sz );
227 static void
228 ao_free( void *p );
230 static char *
231 ao_strdup( char const *str );
233 #define TAGMEM( m, t )
236 * DO option handling?
238 * Options are examined at two times: at immediate handling time and at
239 * normal handling time. If an option is disabled, the timing may be
240 * different from the handling of the undisabled option. The OPTST_DIABLED
241 * bit indicates the state of the currently discovered option.
242 * So, here's how it works:
244 * A) handling at "immediate" time, either 1 or 2:
246 * 1. OPTST_DISABLED is not set:
247 * IMM must be set
248 * DISABLE_IMM don't care
249 * TWICE don't care
250 * DISABLE_TWICE don't care
251 * 0 -and- 1 x x x
253 * 2. OPTST_DISABLED is set:
254 * IMM don't care
255 * DISABLE_IMM must be set
256 * TWICE don't care
257 * DISABLE_TWICE don't care
258 * 1 -and- x 1 x x
260 #define DO_IMMEDIATELY(_flg) \
261 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
262 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
263 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
265 /* B) handling at "regular" time because it was not immediate
267 * 1. OPTST_DISABLED is not set:
268 * IMM must *NOT* be set
269 * DISABLE_IMM don't care
270 * TWICE don't care
271 * DISABLE_TWICE don't care
272 * 0 -and- 0 x x x
274 * 2. OPTST_DISABLED is set:
275 * IMM don't care
276 * DISABLE_IMM don't care
277 * TWICE must be set
278 * DISABLE_TWICE don't care
279 * 1 -and- x x 1 x
281 #define DO_NORMALLY(_flg) ( \
282 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
283 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
284 OPTST_DISABLED) )
286 /* C) handling at "regular" time because it is to be handled twice.
287 * The immediate bit was already tested and found to be set:
289 * 3. OPTST_DISABLED is not set:
290 * IMM is set (but don't care)
291 * DISABLE_IMM don't care
292 * TWICE must be set
293 * DISABLE_TWICE don't care
294 * 0 -and- ? x 1 x
296 * 4. OPTST_DISABLED is set:
297 * IMM don't care
298 * DISABLE_IMM is set (but don't care)
299 * TWICE don't care
300 * DISABLE_TWICE must be set
301 * 1 -and- x ? x 1
303 #define DO_SECOND_TIME(_flg) ( \
304 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
305 OPTST_TWICE) \
306 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
307 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
310 * text_mmap structure. Only active on platforms with mmap(2).
312 #ifdef HAVE_SYS_MMAN_H
313 # include <sys/mman.h>
314 #else
315 # ifndef PROT_READ
316 # define PROT_READ 0x01
317 # endif
318 # ifndef PROT_WRITE
319 # define PROT_WRITE 0x02
320 # endif
321 # ifndef MAP_SHARED
322 # define MAP_SHARED 0x01
323 # endif
324 # ifndef MAP_PRIVATE
325 # define MAP_PRIVATE 0x02
326 # endif
327 #endif
329 #ifndef MAP_FAILED
330 # define MAP_FAILED ((void*)-1)
331 #endif
333 #ifndef _SC_PAGESIZE
334 # ifdef _SC_PAGE_SIZE
335 # define _SC_PAGESIZE _SC_PAGE_SIZE
336 # endif
337 #endif
339 #ifndef HAVE_STRCHR
340 extern char* strchr( char const *s, int c);
341 extern char* strrchr( char const *s, int c);
342 #endif
345 * Define and initialize all the user visible strings.
346 * We do not do translations. If translations are to be done, then
347 * the client will provide a callback for that purpose.
349 #undef DO_TRANSLATIONS
350 #include "autoopts/usage-txt.h"
353 * File pointer for usage output
355 extern FILE* option_usage_fp;
357 extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
359 #endif /* AUTOGEN_AUTOOPTS_H */
361 * Local Variables:
362 * mode: C
363 * c-file-style: "stroustrup"
364 * indent-tabs-mode: nil
365 * End:
366 * end of autoopts/autoopts.h */