5 * Time-stamp: "2008-11-01 20:08:06 bkorb"
7 * autoopts.h Id: d5e30331d37ca10ec88c592d24d8615dd6c1f0ee
9 * This file defines all the global structures and special values
10 * used in the automated option processing library.
12 * This file is part of AutoOpts, a companion to AutoGen.
13 * AutoOpts is free software.
14 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
16 * AutoOpts is available under any one of two licenses. The license
17 * in use must be one of these two and the choice is under the control
18 * of the user of the license.
20 * The GNU Lesser General Public License, version 3 or later
21 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
23 * The Modified Berkeley Software Distribution License
24 * See the file "COPYING.mbsd"
26 * These files have the following md5sums:
28 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
29 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
30 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
33 #ifndef AUTOGEN_AUTOOPTS_H
34 #define AUTOGEN_AUTOOPTS_H
36 #include "compat/compat.h"
37 #include "ag-char-map.h"
39 #define AO_NAME_LIMIT 127
40 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
44 # define AG_PATH_MAX ((size_t)PATH_MAX)
46 # define AG_PATH_MAX ((size_t)4096)
49 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
51 # define AG_PATH_MAX ((size_t)PATH_MAX)
58 #if defined(_WIN32) && !defined(__CYGWIN__)
65 # define EX_NOINPUT 66
68 # 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_DOCUMENT|OPTST_OMITTED)) != 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 * Procedure success codes
95 * USAGE: define procedures to return "tSuccess". Test their results
96 * with the SUCCEEDED, FAILED and HADGLITCH macros.
98 * Microsoft sticks its nose into user space here, so for Windows' sake,
99 * make sure all of these are undefined.
109 #define SUCCESS ((tSuccess) 0)
110 #define FAILURE ((tSuccess)-1)
111 #define PROBLEM ((tSuccess) 1)
113 typedef int tSuccess
;
115 #define SUCCEEDED( p ) ((p) == SUCCESS)
116 #define SUCCESSFUL( p ) SUCCEEDED( p )
117 #define FAILED( p ) ((p) < SUCCESS)
118 #define HADGLITCH( p ) ((p) > SUCCESS)
121 * When loading a line (or block) of text as an option, the value can
122 * be processed in any of several modes:
126 * Every part of the value between the delimiters is saved.
129 * Even if the value begins with quote characters, do not do quote processing.
132 * If the value looks like a quoted string, then process it.
133 * Double quoted strings are processed the way strings are in "C" programs,
134 * except they are treated as regular characters if the following character
135 * is not a well-established escape sequence.
136 * Single quoted strings (quoted with apostrophies) are handled the way
137 * strings are handled in shell scripts, *except* that backslash escapes
138 * are honored before backslash escapes and apostrophies.
143 OPTION_LOAD_UNCOOKED
,
147 extern tOptionLoadMode option_load_mode
;
150 * The pager state is used by optionPagedUsage() procedure.
151 * When it runs, it sets itself up to be called again on exit.
152 * If, however, a routine needs a child process to do some work
153 * before it is done, then 'pagerState' must be set to
154 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
155 * to run the pager program before its time.
163 extern tePagerState pagerState
;
184 #define OPTSTATE_INITIALIZER(st) \
185 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
187 #define TEXTTO_TABLE \
194 typedef enum { TEXTTO_TABLE COUNT_TT
} teTextTo
;
216 #define AGALOC( c, w ) ao_malloc((size_t)c)
217 #define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c)
218 #define AGFREE(_p) do{void*X=(void*)_p;ao_free(X);}while(0)
219 #define AGDUPSTR( p, s, w ) (p = ao_strdup(s))
222 ao_malloc( size_t sz
);
225 ao_realloc( void *p
, size_t sz
);
231 ao_strdup( char const *str
);
233 #define TAGMEM( m, t )
236 * DO option handling?
238 * Options are examined at two times: at immediate handling time and at
239 * normal handling time. If an option is disabled, the timing may be
240 * different from the handling of the undisabled option. The OPTST_DIABLED
241 * bit indicates the state of the currently discovered option.
242 * So, here's how it works:
244 * A) handling at "immediate" time, either 1 or 2:
246 * 1. OPTST_DISABLED is not set:
248 * DISABLE_IMM don't care
250 * DISABLE_TWICE don't care
253 * 2. OPTST_DISABLED is set:
255 * DISABLE_IMM must be set
257 * DISABLE_TWICE don't care
260 #define DO_IMMEDIATELY(_flg) \
261 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
262 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
263 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
265 /* B) handling at "regular" time because it was not immediate
267 * 1. OPTST_DISABLED is not set:
268 * IMM must *NOT* be set
269 * DISABLE_IMM don't care
271 * DISABLE_TWICE don't care
274 * 2. OPTST_DISABLED is set:
276 * DISABLE_IMM don't care
278 * DISABLE_TWICE don't care
281 #define DO_NORMALLY(_flg) ( \
282 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
283 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
286 /* C) handling at "regular" time because it is to be handled twice.
287 * The immediate bit was already tested and found to be set:
289 * 3. OPTST_DISABLED is not set:
290 * IMM is set (but don't care)
291 * DISABLE_IMM don't care
293 * DISABLE_TWICE don't care
296 * 4. OPTST_DISABLED is set:
298 * DISABLE_IMM is set (but don't care)
300 * DISABLE_TWICE must be set
303 #define DO_SECOND_TIME(_flg) ( \
304 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
306 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
307 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
310 * text_mmap structure. Only active on platforms with mmap(2).
312 #ifdef HAVE_SYS_MMAN_H
313 # include <sys/mman.h>
316 # define PROT_READ 0x01
319 # define PROT_WRITE 0x02
322 # define MAP_SHARED 0x01
325 # define MAP_PRIVATE 0x02
330 # define MAP_FAILED ((void*)-1)
334 # ifdef _SC_PAGE_SIZE
335 # define _SC_PAGESIZE _SC_PAGE_SIZE
340 extern char* strchr( char const *s
, int c
);
341 extern char* strrchr( char const *s
, int c
);
345 * Define and initialize all the user visible strings.
346 * We do not do translations. If translations are to be done, then
347 * the client will provide a callback for that purpose.
349 #undef DO_TRANSLATIONS
350 #include "autoopts/usage-txt.h"
353 * File pointer for usage output
355 extern FILE* option_usage_fp
;
357 extern tOptProc optionPrintVersion
, optionPagedUsage
, optionLoadOpt
;
359 #endif /* AUTOGEN_AUTOOPTS_H */
363 * c-file-style: "stroustrup"
364 * indent-tabs-mode: nil
366 * end of autoopts/autoopts.h */