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))
39 # define AG_PATH_MAX ((size_t)PATH_MAX)
41 # define AG_PATH_MAX ((size_t)4096)
44 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
46 # define AG_PATH_MAX ((size_t)PATH_MAX)
53 #if defined(_WIN32) && !defined(__CYGWIN__)
59 #define AO_EXIT_REQ_USAGE 64
62 * option state was requested from a file that cannot be loaded.
64 # define EX_NOINPUT 66
68 * AutoOpts Software failure.
70 # define EX_SOFTWARE 70
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:
99 * Every part of the value between the delimiters is saved.
102 * Even if the value begins with quote characters, do not do quote processing.
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.
116 OPTION_LOAD_UNCOOKED
,
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.
155 #define OPTSTATE_INITIALIZER(st) \
156 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
158 #define TEXTTO_TABLE \
165 typedef enum { TEXTTO_TABLE COUNT_TT
} teTextTo
;
183 char const * pzOptFmt
;
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))
193 ao_malloc(size_t sz
);
196 ao_realloc(void *p
, size_t sz
);
198 #define ao_free(_p) free((void *)_p)
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:
216 * DISABLE_IMM don't care
218 * DISABLE_TWICE don't care
221 * 2. OPTST_DISABLED is set:
223 * DISABLE_IMM must be set
225 * DISABLE_TWICE don't care
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
239 * DISABLE_TWICE don't care
242 * 2. OPTST_DISABLED is set:
244 * DISABLE_IMM don't care
246 * DISABLE_TWICE don't care
249 #define DO_NORMALLY(_flg) ( \
250 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
251 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
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
261 * DISABLE_TWICE don't care
264 * 4. OPTST_DISABLED is set:
266 * DISABLE_IMM is set (but don't care)
268 * DISABLE_TWICE must be set
271 #define DO_SECOND_TIME(_flg) ( \
272 (((_flg) & (OPTST_DISABLED|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>
284 # define PROT_READ 0x01
287 # define PROT_WRITE 0x02
290 # define MAP_SHARED 0x01
293 # define MAP_PRIVATE 0x02
298 # define MAP_FAILED ((void*)-1)
302 # ifdef _SC_PAGE_SIZE
303 # define _SC_PAGESIZE _SC_PAGE_SIZE
308 extern char* strchr(char const *s
, int c
);
309 extern char* strrchr(char const *s
, int c
);
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 */
332 * c-file-style: "stroustrup"
333 * indent-tabs-mode: nil
335 * end of autoopts/autoopts.h */