Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / sntp / libopts / autoopts.h
blobf1bd8f576336683ad334d8ec5c21a1fd01ab637e
1 /* $NetBSD$ */
4 /*
5 * Time-stamp: "2007-04-15 09:59:39 bkorb"
7 * autoopts.h Id: autoopts.h,v 4.23 2007/04/15 19:01:18 bkorb Exp
8 * Time-stamp: "2005-02-14 05:59:50 bkorb"
10 * This file defines all the global structures and special values
11 * used in the automated option processing library.
15 * Automated Options copyright 1992-2007 Bruce Korb
17 * Automated Options is free software.
18 * You may redistribute it and/or modify it under the terms of the
19 * GNU General Public License, as published by the Free Software
20 * Foundation; either version 2, or (at your option) any later version.
22 * Automated Options is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with Automated Options. See the file "COPYING". If not,
29 * write to: The Free Software Foundation, Inc.,
30 * 51 Franklin Street, Fifth Floor,
31 * Boston, MA 02110-1301, USA.
33 * As a special exception, Bruce Korb gives permission for additional
34 * uses of the text contained in his release of AutoOpts.
36 * The exception is that, if you link the AutoOpts library with other
37 * files to produce an executable, this does not by itself cause the
38 * resulting executable to be covered by the GNU General Public License.
39 * Your use of that executable is in no way restricted on account of
40 * linking the AutoOpts library code into it.
42 * This exception does not however invalidate any other reasons why
43 * the executable file might be covered by the GNU General Public License.
45 * This exception applies only to the code released by Bruce Korb under
46 * the name AutoOpts. If you copy code from other sources under the
47 * General Public License into a copy of AutoOpts, as the General Public
48 * License permits, the exception does not apply to the code that you add
49 * in this way. To avoid misleading anyone as to the status of such
50 * modified files, you must delete this exception notice from them.
52 * If you write modifications of your own for AutoOpts, it is your choice
53 * whether to permit this exception to apply to your modifications.
54 * If you do not wish that, delete this exception notice.
57 #ifndef AUTOGEN_AUTOOPTS_H
58 #define AUTOGEN_AUTOOPTS_H
60 #include "compat/compat.h"
62 #define AO_NAME_LIMIT 127
63 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
65 #ifndef AG_PATH_MAX
66 # ifdef PATH_MAX
67 # define AG_PATH_MAX ((size_t)PATH_MAX)
68 # else
69 # define AG_PATH_MAX ((size_t)4096)
70 # endif
71 #else
72 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
73 # undef AG_PATH_MAX
74 # define AG_PATH_MAX ((size_t)PATH_MAX)
75 # endif
76 #endif
78 #undef EXPORT
79 #define EXPORT
81 #if defined(_WIN32) && !defined(__CYGWIN__)
82 # define DIRCH '\\'
83 #else
84 # define DIRCH '/'
85 #endif
87 #ifndef EX_NOINPUT
88 # define EX_NOINPUT 66
89 #endif
90 #ifndef EX_SOFTWARE
91 # define EX_SOFTWARE 70
92 #endif
93 #ifndef EX_CONFIG
94 # define EX_CONFIG 78
95 #endif
98 * Convert the number to a list usable in a printf call
100 #define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
102 #define NAMED_OPTS(po) \
103 (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
105 #define SKIP_OPT(p) (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
107 typedef int tDirection;
108 #define DIRECTION_PRESET -1
109 #define DIRECTION_PROCESS 1
110 #define DIRECTION_CALLED 0
112 #define PROCESSING(d) ((d)>0)
113 #define PRESETTING(d) ((d)<0)
115 #define ISNAMECHAR( c ) (isalnum(c) || ((c) == '_') || ((c) == '-'))
118 * Procedure success codes
120 * USAGE: define procedures to return "tSuccess". Test their results
121 * with the SUCCEEDED, FAILED and HADGLITCH macros.
123 * Microsoft sticks its nose into user space here, so for Windows' sake,
124 * make sure all of these are undefined.
126 #undef SUCCESS
127 #undef FAILURE
128 #undef PROBLEM
129 #undef SUCCEEDED
130 #undef SUCCESSFUL
131 #undef FAILED
132 #undef HADGLITCH
134 #define SUCCESS ((tSuccess) 0)
135 #define FAILURE ((tSuccess)-1)
136 #define PROBLEM ((tSuccess) 1)
138 typedef int tSuccess;
140 #define SUCCEEDED( p ) ((p) == SUCCESS)
141 #define SUCCESSFUL( p ) SUCCEEDED( p )
142 #define FAILED( p ) ((p) < SUCCESS)
143 #define HADGLITCH( p ) ((p) > SUCCESS)
146 * When loading a line (or block) of text as an option, the value can
147 * be processed in any of several modes:
149 * @table @samp
150 * @item keep
151 * Every part of the value between the delimiters is saved.
153 * @item uncooked
154 * Even if the value begins with quote characters, do not do quote processing.
156 * @item cooked
157 * If the value looks like a quoted string, then process it.
158 * Double quoted strings are processed the way strings are in "C" programs,
159 * except they are treated as regular characters if the following character
160 * is not a well-established escape sequence.
161 * Single quoted strings (quoted with apostrophies) are handled the way
162 * strings are handled in shell scripts, *except* that backslash escapes
163 * are honored before backslash escapes and apostrophies.
164 * @end table
166 typedef enum {
167 OPTION_LOAD_COOKED,
168 OPTION_LOAD_UNCOOKED,
169 OPTION_LOAD_KEEP
170 } tOptionLoadMode;
172 extern tOptionLoadMode option_load_mode;
175 * The pager state is used by optionPagedUsage() procedure.
176 * When it runs, it sets itself up to be called again on exit.
177 * If, however, a routine needs a child process to do some work
178 * before it is done, then 'pagerState' must be set to
179 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
180 * to run the pager program before its time.
182 typedef enum {
183 PAGER_STATE_INITIAL,
184 PAGER_STATE_READY,
185 PAGER_STATE_CHILD
186 } tePagerState;
188 extern tePagerState pagerState;
190 typedef enum {
191 ENV_ALL,
192 ENV_IMM,
193 ENV_NON_IMM
194 } teEnvPresetType;
196 typedef enum {
197 TOPT_UNDEFINED = 0,
198 TOPT_SHORT,
199 TOPT_LONG,
200 TOPT_DEFAULT
201 } teOptType;
203 typedef struct {
204 tOptDesc* pOD;
205 tCC* pzOptArg;
206 tAoUL flags;
207 teOptType optType;
208 } tOptState;
209 #define OPTSTATE_INITIALIZER(st) \
210 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
212 #define TEXTTO_TABLE \
213 _TT_( LONGUSAGE ) \
214 _TT_( USAGE ) \
215 _TT_( VERSION )
216 #define _TT_(n) \
217 TT_ ## n ,
219 typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
221 #undef _TT_
223 typedef struct {
224 tCC* pzStr;
225 tCC* pzReq;
226 tCC* pzNum;
227 tCC* pzKey;
228 tCC* pzKeyL;
229 tCC* pzBool;
230 tCC* pzNest;
231 tCC* pzOpt;
232 tCC* pzNo;
233 tCC* pzBrk;
234 tCC* pzNoF;
235 tCC* pzSpc;
236 tCC* pzOptFmt;
237 } arg_types_t;
239 #define AGALOC( c, w ) ao_malloc((size_t)c)
240 #define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c)
241 #define AGFREE( p ) ao_free((void*)p)
242 #define AGDUPSTR( p, s, w ) (p = ao_strdup(s))
244 static void *
245 ao_malloc( size_t sz );
247 static void *
248 ao_realloc( void *p, size_t sz );
250 static void
251 ao_free( void *p );
253 static char *
254 ao_strdup( char const *str );
256 #define TAGMEM( m, t )
259 * DO option handling?
261 * Options are examined at two times: at immediate handling time and at
262 * normal handling time. If an option is disabled, the timing may be
263 * different from the handling of the undisabled option. The OPTST_DIABLED
264 * bit indicates the state of the currently discovered option.
265 * So, here's how it works:
267 * A) handling at "immediate" time, either 1 or 2:
269 * 1. OPTST_DISABLED is not set:
270 * IMM must be set
271 * DISABLE_IMM don't care
272 * TWICE don't care
273 * DISABLE_TWICE don't care
274 * 0 -and- 1 x x x
276 * 2. OPTST_DISABLED is set:
277 * IMM don't care
278 * DISABLE_IMM must be set
279 * TWICE don't care
280 * DISABLE_TWICE don't care
281 * 1 -and- x 1 x x
283 #define DO_IMMEDIATELY(_flg) \
284 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
285 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
286 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
288 /* B) handling at "regular" time because it was not immediate
290 * 1. OPTST_DISABLED is not set:
291 * IMM must *NOT* be set
292 * DISABLE_IMM don't care
293 * TWICE don't care
294 * DISABLE_TWICE don't care
295 * 0 -and- 0 x x x
297 * 2. OPTST_DISABLED is set:
298 * IMM don't care
299 * DISABLE_IMM don't care
300 * TWICE must be set
301 * DISABLE_TWICE don't care
302 * 1 -and- x x 1 x
304 #define DO_NORMALLY(_flg) ( \
305 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
306 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
307 OPTST_DISABLED) )
309 /* C) handling at "regular" time because it is to be handled twice.
310 * The immediate bit was already tested and found to be set:
312 * 3. OPTST_DISABLED is not set:
313 * IMM is set (but don't care)
314 * DISABLE_IMM don't care
315 * TWICE must be set
316 * DISABLE_TWICE don't care
317 * 0 -and- ? x 1 x
319 * 4. OPTST_DISABLED is set:
320 * IMM don't care
321 * DISABLE_IMM is set (but don't care)
322 * TWICE don't care
323 * DISABLE_TWICE must be set
324 * 1 -and- x ? x 1
326 #define DO_SECOND_TIME(_flg) ( \
327 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
328 OPTST_TWICE) \
329 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
330 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
333 * text_mmap structure. Only active on platforms with mmap(2).
335 #ifdef HAVE_SYS_MMAN_H
336 # include <sys/mman.h>
337 #else
338 # ifndef PROT_READ
339 # define PROT_READ 0x01
340 # endif
341 # ifndef PROT_WRITE
342 # define PROT_WRITE 0x02
343 # endif
344 # ifndef MAP_SHARED
345 # define MAP_SHARED 0x01
346 # endif
347 # ifndef MAP_PRIVATE
348 # define MAP_PRIVATE 0x02
349 # endif
350 #endif
352 #ifndef MAP_FAILED
353 # define MAP_FAILED ((void*)-1)
354 #endif
356 #ifndef _SC_PAGESIZE
357 # ifdef _SC_PAGE_SIZE
358 # define _SC_PAGESIZE _SC_PAGE_SIZE
359 # endif
360 #endif
362 #ifndef HAVE_STRCHR
363 extern char* strchr( char const *s, int c);
364 extern char* strrchr( char const *s, int c);
365 #endif
368 * Define and initialize all the user visible strings.
369 * We do not do translations. If translations are to be done, then
370 * the client will provide a callback for that purpose.
372 #undef DO_TRANSLATIONS
373 #include "autoopts/usage-txt.h"
376 * File pointer for usage output
378 extern FILE* option_usage_fp;
380 extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
382 #endif /* AUTOGEN_AUTOOPTS_H */
384 * Local Variables:
385 * mode: C
386 * c-file-style: "stroustrup"
387 * indent-tabs-mode: nil
388 * End:
389 * end of autoopts/autoopts.h */