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))
42 # define AG_PATH_MAX ((size_t)PATH_MAX)
44 # define AG_PATH_MAX ((size_t)4096)
47 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
49 # define AG_PATH_MAX ((size_t)PATH_MAX)
56 #if defined(_WIN32) && !defined(__CYGWIN__)
63 # define EX_NOINPUT 66
66 # define EX_SOFTWARE 70
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:
98 * Every part of the value between the delimiters is saved.
101 * Even if the value begins with quote characters, do not do quote processing.
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.
115 OPTION_LOAD_UNCOOKED
,
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.
154 #define OPTSTATE_INITIALIZER(st) \
155 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
157 #define TEXTTO_TABLE \
164 typedef enum { TEXTTO_TABLE COUNT_TT
} teTextTo
;
182 char const * pzOptFmt
;
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))
192 ao_malloc(size_t sz
);
195 ao_realloc(void *p
, size_t sz
);
197 #define ao_free(_p) free((void *)_p)
200 ao_strdup(char const *str
);
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:
217 * DISABLE_IMM don't care
219 * DISABLE_TWICE don't care
222 * 2. OPTST_DISABLED is set:
224 * DISABLE_IMM must be set
226 * DISABLE_TWICE don't care
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
240 * DISABLE_TWICE don't care
243 * 2. OPTST_DISABLED is set:
245 * DISABLE_IMM don't care
247 * DISABLE_TWICE don't care
250 #define DO_NORMALLY(_flg) ( \
251 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
252 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
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
262 * DISABLE_TWICE don't care
265 * 4. OPTST_DISABLED is set:
267 * DISABLE_IMM is set (but don't care)
269 * DISABLE_TWICE must be set
272 #define DO_SECOND_TIME(_flg) ( \
273 (((_flg) & (OPTST_DISABLED|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>
285 # define PROT_READ 0x01
288 # define PROT_WRITE 0x02
291 # define MAP_SHARED 0x01
294 # define MAP_PRIVATE 0x02
299 # define MAP_FAILED ((void*)-1)
303 # ifdef _SC_PAGE_SIZE
304 # define _SC_PAGESIZE _SC_PAGE_SIZE
309 extern char* strchr(char const *s
, int c
);
310 extern char* strrchr(char const *s
, int c
);
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 */
333 * c-file-style: "stroustrup"
334 * indent-tabs-mode: nil
336 * end of autoopts/autoopts.h */