If OCSP revocation data are invalid or too old set appropriate verification flags.
[gnutls.git] / src / libopts / autoopts.h
blob194ea5a839ef7703c7630fb5414acc2ee92ef770
2 /*
3 * \file autoopts.h
5 * Time-stamp: "2012-03-04 19:05:01 bkorb"
7 * This file defines all the global structures and special values
8 * used in the automated option processing library.
10 * This file is part of AutoOpts, a companion to AutoGen.
11 * AutoOpts is free software.
12 * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
14 * AutoOpts is available under any one of two licenses. The license
15 * in use must be one of these two and the choice is under the control
16 * of the user of the license.
18 * The GNU Lesser General Public License, version 3 or later
19 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
21 * The Modified Berkeley Software Distribution License
22 * See the file "COPYING.mbsd"
24 * These files have the following md5sums:
26 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
27 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
28 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
31 #ifndef AUTOGEN_AUTOOPTS_H
32 #define AUTOGEN_AUTOOPTS_H
34 #define AO_NAME_LIMIT 127
35 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
37 #ifndef AG_PATH_MAX
38 # ifdef PATH_MAX
39 # define AG_PATH_MAX ((size_t)PATH_MAX)
40 # else
41 # define AG_PATH_MAX ((size_t)4096)
42 # endif
43 #else
44 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
45 # undef AG_PATH_MAX
46 # define AG_PATH_MAX ((size_t)PATH_MAX)
47 # endif
48 #endif
50 #undef EXPORT
51 #define EXPORT
53 #if defined(_WIN32) && !defined(__CYGWIN__)
54 # define DIRCH '\\'
55 #else
56 # define DIRCH '/'
57 #endif
59 #define AO_EXIT_REQ_USAGE 64
60 #ifndef EX_NOINPUT
61 /**
62 * option state was requested from a file that cannot be loaded.
64 # define EX_NOINPUT 66
65 #endif
66 #ifndef EX_SOFTWARE
67 /**
68 * AutoOpts Software failure.
70 # define EX_SOFTWARE 70
71 #endif
73 #define NL '\n'
76 * Convert the number to a list usable in a printf call
78 #define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
80 #define NAMED_OPTS(po) \
81 (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
83 #define SKIP_OPT(p) (((p)->fOptState & OPTST_IMMUTABLE_MASK) != 0)
85 typedef int tDirection;
86 #define DIRECTION_PRESET -1
87 #define DIRECTION_PROCESS 1
88 #define DIRECTION_CALLED 0
90 #define PROCESSING(d) ((d)>0)
91 #define PRESETTING(d) ((d)<0)
94 * When loading a line (or block) of text as an option, the value can
95 * be processed in any of several modes:
97 * @table @samp
98 * @item keep
99 * Every part of the value between the delimiters is saved.
101 * @item uncooked
102 * Even if the value begins with quote characters, do not do quote processing.
104 * @item cooked
105 * If the value looks like a quoted string, then process it.
106 * Double quoted strings are processed the way strings are in "C" programs,
107 * except they are treated as regular characters if the following character
108 * is not a well-established escape sequence.
109 * Single quoted strings (quoted with apostrophies) are handled the way
110 * strings are handled in shell scripts, *except* that backslash escapes
111 * are honored before backslash escapes and apostrophies.
112 * @end table
114 typedef enum {
115 OPTION_LOAD_COOKED,
116 OPTION_LOAD_UNCOOKED,
117 OPTION_LOAD_KEEP
118 } tOptionLoadMode;
120 static tOptionLoadMode option_load_mode;
123 * The pager state is used by optionPagedUsage() procedure.
124 * When it runs, it sets itself up to be called again on exit.
125 * If, however, a routine needs a child process to do some work
126 * before it is done, then 'pagerState' must be set to
127 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
128 * to run the pager program before its time.
130 typedef enum {
131 PAGER_STATE_INITIAL,
132 PAGER_STATE_READY,
133 PAGER_STATE_CHILD
134 } tePagerState;
136 typedef enum {
137 ENV_ALL,
138 ENV_IMM,
139 ENV_NON_IMM
140 } teEnvPresetType;
142 typedef enum {
143 TOPT_UNDEFINED = 0,
144 TOPT_SHORT,
145 TOPT_LONG,
146 TOPT_DEFAULT
147 } teOptType;
149 typedef struct {
150 tOptDesc* pOD;
151 tCC* pzOptArg;
152 tAoUL flags;
153 teOptType optType;
154 } tOptState;
155 #define OPTSTATE_INITIALIZER(st) \
156 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
158 #define TEXTTO_TABLE \
159 _TT_(LONGUSAGE) \
160 _TT_(USAGE) \
161 _TT_(VERSION)
162 #define _TT_(n) \
163 TT_ ## n ,
165 typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
167 #undef _TT_
169 typedef struct {
170 char const * pzStr;
171 char const * pzReq;
172 char const * pzNum;
173 char const * pzFile;
174 char const * pzKey;
175 char const * pzKeyL;
176 char const * pzBool;
177 char const * pzNest;
178 char const * pzOpt;
179 char const * pzNo;
180 char const * pzBrk;
181 char const * pzNoF;
182 char const * pzSpc;
183 char const * pzOptFmt;
184 char const * pzTime;
185 } arg_types_t;
187 #define AGALOC(c, w) ao_malloc((size_t)c)
188 #define AGREALOC(p, c, w) ao_realloc((void*)p, (size_t)c)
189 #define AGFREE(_p) free((void *)_p)
190 #define AGDUPSTR(p, s, w) (p = ao_strdup(s))
192 static void *
193 ao_malloc(size_t sz);
195 static void *
196 ao_realloc(void *p, size_t sz);
198 #define ao_free(_p) free((void *)_p)
200 static char *
201 ao_strdup(char const *str);
204 * DO option handling?
206 * Options are examined at two times: at immediate handling time and at
207 * normal handling time. If an option is disabled, the timing may be
208 * different from the handling of the undisabled option. The OPTST_DIABLED
209 * bit indicates the state of the currently discovered option.
210 * So, here's how it works:
212 * A) handling at "immediate" time, either 1 or 2:
214 * 1. OPTST_DISABLED is not set:
215 * IMM must be set
216 * DISABLE_IMM don't care
217 * TWICE don't care
218 * DISABLE_TWICE don't care
219 * 0 -and- 1 x x x
221 * 2. OPTST_DISABLED is set:
222 * IMM don't care
223 * DISABLE_IMM must be set
224 * TWICE don't care
225 * DISABLE_TWICE don't care
226 * 1 -and- x 1 x x
228 #define DO_IMMEDIATELY(_flg) \
229 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
230 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
231 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
233 /* B) handling at "regular" time because it was not immediate
235 * 1. OPTST_DISABLED is not set:
236 * IMM must *NOT* be set
237 * DISABLE_IMM don't care
238 * TWICE don't care
239 * DISABLE_TWICE don't care
240 * 0 -and- 0 x x x
242 * 2. OPTST_DISABLED is set:
243 * IMM don't care
244 * DISABLE_IMM don't care
245 * TWICE must be set
246 * DISABLE_TWICE don't care
247 * 1 -and- x x 1 x
249 #define DO_NORMALLY(_flg) ( \
250 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
251 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
252 OPTST_DISABLED) )
254 /* C) handling at "regular" time because it is to be handled twice.
255 * The immediate bit was already tested and found to be set:
257 * 3. OPTST_DISABLED is not set:
258 * IMM is set (but don't care)
259 * DISABLE_IMM don't care
260 * TWICE must be set
261 * DISABLE_TWICE don't care
262 * 0 -and- ? x 1 x
264 * 4. OPTST_DISABLED is set:
265 * IMM don't care
266 * DISABLE_IMM is set (but don't care)
267 * TWICE don't care
268 * DISABLE_TWICE must be set
269 * 1 -and- x ? x 1
271 #define DO_SECOND_TIME(_flg) ( \
272 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
273 OPTST_TWICE) \
274 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
275 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
278 * text_mmap structure. Only active on platforms with mmap(2).
280 #ifdef HAVE_SYS_MMAN_H
281 # include <sys/mman.h>
282 #else
283 # ifndef PROT_READ
284 # define PROT_READ 0x01
285 # endif
286 # ifndef PROT_WRITE
287 # define PROT_WRITE 0x02
288 # endif
289 # ifndef MAP_SHARED
290 # define MAP_SHARED 0x01
291 # endif
292 # ifndef MAP_PRIVATE
293 # define MAP_PRIVATE 0x02
294 # endif
295 #endif
297 #ifndef MAP_FAILED
298 # define MAP_FAILED ((void*)-1)
299 #endif
301 #ifndef _SC_PAGESIZE
302 # ifdef _SC_PAGE_SIZE
303 # define _SC_PAGESIZE _SC_PAGE_SIZE
304 # endif
305 #endif
307 #ifndef HAVE_STRCHR
308 extern char* strchr(char const *s, int c);
309 extern char* strrchr(char const *s, int c);
310 #endif
313 * Define and initialize all the user visible strings.
314 * We do not do translations. If translations are to be done, then
315 * the client will provide a callback for that purpose.
317 #undef DO_TRANSLATIONS
318 #include "autoopts/usage-txt.h"
321 * File pointer for usage output
323 FILE * option_usage_fp;
324 static char const * program_pkgdatadir;
326 extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
328 #endif /* AUTOGEN_AUTOOPTS_H */
330 * Local Variables:
331 * mode: C
332 * c-file-style: "stroustrup"
333 * indent-tabs-mode: nil
334 * End:
335 * end of autoopts/autoopts.h */