3 * Time-stamp: "2007-04-15 09:59:39 bkorb"
5 * autoopts.h $Id: autoopts.h,v 4.23 2007/04/15 19:01:18 bkorb Exp $
6 * Time-stamp: "2005-02-14 05:59:50 bkorb"
8 * This file defines all the global structures and special values
9 * used in the automated option processing library.
13 * Automated Options copyright 1992-2007 Bruce Korb
15 * Automated Options is free software.
16 * You may redistribute it and/or modify it under the terms of the
17 * GNU General Public License, as published by the Free Software
18 * Foundation; either version 2, or (at your option) any later version.
20 * Automated Options is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with Automated Options. See the file "COPYING". If not,
27 * write to: The Free Software Foundation, Inc.,
28 * 51 Franklin Street, Fifth Floor,
29 * Boston, MA 02110-1301, USA.
31 * As a special exception, Bruce Korb gives permission for additional
32 * uses of the text contained in his release of AutoOpts.
34 * The exception is that, if you link the AutoOpts library with other
35 * files to produce an executable, this does not by itself cause the
36 * resulting executable to be covered by the GNU General Public License.
37 * Your use of that executable is in no way restricted on account of
38 * linking the AutoOpts library code into it.
40 * This exception does not however invalidate any other reasons why
41 * the executable file might be covered by the GNU General Public License.
43 * This exception applies only to the code released by Bruce Korb under
44 * the name AutoOpts. If you copy code from other sources under the
45 * General Public License into a copy of AutoOpts, as the General Public
46 * License permits, the exception does not apply to the code that you add
47 * in this way. To avoid misleading anyone as to the status of such
48 * modified files, you must delete this exception notice from them.
50 * If you write modifications of your own for AutoOpts, it is your choice
51 * whether to permit this exception to apply to your modifications.
52 * If you do not wish that, delete this exception notice.
55 #ifndef AUTOGEN_AUTOOPTS_H
56 #define AUTOGEN_AUTOOPTS_H
58 #include "compat/compat.h"
60 #define AO_NAME_LIMIT 127
61 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
65 # define AG_PATH_MAX ((size_t)PATH_MAX)
67 # define AG_PATH_MAX ((size_t)4096)
70 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
72 # define AG_PATH_MAX ((size_t)PATH_MAX)
79 #if defined(_WIN32) && !defined(__CYGWIN__)
86 # define EX_NOINPUT 66
89 # define EX_SOFTWARE 70
96 * Convert the number to a list usable in a printf call
98 #define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
100 #define NAMED_OPTS(po) \
101 (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
103 #define SKIP_OPT(p) (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
105 typedef int tDirection
;
106 #define DIRECTION_PRESET -1
107 #define DIRECTION_PROCESS 1
108 #define DIRECTION_CALLED 0
110 #define PROCESSING(d) ((d)>0)
111 #define PRESETTING(d) ((d)<0)
113 #define ISNAMECHAR( c ) (isalnum(c) || ((c) == '_') || ((c) == '-'))
116 * Procedure success codes
118 * USAGE: define procedures to return "tSuccess". Test their results
119 * with the SUCCEEDED, FAILED and HADGLITCH macros.
121 * Microsoft sticks its nose into user space here, so for Windows' sake,
122 * make sure all of these are undefined.
132 #define SUCCESS ((tSuccess) 0)
133 #define FAILURE ((tSuccess)-1)
134 #define PROBLEM ((tSuccess) 1)
136 typedef int tSuccess
;
138 #define SUCCEEDED( p ) ((p) == SUCCESS)
139 #define SUCCESSFUL( p ) SUCCEEDED( p )
140 #define FAILED( p ) ((p) < SUCCESS)
141 #define HADGLITCH( p ) ((p) > SUCCESS)
144 * When loading a line (or block) of text as an option, the value can
145 * be processed in any of several modes:
149 * Every part of the value between the delimiters is saved.
152 * Even if the value begins with quote characters, do not do quote processing.
155 * If the value looks like a quoted string, then process it.
156 * Double quoted strings are processed the way strings are in "C" programs,
157 * except they are treated as regular characters if the following character
158 * is not a well-established escape sequence.
159 * Single quoted strings (quoted with apostrophies) are handled the way
160 * strings are handled in shell scripts, *except* that backslash escapes
161 * are honored before backslash escapes and apostrophies.
166 OPTION_LOAD_UNCOOKED
,
170 extern tOptionLoadMode option_load_mode
;
173 * The pager state is used by optionPagedUsage() procedure.
174 * When it runs, it sets itself up to be called again on exit.
175 * If, however, a routine needs a child process to do some work
176 * before it is done, then 'pagerState' must be set to
177 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
178 * to run the pager program before its time.
186 extern tePagerState pagerState
;
207 #define OPTSTATE_INITIALIZER(st) \
208 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
210 #define TEXTTO_TABLE \
217 typedef enum { TEXTTO_TABLE COUNT_TT
} teTextTo
;
237 #define AGALOC( c, w ) ao_malloc((size_t)c)
238 #define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c)
239 #define AGFREE( p ) ao_free((void*)p)
240 #define AGDUPSTR( p, s, w ) (p = ao_strdup(s))
243 ao_malloc( size_t sz
);
246 ao_realloc( void *p
, size_t sz
);
252 ao_strdup( char const *str
);
254 #define TAGMEM( m, t )
257 * DO option handling?
259 * Options are examined at two times: at immediate handling time and at
260 * normal handling time. If an option is disabled, the timing may be
261 * different from the handling of the undisabled option. The OPTST_DIABLED
262 * bit indicates the state of the currently discovered option.
263 * So, here's how it works:
265 * A) handling at "immediate" time, either 1 or 2:
267 * 1. OPTST_DISABLED is not set:
269 * DISABLE_IMM don't care
271 * DISABLE_TWICE don't care
274 * 2. OPTST_DISABLED is set:
276 * DISABLE_IMM must be set
278 * DISABLE_TWICE don't care
281 #define DO_IMMEDIATELY(_flg) \
282 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
283 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
284 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
286 /* B) handling at "regular" time because it was not immediate
288 * 1. OPTST_DISABLED is not set:
289 * IMM must *NOT* be set
290 * DISABLE_IMM don't care
292 * DISABLE_TWICE don't care
295 * 2. OPTST_DISABLED is set:
297 * DISABLE_IMM don't care
299 * DISABLE_TWICE don't care
302 #define DO_NORMALLY(_flg) ( \
303 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
304 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
307 /* C) handling at "regular" time because it is to be handled twice.
308 * The immediate bit was already tested and found to be set:
310 * 3. OPTST_DISABLED is not set:
311 * IMM is set (but don't care)
312 * DISABLE_IMM don't care
314 * DISABLE_TWICE don't care
317 * 4. OPTST_DISABLED is set:
319 * DISABLE_IMM is set (but don't care)
321 * DISABLE_TWICE must be set
324 #define DO_SECOND_TIME(_flg) ( \
325 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
327 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
328 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
331 * text_mmap structure. Only active on platforms with mmap(2).
333 #ifdef HAVE_SYS_MMAN_H
334 # include <sys/mman.h>
337 # define PROT_READ 0x01
340 # define PROT_WRITE 0x02
343 # define MAP_SHARED 0x01
346 # define MAP_PRIVATE 0x02
351 # define MAP_FAILED ((void*)-1)
355 # ifdef _SC_PAGE_SIZE
356 # define _SC_PAGESIZE _SC_PAGE_SIZE
361 extern char* strchr( char const *s
, int c
);
362 extern char* strrchr( char const *s
, int c
);
366 * Define and initialize all the user visible strings.
367 * We do not do translations. If translations are to be done, then
368 * the client will provide a callback for that purpose.
370 #undef DO_TRANSLATIONS
371 #include "autoopts/usage-txt.h"
374 * File pointer for usage output
376 extern FILE* option_usage_fp
;
378 extern tOptProc optionPrintVersion
, optionPagedUsage
, optionLoadOpt
;
380 #endif /* AUTOGEN_AUTOOPTS_H */
384 * c-file-style: "stroustrup"
385 * indent-tabs-mode: nil
387 * end of autoopts/autoopts.h */