corrected call to gnutls_error_is_fatal().
[gnutls.git] / src / libopts / autoopts.h
blob6c3fee767be0106e6fed33cce242eb9efac31dba
2 /*
3 * \file autoopts.h
5 * Time-stamp: "2012-02-12 09:04:40 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 #include "compat/compat.h"
35 #include "ag-char-map.h"
37 #define AO_NAME_LIMIT 127
38 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
40 #ifndef AG_PATH_MAX
41 # ifdef PATH_MAX
42 # define AG_PATH_MAX ((size_t)PATH_MAX)
43 # else
44 # define AG_PATH_MAX ((size_t)4096)
45 # endif
46 #else
47 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
48 # undef AG_PATH_MAX
49 # define AG_PATH_MAX ((size_t)PATH_MAX)
50 # endif
51 #endif
53 #undef EXPORT
54 #define EXPORT
56 #if defined(_WIN32) && !defined(__CYGWIN__)
57 # define DIRCH '\\'
58 #else
59 # define DIRCH '/'
60 #endif
62 #ifndef EX_NOINPUT
63 # define EX_NOINPUT 66
64 #endif
65 #ifndef EX_SOFTWARE
66 # define EX_SOFTWARE 70
67 #endif
68 #ifndef EX_CONFIG
69 # define EX_CONFIG 78
70 #endif
72 #define NL '\n'
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_IMMUTABLE_MASK) != 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 * When loading a line (or block) of text as an option, the value can
94 * be processed in any of several modes:
96 * @table @samp
97 * @item keep
98 * Every part of the value between the delimiters is saved.
100 * @item uncooked
101 * Even if the value begins with quote characters, do not do quote processing.
103 * @item cooked
104 * If the value looks like a quoted string, then process it.
105 * Double quoted strings are processed the way strings are in "C" programs,
106 * except they are treated as regular characters if the following character
107 * is not a well-established escape sequence.
108 * Single quoted strings (quoted with apostrophies) are handled the way
109 * strings are handled in shell scripts, *except* that backslash escapes
110 * are honored before backslash escapes and apostrophies.
111 * @end table
113 typedef enum {
114 OPTION_LOAD_COOKED,
115 OPTION_LOAD_UNCOOKED,
116 OPTION_LOAD_KEEP
117 } tOptionLoadMode;
119 static tOptionLoadMode option_load_mode;
122 * The pager state is used by optionPagedUsage() procedure.
123 * When it runs, it sets itself up to be called again on exit.
124 * If, however, a routine needs a child process to do some work
125 * before it is done, then 'pagerState' must be set to
126 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
127 * to run the pager program before its time.
129 typedef enum {
130 PAGER_STATE_INITIAL,
131 PAGER_STATE_READY,
132 PAGER_STATE_CHILD
133 } tePagerState;
135 typedef enum {
136 ENV_ALL,
137 ENV_IMM,
138 ENV_NON_IMM
139 } teEnvPresetType;
141 typedef enum {
142 TOPT_UNDEFINED = 0,
143 TOPT_SHORT,
144 TOPT_LONG,
145 TOPT_DEFAULT
146 } teOptType;
148 typedef struct {
149 tOptDesc* pOD;
150 tCC* pzOptArg;
151 tAoUL flags;
152 teOptType optType;
153 } tOptState;
154 #define OPTSTATE_INITIALIZER(st) \
155 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
157 #define TEXTTO_TABLE \
158 _TT_(LONGUSAGE) \
159 _TT_(USAGE) \
160 _TT_(VERSION)
161 #define _TT_(n) \
162 TT_ ## n ,
164 typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
166 #undef _TT_
168 typedef struct {
169 char const * pzStr;
170 char const * pzReq;
171 char const * pzNum;
172 char const * pzFile;
173 char const * pzKey;
174 char const * pzKeyL;
175 char const * pzBool;
176 char const * pzNest;
177 char const * pzOpt;
178 char const * pzNo;
179 char const * pzBrk;
180 char const * pzNoF;
181 char const * pzSpc;
182 char const * pzOptFmt;
183 char const * pzTime;
184 } arg_types_t;
186 #define AGALOC(c, w) ao_malloc((size_t)c)
187 #define AGREALOC(p, c, w) ao_realloc((void*)p, (size_t)c)
188 #define AGFREE(_p) free((void *)_p)
189 #define AGDUPSTR(p, s, w) (p = ao_strdup(s))
191 static void *
192 ao_malloc(size_t sz);
194 static void *
195 ao_realloc(void *p, size_t sz);
197 #define ao_free(_p) free((void *)_p)
199 static char *
200 ao_strdup(char const *str);
202 #define TAGMEM(m, t)
205 * DO option handling?
207 * Options are examined at two times: at immediate handling time and at
208 * normal handling time. If an option is disabled, the timing may be
209 * different from the handling of the undisabled option. The OPTST_DIABLED
210 * bit indicates the state of the currently discovered option.
211 * So, here's how it works:
213 * A) handling at "immediate" time, either 1 or 2:
215 * 1. OPTST_DISABLED is not set:
216 * IMM must be set
217 * DISABLE_IMM don't care
218 * TWICE don't care
219 * DISABLE_TWICE don't care
220 * 0 -and- 1 x x x
222 * 2. OPTST_DISABLED is set:
223 * IMM don't care
224 * DISABLE_IMM must be set
225 * TWICE don't care
226 * DISABLE_TWICE don't care
227 * 1 -and- x 1 x x
229 #define DO_IMMEDIATELY(_flg) \
230 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
231 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
232 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
234 /* B) handling at "regular" time because it was not immediate
236 * 1. OPTST_DISABLED is not set:
237 * IMM must *NOT* be set
238 * DISABLE_IMM don't care
239 * TWICE don't care
240 * DISABLE_TWICE don't care
241 * 0 -and- 0 x x x
243 * 2. OPTST_DISABLED is set:
244 * IMM don't care
245 * DISABLE_IMM don't care
246 * TWICE must be set
247 * DISABLE_TWICE don't care
248 * 1 -and- x x 1 x
250 #define DO_NORMALLY(_flg) ( \
251 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
252 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
253 OPTST_DISABLED) )
255 /* C) handling at "regular" time because it is to be handled twice.
256 * The immediate bit was already tested and found to be set:
258 * 3. OPTST_DISABLED is not set:
259 * IMM is set (but don't care)
260 * DISABLE_IMM don't care
261 * TWICE must be set
262 * DISABLE_TWICE don't care
263 * 0 -and- ? x 1 x
265 * 4. OPTST_DISABLED is set:
266 * IMM don't care
267 * DISABLE_IMM is set (but don't care)
268 * TWICE don't care
269 * DISABLE_TWICE must be set
270 * 1 -and- x ? x 1
272 #define DO_SECOND_TIME(_flg) ( \
273 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
274 OPTST_TWICE) \
275 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
276 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
279 * text_mmap structure. Only active on platforms with mmap(2).
281 #ifdef HAVE_SYS_MMAN_H
282 # include <sys/mman.h>
283 #else
284 # ifndef PROT_READ
285 # define PROT_READ 0x01
286 # endif
287 # ifndef PROT_WRITE
288 # define PROT_WRITE 0x02
289 # endif
290 # ifndef MAP_SHARED
291 # define MAP_SHARED 0x01
292 # endif
293 # ifndef MAP_PRIVATE
294 # define MAP_PRIVATE 0x02
295 # endif
296 #endif
298 #ifndef MAP_FAILED
299 # define MAP_FAILED ((void*)-1)
300 #endif
302 #ifndef _SC_PAGESIZE
303 # ifdef _SC_PAGE_SIZE
304 # define _SC_PAGESIZE _SC_PAGE_SIZE
305 # endif
306 #endif
308 #ifndef HAVE_STRCHR
309 extern char* strchr(char const *s, int c);
310 extern char* strrchr(char const *s, int c);
311 #endif
314 * Define and initialize all the user visible strings.
315 * We do not do translations. If translations are to be done, then
316 * the client will provide a callback for that purpose.
318 #undef DO_TRANSLATIONS
319 #include "autoopts/usage-txt.h"
322 * File pointer for usage output
324 FILE * option_usage_fp;
325 static char const * program_pkgdatadir;
327 extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
329 #endif /* AUTOGEN_AUTOOPTS_H */
331 * Local Variables:
332 * mode: C
333 * c-file-style: "stroustrup"
334 * indent-tabs-mode: nil
335 * End:
336 * end of autoopts/autoopts.h */