5 * Time-stamp: "2007-04-15 09:59:39 bkorb"
7 * autoopts.h Id: autoopts.h,v 4.23 2007/04/15 19:01:18 bkorb Exp
8 * Time-stamp: "2005-02-14 05:59:50 bkorb"
10 * This file defines all the global structures and special values
11 * used in the automated option processing library.
15 * Automated Options copyright 1992-2007 Bruce Korb
17 * Automated Options is free software.
18 * You may redistribute it and/or modify it under the terms of the
19 * GNU General Public License, as published by the Free Software
20 * Foundation; either version 2, or (at your option) any later version.
22 * Automated Options is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with Automated Options. See the file "COPYING". If not,
29 * write to: The Free Software Foundation, Inc.,
30 * 51 Franklin Street, Fifth Floor,
31 * Boston, MA 02110-1301, USA.
33 * As a special exception, Bruce Korb gives permission for additional
34 * uses of the text contained in his release of AutoOpts.
36 * The exception is that, if you link the AutoOpts library with other
37 * files to produce an executable, this does not by itself cause the
38 * resulting executable to be covered by the GNU General Public License.
39 * Your use of that executable is in no way restricted on account of
40 * linking the AutoOpts library code into it.
42 * This exception does not however invalidate any other reasons why
43 * the executable file might be covered by the GNU General Public License.
45 * This exception applies only to the code released by Bruce Korb under
46 * the name AutoOpts. If you copy code from other sources under the
47 * General Public License into a copy of AutoOpts, as the General Public
48 * License permits, the exception does not apply to the code that you add
49 * in this way. To avoid misleading anyone as to the status of such
50 * modified files, you must delete this exception notice from them.
52 * If you write modifications of your own for AutoOpts, it is your choice
53 * whether to permit this exception to apply to your modifications.
54 * If you do not wish that, delete this exception notice.
57 #ifndef AUTOGEN_AUTOOPTS_H
58 #define AUTOGEN_AUTOOPTS_H
60 #include "compat/compat.h"
62 #define AO_NAME_LIMIT 127
63 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
67 # define AG_PATH_MAX ((size_t)PATH_MAX)
69 # define AG_PATH_MAX ((size_t)4096)
72 # if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
74 # define AG_PATH_MAX ((size_t)PATH_MAX)
81 #if defined(_WIN32) && !defined(__CYGWIN__)
88 # define EX_NOINPUT 66
91 # define EX_SOFTWARE 70
98 * Convert the number to a list usable in a printf call
100 #define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
102 #define NAMED_OPTS(po) \
103 (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
105 #define SKIP_OPT(p) (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
107 typedef int tDirection
;
108 #define DIRECTION_PRESET -1
109 #define DIRECTION_PROCESS 1
110 #define DIRECTION_CALLED 0
112 #define PROCESSING(d) ((d)>0)
113 #define PRESETTING(d) ((d)<0)
115 #define ISNAMECHAR( c ) (isalnum(c) || ((c) == '_') || ((c) == '-'))
118 * Procedure success codes
120 * USAGE: define procedures to return "tSuccess". Test their results
121 * with the SUCCEEDED, FAILED and HADGLITCH macros.
123 * Microsoft sticks its nose into user space here, so for Windows' sake,
124 * make sure all of these are undefined.
134 #define SUCCESS ((tSuccess) 0)
135 #define FAILURE ((tSuccess)-1)
136 #define PROBLEM ((tSuccess) 1)
138 typedef int tSuccess
;
140 #define SUCCEEDED( p ) ((p) == SUCCESS)
141 #define SUCCESSFUL( p ) SUCCEEDED( p )
142 #define FAILED( p ) ((p) < SUCCESS)
143 #define HADGLITCH( p ) ((p) > SUCCESS)
146 * When loading a line (or block) of text as an option, the value can
147 * be processed in any of several modes:
151 * Every part of the value between the delimiters is saved.
154 * Even if the value begins with quote characters, do not do quote processing.
157 * If the value looks like a quoted string, then process it.
158 * Double quoted strings are processed the way strings are in "C" programs,
159 * except they are treated as regular characters if the following character
160 * is not a well-established escape sequence.
161 * Single quoted strings (quoted with apostrophies) are handled the way
162 * strings are handled in shell scripts, *except* that backslash escapes
163 * are honored before backslash escapes and apostrophies.
168 OPTION_LOAD_UNCOOKED
,
172 extern tOptionLoadMode option_load_mode
;
175 * The pager state is used by optionPagedUsage() procedure.
176 * When it runs, it sets itself up to be called again on exit.
177 * If, however, a routine needs a child process to do some work
178 * before it is done, then 'pagerState' must be set to
179 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
180 * to run the pager program before its time.
188 extern tePagerState pagerState
;
209 #define OPTSTATE_INITIALIZER(st) \
210 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
212 #define TEXTTO_TABLE \
219 typedef enum { TEXTTO_TABLE COUNT_TT
} teTextTo
;
239 #define AGALOC( c, w ) ao_malloc((size_t)c)
240 #define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c)
241 #define AGFREE( p ) ao_free((void*)p)
242 #define AGDUPSTR( p, s, w ) (p = ao_strdup(s))
245 ao_malloc( size_t sz
);
248 ao_realloc( void *p
, size_t sz
);
254 ao_strdup( char const *str
);
256 #define TAGMEM( m, t )
259 * DO option handling?
261 * Options are examined at two times: at immediate handling time and at
262 * normal handling time. If an option is disabled, the timing may be
263 * different from the handling of the undisabled option. The OPTST_DIABLED
264 * bit indicates the state of the currently discovered option.
265 * So, here's how it works:
267 * A) handling at "immediate" time, either 1 or 2:
269 * 1. OPTST_DISABLED is not set:
271 * DISABLE_IMM don't care
273 * DISABLE_TWICE don't care
276 * 2. OPTST_DISABLED is set:
278 * DISABLE_IMM must be set
280 * DISABLE_TWICE don't care
283 #define DO_IMMEDIATELY(_flg) \
284 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
285 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
286 == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
288 /* B) handling at "regular" time because it was not immediate
290 * 1. OPTST_DISABLED is not set:
291 * IMM must *NOT* be set
292 * DISABLE_IMM don't care
294 * DISABLE_TWICE don't care
297 * 2. OPTST_DISABLED is set:
299 * DISABLE_IMM don't care
301 * DISABLE_TWICE don't care
304 #define DO_NORMALLY(_flg) ( \
305 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
306 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
309 /* C) handling at "regular" time because it is to be handled twice.
310 * The immediate bit was already tested and found to be set:
312 * 3. OPTST_DISABLED is not set:
313 * IMM is set (but don't care)
314 * DISABLE_IMM don't care
316 * DISABLE_TWICE don't care
319 * 4. OPTST_DISABLED is set:
321 * DISABLE_IMM is set (but don't care)
323 * DISABLE_TWICE must be set
326 #define DO_SECOND_TIME(_flg) ( \
327 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
329 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
330 (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
333 * text_mmap structure. Only active on platforms with mmap(2).
335 #ifdef HAVE_SYS_MMAN_H
336 # include <sys/mman.h>
339 # define PROT_READ 0x01
342 # define PROT_WRITE 0x02
345 # define MAP_SHARED 0x01
348 # define MAP_PRIVATE 0x02
353 # define MAP_FAILED ((void*)-1)
357 # ifdef _SC_PAGE_SIZE
358 # define _SC_PAGESIZE _SC_PAGE_SIZE
363 extern char* strchr( char const *s
, int c
);
364 extern char* strrchr( char const *s
, int c
);
368 * Define and initialize all the user visible strings.
369 * We do not do translations. If translations are to be done, then
370 * the client will provide a callback for that purpose.
372 #undef DO_TRANSLATIONS
373 #include "autoopts/usage-txt.h"
376 * File pointer for usage output
378 extern FILE* option_usage_fp
;
380 extern tOptProc optionPrintVersion
, optionPagedUsage
, optionLoadOpt
;
382 #endif /* AUTOGEN_AUTOOPTS_H */
386 * c-file-style: "stroustrup"
387 * indent-tabs-mode: nil
389 * end of autoopts/autoopts.h */