1 /* -*- buffer-read-only: t -*- vi: set ro:
3 * DO NOT EDIT THIS FILE (options.h)
5 * It has been AutoGen-ed May 6, 2012 at 04:21:03 PM by AutoGen 5.16pre36
6 * From the definitions funcs.def
7 * and the template file options_h
9 * This file defines all the global structures and special values
10 * used in the automated option processing library.
12 * Automated Options Copyright (C) 1992-2012 by Bruce Korb
14 * * AutoOpts is free software: you can redistribute it and/or modify it
15 * under the terms of the GNU Lesser General Public License as published
16 * by the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * AutoOpts is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.";
27 #ifndef AUTOOPTS_OPTIONS_H_GUARD
28 #define AUTOOPTS_OPTIONS_H_GUARD 1
29 #include <sys/types.h>
32 #ifndef COMPAT_H_GUARD
34 * This is needed for test compilations where the "compat.h"
35 * header is not usually available.
37 # if defined(HAVE_STDINT_H)
39 # elif defined(HAVE_INTTYPES_H)
40 # include <inttypes.h>
41 # endif /* HAVE_STDINT/INTTYPES_H */
43 # if defined(HAVE_LIMITS_H)
45 # elif defined(HAVE_SYS_LIMITS_H)
46 # include <sys/limits.h>
47 # endif /* HAVE_LIMITS/SYS_LIMITS_H */
49 # if defined(HAVE_SYSEXITS_H)
50 # include <sysexits.h>
51 # endif /* HAVE_SYSEXITS_H */
53 # if defined(HAVE_STDBOOL_H)
56 typedef enum { false = 0, true = 1 } _Bool
;
59 /* The other macros must be usable in preprocessor directives. */
62 # endif /* HAVE_SYSEXITS_H */
63 #endif /* COMPAT_H_GUARD */
64 // END-CONFIGURED-HEADERS
67 * Defined to normal value of EX_USAGE. Used to indicate that paged usage
68 * was requested. It is used to distinguish a --usage from a --help request.
69 * --usage is abbreviated and --help gives as much help as possible.
71 #define AO_EXIT_REQ_USAGE 64
76 * The following defines may be used in applications that need to test the
77 * state of an option. To test against these masks and values, a pointer
78 * to an option descriptor must be obtained. There are two ways:
80 * 1. inside an option processing procedure, it is the second argument,
81 * conventionally "tOptDesc* pOD".
83 * 2. Outside of an option procedure (or to reference a different option
84 * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )".
86 * See the relevant generated header file to determine which and what
87 * values for "opt_name" are available.
89 #define OPTIONS_STRUCT_VERSION 147460
90 #define OPTIONS_VERSION_STRING "36:4:11"
91 #define OPTIONS_MINIMUM_VERSION 102400
92 #define OPTIONS_MIN_VER_STRING "25:0:0"
93 #define OPTIONS_VER_TO_NUM(_v, _r) (((_v) * 4096) + (_r))
97 OPARG_TYPE_STRING
= 1, /* default type/ vanilla string */
98 OPARG_TYPE_ENUMERATION
= 2, /* opt arg is an enum (keyword list) */
99 OPARG_TYPE_BOOLEAN
= 3, /* opt arg is boolean-valued */
100 OPARG_TYPE_MEMBERSHIP
= 4, /* opt arg sets set membership bits */
101 OPARG_TYPE_NUMERIC
= 5, /* opt arg is a long int */
102 OPARG_TYPE_HIERARCHY
= 6, /* option arg is hierarchical value */
103 OPARG_TYPE_FILE
= 7, /* option arg names a file */
104 OPARG_TYPE_TIME
= 8, /* opt arg is a time duration */
105 OPARG_TYPE_FLOAT
= 9, /* opt arg is a floating point num */
106 OPARG_TYPE_DOUBLE
= 10, /* opt arg is a double prec. float */
107 OPARG_TYPE_LONG_DOUBLE
= 11, /* opt arg is a long double prec. */
108 OPARG_TYPE_LONG_LONG
= 12 /* opt arg is a long long int */
111 typedef struct optionValue
{
112 teOptArgType valType
;
115 char strVal
[1]; /* OPARG_TYPE_STRING */
116 unsigned int enumVal
; /* OPARG_TYPE_ENUMERATION */
117 unsigned int boolVal
; /* OPARG_TYPE_BOOLEAN */
118 unsigned long setVal
; /* OPARG_TYPE_MEMBERSHIP */
119 long longVal
; /* OPARG_TYPE_NUMERIC */
120 void* nestVal
; /* OPARG_TYPE_HIERARCHY */
125 FTYPE_MODE_MAY_EXIST
= 0x00,
126 FTYPE_MODE_MUST_EXIST
= 0x01,
127 FTYPE_MODE_MUST_NOT_EXIST
= 0x02,
128 FTYPE_MODE_EXIST_MASK
= 0x03,
129 FTYPE_MODE_NO_OPEN
= 0x00,
130 FTYPE_MODE_OPEN_FD
= 0x10,
131 FTYPE_MODE_FOPEN_FP
= 0x20,
132 FTYPE_MODE_OPEN_MASK
= 0x30
137 char const * file_mode
;
140 typedef struct argList tArgList
;
141 #define MIN_ARG_ALLOC_CT 6
142 #define INCR_ARG_ALLOC_CT 8
146 char const * apzArgs
[MIN_ARG_ALLOC_CT
];
150 * Bits in the fOptState option descriptor field.
153 OPTST_SET_ID
= 0, /* Set via the "SET_OPT()" macro */
154 OPTST_PRESET_ID
= 1, /* Set via an RC/INI file */
155 OPTST_DEFINED_ID
= 2, /* Set via a command line option */
156 OPTST_RESET_ID
= 3, /* Reset via command line option */
157 OPTST_EQUIVALENCE_ID
= 4, /* selected by equiv'ed option */
158 OPTST_DISABLED_ID
= 5, /* option is in disabled state */
159 OPTST_ALLOC_ARG_ID
= 6, /* pzOptArg was allocated */
160 OPTST_NO_INIT_ID
= 8, /* option cannot be preset */
161 OPTST_NUMBER_OPT_ID
= 9, /* opt value (flag) is any digit */
162 OPTST_STACKED_ID
= 10, /* opt uses optionStackArg proc */
163 OPTST_INITENABLED_ID
= 11, /* option defaults to enabled */
164 OPTST_ARG_TYPE_1_ID
= 12, /* bit 1 of arg type enum */
165 OPTST_ARG_TYPE_2_ID
= 13, /* bit 2 of arg type enum */
166 OPTST_ARG_TYPE_3_ID
= 14, /* bit 3 of arg type enum */
167 OPTST_ARG_TYPE_4_ID
= 15, /* bit 4 of arg type enum */
168 OPTST_ARG_OPTIONAL_ID
= 16, /* the option arg not required */
169 OPTST_IMM_ID
= 17, /* process opt on first pass */
170 OPTST_DISABLE_IMM_ID
= 18, /* process disablement immed. */
171 OPTST_OMITTED_ID
= 19, /* compiled out of program */
172 OPTST_MUST_SET_ID
= 20, /* must be set or pre-set */
173 OPTST_DOCUMENT_ID
= 21, /* opt is for doc only */
174 OPTST_TWICE_ID
= 22, /* process opt twice - imm + reg */
175 OPTST_DISABLE_TWICE_ID
= 23, /* process disabled option twice */
176 OPTST_SCALED_NUM_ID
= 24, /* scaled integer value */
177 OPTST_NO_COMMAND_ID
= 25, /* disable from cmd line */
178 OPTST_DEPRECATED_ID
= 26, /* support is being removed */
179 OPTST_ALIAS_ID
= 27 /* alias for other option */
182 #define OPTST_INIT 0U
183 #define OPTST_SET (1U << OPTST_SET_ID)
184 #define OPTST_PRESET (1U << OPTST_PRESET_ID)
185 #define OPTST_DEFINED (1U << OPTST_DEFINED_ID)
186 #define OPTST_RESET (1U << OPTST_RESET_ID)
187 #define OPTST_EQUIVALENCE (1U << OPTST_EQUIVALENCE_ID)
188 #define OPTST_DISABLED (1U << OPTST_DISABLED_ID)
189 #define OPTST_ALLOC_ARG (1U << OPTST_ALLOC_ARG_ID)
190 #define OPTST_NO_INIT (1U << OPTST_NO_INIT_ID)
191 #define OPTST_NUMBER_OPT (1U << OPTST_NUMBER_OPT_ID)
192 #define OPTST_STACKED (1U << OPTST_STACKED_ID)
193 #define OPTST_INITENABLED (1U << OPTST_INITENABLED_ID)
194 #define OPTST_ARG_TYPE_1 (1U << OPTST_ARG_TYPE_1_ID)
195 #define OPTST_ARG_TYPE_2 (1U << OPTST_ARG_TYPE_2_ID)
196 #define OPTST_ARG_TYPE_3 (1U << OPTST_ARG_TYPE_3_ID)
197 #define OPTST_ARG_TYPE_4 (1U << OPTST_ARG_TYPE_4_ID)
198 #define OPTST_ARG_OPTIONAL (1U << OPTST_ARG_OPTIONAL_ID)
199 #define OPTST_IMM (1U << OPTST_IMM_ID)
200 #define OPTST_DISABLE_IMM (1U << OPTST_DISABLE_IMM_ID)
201 #define OPTST_OMITTED (1U << OPTST_OMITTED_ID)
202 #define OPTST_MUST_SET (1U << OPTST_MUST_SET_ID)
203 #define OPTST_DOCUMENT (1U << OPTST_DOCUMENT_ID)
204 #define OPTST_TWICE (1U << OPTST_TWICE_ID)
205 #define OPTST_DISABLE_TWICE (1U << OPTST_DISABLE_TWICE_ID)
206 #define OPTST_SCALED_NUM (1U << OPTST_SCALED_NUM_ID)
207 #define OPTST_NO_COMMAND (1U << OPTST_NO_COMMAND_ID)
208 #define OPTST_DEPRECATED (1U << OPTST_DEPRECATED_ID)
209 #define OPTST_ALIAS (1U << OPTST_ALIAS_ID)
210 #define OPT_STATE_MASK 0x0FFFFF7FU
212 #define OPTST_SET_MASK ( \
213 OPTST_DEFINED | OPTST_PRESET | OPTST_RESET | \
217 #define OPTST_MUTABLE_MASK ( \
218 OPTST_ALLOC_ARG | OPTST_DEFINED | \
219 OPTST_DISABLED | OPTST_EQUIVALENCE | \
220 OPTST_PRESET | OPTST_RESET | \
224 #define OPTST_SELECTED_MASK ( \
225 OPTST_DEFINED | OPTST_SET \
228 #define OPTST_ARG_TYPE_MASK ( \
229 OPTST_ARG_TYPE_1 | OPTST_ARG_TYPE_2 | OPTST_ARG_TYPE_3 | \
233 #define OPTST_NO_USAGE_MASK ( \
234 OPTST_DEPRECATED | OPTST_NO_COMMAND | OPTST_OMITTED \
237 #define OPTST_IMMUTABLE_MASK ( \
238 OPTST_DOCUMENT | OPTST_OMITTED \
241 #define OPTST_DO_NOT_SAVE_MASK ( \
242 OPTST_DOCUMENT | OPTST_NO_INIT | OPTST_OMITTED \
245 #define OPTST_NO_OUTPUT_MASK ( \
246 OPTST_ALIAS | OPTST_DOCUMENT | OPTST_OMITTED \
249 #ifdef NO_OPTIONAL_OPT_ARGS
250 # undef OPTST_ARG_OPTIONAL
251 # define OPTST_ARG_OPTIONAL 0
254 #define VENDOR_OPTION_VALUE 'W'
256 #define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK)
258 #define SELECTED_OPT(_od) ((_od)->fOptState & OPTST_SELECTED_MASK)
259 #define UNUSED_OPT( _od) (((_od)->fOptState & OPTST_SET_MASK) == 0)
260 #define DISABLED_OPT(_od) ((_od)->fOptState & OPTST_DISABLED)
261 #define OPTION_STATE(_od) ((_od)->fOptState)
262 #define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_1_ID)
263 #define OPTST_GET_ARGTYPE(_f) (((_f)&OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID)
268 * The following values are used in the generated code to communicate
269 * with the option library procedures. They are not for public use
270 * and may be subject to change.
274 * Define the processing state flags
277 OPTPROC_LONGOPT_ID
= 0, /* Process long style options */
278 OPTPROC_SHORTOPT_ID
= 1, /* Process short style "flags" */
279 OPTPROC_ERRSTOP_ID
= 2, /* Stop on argument errors */
280 OPTPROC_DISABLEDOPT_ID
= 3, /* Current option is disabled */
281 OPTPROC_NO_REQ_OPT_ID
= 4, /* no options are required */
282 OPTPROC_NUM_OPT_ID
= 5, /* there is a number option */
283 OPTPROC_INITDONE_ID
= 6, /* have inits been done? */
284 OPTPROC_NEGATIONS_ID
= 7, /* any negation options? */
285 OPTPROC_ENVIRON_ID
= 8, /* check environment? */
286 OPTPROC_NO_ARGS_ID
= 9, /* Disallow remaining arguments */
287 OPTPROC_ARGS_REQ_ID
= 10, /* Require args after options */
288 OPTPROC_REORDER_ID
= 11, /* reorder operands after opts */
289 OPTPROC_GNUUSAGE_ID
= 12, /* emit usage in GNU style */
290 OPTPROC_TRANSLATE_ID
= 13, /* Translate strings in tOptions */
291 OPTPROC_MISUSE_ID
= 14, /* no usage on usage error */
292 OPTPROC_IMMEDIATE_ID
= 15, /* immediate options active */
293 OPTPROC_NXLAT_OPT_CFG_ID
= 16, /* suppress for config only */
294 OPTPROC_NXLAT_OPT_ID
= 17, /* suppress xlation always */
295 OPTPROC_VENDOR_OPT_ID
= 18, /* vendor options active */
296 OPTPROC_PRESETTING_ID
= 19 /* opt processing in preset state */
297 } optproc_state_enum_t
;
299 #define OPTPROC_NONE 0U
300 #define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID)
301 #define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID)
302 #define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID)
303 #define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID)
304 #define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID)
305 #define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID)
306 #define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID)
307 #define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID)
308 #define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID)
309 #define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID)
310 #define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID)
311 #define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID)
312 #define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID)
313 #define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID)
314 #define OPTPROC_MISUSE (1U << OPTPROC_MISUSE_ID)
315 #define OPTPROC_IMMEDIATE (1U << OPTPROC_IMMEDIATE_ID)
316 #define OPTPROC_NXLAT_OPT_CFG (1U << OPTPROC_NXLAT_OPT_CFG_ID)
317 #define OPTPROC_NXLAT_OPT (1U << OPTPROC_NXLAT_OPT_ID)
318 #define OPTPROC_VENDOR_OPT (1U << OPTPROC_VENDOR_OPT_ID)
319 #define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID)
320 #define OPTPROC_STATE_MASK 0x000FFFFFU
322 #define OPTPROC_NO_XLAT_MASK ( \
323 OPTPROC_NXLAT_OPT | OPTPROC_NXLAT_OPT_CFG \
326 #define STMTS(s) do { s; } while (false)
329 * The following must be #defined instead of typedef-ed
330 * because "static const" cannot both be applied to a type,
331 * tho each individually can...so they all are
333 #define tSCC static char const
334 #define tCC char const
335 #define tAoSC static char
336 #define tAoUC unsigned char
337 #define tAoUI unsigned int
338 #define tAoUL unsigned long
339 #define tAoUS unsigned short
342 * It is so disgusting that there must be so many ways
343 * of specifying TRUE and FALSE.
345 typedef enum { AG_FALSE
= 0, AG_TRUE
} ag_bool
;
348 * Define a structure that describes each option and
349 * a pointer to the procedure that handles it.
350 * The argument is the count of this flag previously seen.
352 typedef struct options tOptions
;
353 typedef struct optDesc tOptDesc
;
354 typedef struct optNames tOptNames
;
355 #define OPTPROC_EMIT_USAGE ((tOptions *)0x01UL)
356 #define OPTPROC_EMIT_SHELL ((tOptions *)0x02UL)
357 #define OPTPROC_RETURN_VALNAME ((tOptions *)0x03UL)
358 #define OPTPROC_EMIT_LIMIT ((tOptions *)0x0FUL)
361 * The option procedures do the special processing for each
362 * option flag that needs it.
364 typedef void (tOptProc
)(tOptions
* pOpts
, tOptDesc
* pOptDesc
);
365 typedef tOptProc
* tpOptProc
;
368 * The usage procedure will never return. It calls "exit(2)"
369 * with the "exitCode" argument passed to it.
372 typedef void (tUsageProc
)(tOptions
* pOpts
, int exitCode
);
373 typedef tUsageProc
* tpUsageProc
;
376 * Special definitions. "NOLIMIT" is the 'max' value to use when
377 * a flag may appear multiple times without limit. "NO_EQUIVALENT"
378 * is an illegal value for 'optIndex' (option description index).
380 #define NOLIMIT USHRT_MAX
381 #define OPTION_LIMIT SHRT_MAX
382 #define NO_EQUIVALENT (OPTION_LIMIT+1)
385 char const * argString
;
389 unsigned long argUint
;
390 unsigned int argBool
;
395 #define pzLastArg optArg.argString
398 * Descriptor structure for each option.
399 * Only the fields marked "PUBLIC" are for public use.
402 tAoUS
const optIndex
; /* PUBLIC */
403 tAoUS
const optValue
; /* PUBLIC */
404 tAoUS optActualIndex
; /* PUBLIC */
405 tAoUS optActualValue
; /* PUBLIC */
407 tAoUS
const optEquivIndex
; /* PUBLIC */
408 tAoUS
const optMinCt
;
409 tAoUS
const optMaxCt
;
410 tAoUS optOccCt
; /* PUBLIC */
412 tAoUI fOptState
; /* PUBLIC */
414 optArgBucket_t optArg
; /* PUBLIC */
415 void* optCookie
; /* PUBLIC */
417 int const * const pOptMust
;
418 int const * const pOptCant
;
419 tpOptProc
const pOptProc
;
420 char const* const pzText
;
422 char const* const pz_NAME
;
423 char const* const pz_Name
;
424 char const* const pz_DisableName
;
425 char const* const pz_DisablePfx
;
429 * Some options need special processing, so we store their
430 * indexes in a known place:
432 typedef struct optSpecIndex tOptSpecIndex
;
433 struct optSpecIndex
{
434 const tAoUS more_help
;
435 const tAoUS save_opts
;
436 const tAoUS number_option
;
437 const tAoUS default_opt
;
441 * The procedure generated for translating option text
443 typedef void (tOptionXlateProc
)(void);
446 * Everything marked "PUBLIC" is also marked "const". Public access is not
447 * a license to modify. Other fields are used and modified by the library.
448 * They are also subject to change without any notice.
449 * Do not even look at these outside of libopts.
452 int const structVersion
;
453 unsigned int origArgCt
;
455 unsigned int fOptSet
;
456 unsigned int curOptIdx
;
459 char const* const pzProgPath
; /* PUBLIC */
460 char const* const pzProgName
; /* PUBLIC */
461 char const* const pzPROGNAME
; /* PUBLIC */
462 char const* const pzRcName
; /* PUBLIC */
463 char const* const pzCopyright
; /* PUBLIC */
464 char const* const pzCopyNotice
; /* PUBLIC */
465 char const* const pzFullVersion
; /* PUBLIC */
466 char const* const* const papzHomeList
;
467 char const* const pzUsageTitle
;
468 char const* const pzExplain
;
469 char const* const pzDetail
;
470 tOptDesc
* const pOptDesc
; /* PUBLIC */
471 char const* const pzBugAddr
; /* PUBLIC */
477 tpUsageProc pUsageProc
;
478 tOptionXlateProc
* pTransProc
;
480 tOptSpecIndex specOptIdx
;
482 int const presetOptCt
;
483 char const * pzFullUsage
;
484 char const * pzShortUsage
;
486 optArgBucket_t
const * const originalOptArgArray
;
487 void * const * const originalOptArgCookie
;
488 char const * const pzPkgDataDir
;
489 char const * const pzPackager
;
493 * Versions where in various fields first appear:
494 * ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero)
496 #define originalOptArgArray_STRUCT_VERSION 131072 /* AO_CURRENT = 32 */
497 #define HAS_originalOptArgArray(_opt) \
498 ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION)
500 #define pzPkgDataDir_STRUCT_VERSION 139264 /* AO_CURRENT = 34 */
501 #define HAS_pzPkgDataDir(_opt) \
502 ((_opt)->structVersion >= pzPkgDataDir_STRUCT_VERSION)
505 * "token list" structure returned by "string_tokenize()"
508 unsigned long tkn_ct
;
509 unsigned char* tkn_list
[1];
513 * Hide the interface - it pollutes a POSIX claim, but leave it for
514 * anyone #include-ing this header
516 #define strneqvcmp option_strneqvcmp
517 #define streqvcmp option_streqvcmp
518 #define streqvmap option_streqvmap
519 #define strequate option_strequate
520 #define strtransform option_strtransform
523 * Everything needed to be known about an mmap-ed file.
525 * This is an output only structure used by text_mmap and text_munmap.
526 * Clients must not alter the contents and must provide it to both
527 * the text_mmap and text_munmap procedures. BE ADVISED: if you are
528 * mapping the file with PROT_WRITE the NUL byte at the end MIGHT NOT
529 * BE WRITABLE. In any event, that byte is not be written back
530 * to the source file. ALSO: if "txt_data" is valid and "txt_errno"
531 * is not zero, then there *may* not be a terminating NUL.
534 void * txt_data
; /*@< text file data */
535 size_t txt_size
; /*@< actual file size */
536 size_t txt_full_size
; /*@< mmaped mem size */
537 int txt_fd
; /*@< file descriptor */
538 int txt_zero_fd
; /*@< fd for /dev/zero */
539 int txt_errno
; /*@< warning code */
540 int txt_prot
; /*@< "prot" flags */
541 int txt_flags
; /*@< mapping type */
544 #define TEXT_MMAP_FAILED_ADDR(a) ((void*)(a) == (void*)MAP_FAILED)
547 #define CPLUSPLUS_OPENER extern "C" {
549 #define CPLUSPLUS_CLOSER }
551 #define CPLUSPLUS_CLOSER
555 * The following routines may be coded into AutoOpts client code:
558 /* From: tokenize.c line 164
560 * ao_string_tokenize - tokenize an input string
563 * string string to be tokenized
565 * Returns: token_list_t* - pointer to a structure that lists each token
567 * This function will convert one input string into a list of strings.
568 * The list of strings is derived by separating the input based on
569 * white space separation. However, if the input contains either single
570 * or double quote characters, then the text after that character up to
571 * a matching quote will become the string in the list.
573 * The returned pointer should be deallocated with @code{free(3C)} when
574 * are done using the data. The data are placed in a single block of
575 * allocated memory. Do not deallocate individual token/strings.
577 * The structure pointed to will contain at least these two fields:
580 * The number of tokens found in the input string.
582 * An array of @code{tkn_ct + 1} pointers to substring tokens, with
583 * the last pointer set to NULL.
586 * There are two types of quoted strings: single quoted (@code{'}) and
587 * double quoted (@code{"}). Singly quoted strings are fairly raw in that
588 * escape characters (@code{\\}) are simply another character, except when
589 * preceding the following characters:
591 * @code{\\} double backslashes reduce to one
592 * @code{'} incorporates the single quote into the string
593 * @code{\n} suppresses both the backslash and newline character
596 * Double quote strings are formed according to the rules of string
597 * constants in ANSI-C programs.
599 extern token_list_t
* ao_string_tokenize(char const*);
602 /* From: configfile.c line 77
604 * configFileLoad - parse a configuration file
607 * pzFile the file to load
609 * Returns: const tOptionValue* - An allocated, compound value structure
611 * This routine will load a named configuration file and parse the
612 * text as a hierarchically valued option. The option descriptor
613 * created from an option definition file is not used via this interface.
614 * The returned value is "named" with the input file name and is of
615 * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to
616 * @code{optionGetValue()}, @code{optionNextValue()} and
617 * @code{optionUnloadNested()}.
619 extern const tOptionValue
* configFileLoad(char const*);
622 /* From: configfile.c line 1066
624 * optionFileLoad - Load the locatable config files, in order
627 * pOpts program options descriptor
628 * pzProg program name
630 * Returns: int - 0 -> SUCCESS, -1 -> FAILURE
632 * This function looks in all the specified directories for a configuration
633 * file ("rc" file or "ini" file) and processes any found twice. The first
634 * time through, they are processed in reverse order (last file first). At
635 * that time, only "immediate action" configurables are processed. For
636 * example, if the last named file specifies not processing any more
637 * configuration files, then no more configuration files will be processed.
638 * Such an option in the @strong{first} named directory will have no effect.
640 * Once the immediate action configurables have been handled, then the
641 * directories are handled in normal, forward order. In that way, later
642 * config files can override the settings of earlier config files.
644 * See the AutoOpts documentation for a thorough discussion of the
645 * config file format.
647 * Configuration files not found or not decipherable are simply ignored.
649 extern int optionFileLoad(tOptions
*, char const*);
652 /* From: configfile.c line 211
654 * optionFindNextValue - find a hierarcicaly valued option instance
657 * pOptDesc an option with a nested arg type
658 * pPrevVal the last entry
659 * name name of value to find
660 * value the matching value
662 * Returns: const tOptionValue* - a compound value structure
664 * This routine will find the next entry in a nested value option or
665 * configurable. It will search through the list and return the next entry
666 * that matches the criteria.
668 extern const tOptionValue
* optionFindNextValue(const tOptDesc
*, const tOptionValue
*, char const*, char const*);
671 /* From: configfile.c line 137
673 * optionFindValue - find a hierarcicaly valued option instance
676 * pOptDesc an option with a nested arg type
677 * name name of value to find
678 * value the matching value
680 * Returns: const tOptionValue* - a compound value structure
682 * This routine will find an entry in a nested value option or configurable.
683 * It will search through the list and return a matching entry.
685 extern const tOptionValue
* optionFindValue(const tOptDesc
*, char const*, char const*);
688 /* From: restore.c line 166
690 * optionFree - free allocated option processing memory
693 * pOpts program options descriptor
695 * AutoOpts sometimes allocates memory and puts pointers to it in the
696 * option state structures. This routine deallocates all such memory.
698 extern void optionFree(tOptions
*);
701 /* From: configfile.c line 280
703 * optionGetValue - get a specific value from a hierarcical list
706 * pOptValue a hierarchcal value
707 * valueName name of value to get
709 * Returns: const tOptionValue* - a compound value structure
711 * This routine will find an entry in a nested value option or configurable.
712 * If "valueName" is NULL, then the first entry is returned. Otherwise,
713 * the first entry with a name that exactly matches the argument will be
714 * returned. If there is no matching value, NULL is returned and errno is
715 * set to ENOENT. If the provided option value is not a hierarchical value,
716 * NULL is also returned and errno is set to EINVAL.
718 extern const tOptionValue
* optionGetValue(const tOptionValue
*, char const*);
721 /* From: load.c line 475
723 * optionLoadLine - process a string for an option name and value
726 * pOpts program options descriptor
727 * pzLine NUL-terminated text
729 * This is a client program callable routine for setting options from, for
730 * example, the contents of a file that they read in. Only one option may
731 * appear in the text. It will be treated as a normal (non-preset) option.
733 * When passed a pointer to the option struct and a string, it will find
734 * the option named by the first token on the string and set the option
735 * argument to the remainder of the string. The caller must NUL terminate
736 * the string. Any embedded new lines will be included in the option
737 * argument. If the input looks like one or more quoted strings, then the
738 * input will be "cooked". The "cooking" is identical to the string
739 * formation used in AutoGen definition files (@pxref{basic expression}),
740 * except that you may not use backquotes.
742 extern void optionLoadLine(tOptions
*, char const*);
745 /* From: configfile.c line 340
747 * optionNextValue - get the next value from a hierarchical list
750 * pOptValue a hierarchcal list value
751 * pOldValue a value from this list
753 * Returns: const tOptionValue* - a compound value structure
755 * This routine will return the next entry after the entry passed in. At the
756 * end of the list, NULL will be returned. If the entry is not found on the
757 * list, NULL will be returned and "@var{errno}" will be set to EINVAL.
758 * The "@var{pOldValue}" must have been gotten from a prior call to this
759 * routine or to "@code{opitonGetValue()}".
761 extern const tOptionValue
* optionNextValue(const tOptionValue
*, const tOptionValue
*);
764 /* From: usage.c line 201
766 * optionOnlyUsage - Print usage text for just the options
769 * pOpts program options descriptor
770 * ex_code exit code for calling exit(3)
772 * This routine will print only the usage for each option.
773 * This function may be used when the emitted usage must incorporate
774 * information not available to AutoOpts.
776 extern void optionOnlyUsage(tOptions
*, int);
779 /* From: autoopts.c line 607
781 * optionProcess - this is the main option processing routine
784 * pOpts program options descriptor
785 * argc program arg count
786 * argv program arg vector
788 * Returns: int - the count of the arguments processed
790 * This is the main entry point for processing options. It is intended
791 * that this procedure be called once at the beginning of the execution of
792 * a program. Depending on options selected earlier, it is sometimes
793 * necessary to stop and restart option processing, or to select completely
794 * different sets of options. This can be done easily, but you generally
795 * do not want to do this.
797 * The number of arguments processed always includes the program name.
798 * If one of the arguments is "--", then it is counted and the processing
799 * stops. If an error was encountered and errors are to be tolerated, then
800 * the returned value is the index of the argument causing the error.
801 * A hyphen by itself ("-") will also cause processing to stop and will
802 * @emph{not} be counted among the processed arguments. A hyphen by itself
803 * is treated as an operand. Encountering an operand stops option
806 extern int optionProcess(tOptions
*, int, char**);
809 /* From: restore.c line 123
811 * optionRestore - restore option state from memory copy
814 * pOpts program options descriptor
816 * Copy back the option state from saved memory.
817 * The allocated memory is left intact, so this routine can be
818 * called repeatedly without having to call optionSaveState again.
819 * If you are restoring a state that was saved before the first call
820 * to optionProcess(3AO), then you may change the contents of the
821 * argc/argv parameters to optionProcess.
823 extern void optionRestore(tOptions
*);
826 /* From: save.c line 648
828 * optionSaveFile - saves the option state to a file
831 * pOpts program options descriptor
833 * This routine will save the state of option processing to a file. The name
834 * of that file can be specified with the argument to the @code{--save-opts}
835 * option, or by appending the @code{rcfile} attribute to the last
836 * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it
837 * will default to @code{.@i{programname}rc}. If you wish to specify another
838 * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro.
840 * The recommend usage is as follows:
842 * optionProcess(&progOptions, argc, argv);
843 * if (i_want_a_non_standard_place_for_this)
844 * SET_OPT_SAVE_OPTS("myfilename");
845 * optionSaveFile(&progOptions);
848 extern void optionSaveFile(tOptions
*);
851 /* From: restore.c line 71
853 * optionSaveState - saves the option state to memory
856 * pOpts program options descriptor
858 * This routine will allocate enough memory to save the current option
859 * processing state. If this routine has been called before, that memory
860 * will be reused. You may only save one copy of the option state. This
861 * routine may be called before optionProcess(3AO). If you do call it
862 * before the first call to optionProcess, then you may also change the
863 * contents of argc/argv after you call optionRestore(3AO)
865 * In fact, more strongly put: it is safest to only use this function
866 * before having processed any options. In particular, the saving and
867 * restoring of stacked string arguments and hierarchical values is
868 * disabled. The values are not saved.
870 extern void optionSaveState(tOptions
*);
873 /* From: nested.c line 563
875 * optionUnloadNested - Deallocate the memory for a nested value
878 * pOptVal the hierarchical value
880 * A nested value needs to be deallocated. The pointer passed in should
881 * have been gotten from a call to @code{configFileLoad()} (See
882 * @pxref{libopts-configFileLoad}).
884 extern void optionUnloadNested(tOptionValue
const *);
887 /* From: version.c line 31
889 * optionVersion - return the compiled AutoOpts version number
891 * Returns: char const* - the version string in constant memory
893 * Returns the full version string compiled into the library.
894 * The returned string cannot be modified.
896 extern char const* optionVersion(void);
899 /* From: ../compat/pathfind.c line 29
901 * pathfind - fild a file in a list of directories
904 * path colon separated list of search directories
905 * file the name of the file to look for
906 * mode the mode bits that must be set to match
908 * Returns: char* - the path to the located file
910 * the pathfind function is available only if HAVE_PATHFIND is not defined
912 * pathfind looks for a a file with name "FILE" and "MODE" access
913 * along colon delimited "PATH", and returns the full pathname as a
914 * string, or NULL if not found. If "FILE" contains a slash, then
915 * it is treated as a relative or absolute path and "PATH" is ignored.
917 * @strong{NOTE}: this function is compiled into @file{libopts} only if
918 * it is not natively supplied.
920 * The "MODE" argument is a string of option letters chosen from the
927 * f normal file (NOT IMPLEMENTED)
928 * b block special (NOT IMPLEMENTED)
929 * c character special (NOT IMPLEMENTED)
930 * d directory (NOT IMPLEMENTED)
931 * p FIFO (pipe) (NOT IMPLEMENTED)
932 * u set user ID bit (NOT IMPLEMENTED)
933 * g set group ID bit (NOT IMPLEMENTED)
934 * k sticky bit (NOT IMPLEMENTED)
935 * s size nonzero (NOT IMPLEMENTED)
938 #ifndef HAVE_PATHFIND
939 extern char* pathfind(char const*, char const*, char const*);
940 #endif /* HAVE_PATHFIND */
943 /* From: streqvcmp.c line 209
945 * strequate - map a list of characters to the same value
948 * ch_list characters to equivalence
950 * Each character in the input string get mapped to the first character
952 * This function name is mapped to option_strequate so as to not conflict
953 * with the POSIX name space.
955 extern void strequate(char const*);
958 /* From: streqvcmp.c line 119
960 * streqvcmp - compare two strings with an equivalence mapping
966 * Returns: int - the difference between two differing characters
968 * Using a character mapping, two strings are compared for "equivalence".
969 * Each input character is mapped to a comparison character and the
970 * mapped-to characters are compared for the two NUL terminated input strings.
971 * This function name is mapped to option_streqvcmp so as to not conflict
972 * with the POSIX name space.
974 extern int streqvcmp(char const*, char const*);
977 /* From: streqvcmp.c line 156
979 * streqvmap - Set the character mappings for the streqv functions
982 * From Input character
983 * To Mapped-to character
986 * Set the character mapping. If the count (@code{ct}) is set to zero, then
987 * the map is cleared by setting all entries in the map to their index
988 * value. Otherwise, the "@code{From}" character is mapped to the "@code{To}"
989 * character. If @code{ct} is greater than 1, then @code{From} and @code{To}
990 * are incremented and the process repeated until @code{ct} entries have been
993 * streqvmap('a', 'A', 26);
996 * will alter the mapping so that all English lower case letters
997 * will map to upper case.
999 * This function name is mapped to option_streqvmap so as to not conflict
1000 * with the POSIX name space.
1002 extern void streqvmap(char, char, int);
1005 /* From: streqvcmp.c line 78
1007 * strneqvcmp - compare two strings with an equivalence mapping
1011 * str2 second string
1014 * Returns: int - the difference between two differing characters
1016 * Using a character mapping, two strings are compared for "equivalence".
1017 * Each input character is mapped to a comparison character and the
1018 * mapped-to characters are compared for the two NUL terminated input strings.
1019 * The comparison is limited to @code{ct} bytes.
1020 * This function name is mapped to option_strneqvcmp so as to not conflict
1021 * with the POSIX name space.
1023 extern int strneqvcmp(char const*, char const*, int);
1026 /* From: streqvcmp.c line 235
1028 * strtransform - convert a string into its mapped-to value
1031 * dest output string
1034 * Each character in the input string is mapped and the mapped-to
1035 * character is put into the output.
1036 * This function name is mapped to option_strtransform so as to not conflict
1037 * with the POSIX name space.
1039 * The source and destination may be the same.
1041 extern void strtransform(char*, char const*);
1043 /* AutoOpts PRIVATE FUNCTIONS: */
1044 tOptProc optionStackArg
, optionUnstackArg
, optionBooleanVal
, optionNumericVal
;
1046 extern char* ao_string_cook(char*, int*);
1048 extern unsigned int ao_string_cook_escape_char(char const*, char*, unsigned int);
1050 extern void genshelloptUsage(tOptions
*, int);
1052 extern int optionAlias(tOptions
*, tOptDesc
*, unsigned int);
1054 extern void optionBooleanVal(tOptions
*, tOptDesc
*);
1056 extern uintptr_t optionEnumerationVal(tOptions
*, tOptDesc
*, char const * const *, unsigned int);
1058 extern void optionFileCheck(tOptions
*, tOptDesc
*, teOptFileType
, tuFileMode
);
1060 extern char const * optionKeywordName(tOptDesc
*, unsigned int);
1062 extern void optionLoadOpt(tOptions
*, tOptDesc
*);
1064 extern bool optionMakePath(char*, int, char const*, char const*);
1066 extern void optionNestedVal(tOptions
*, tOptDesc
*);
1068 extern void optionNumericVal(tOptions
*, tOptDesc
*);
1070 extern void optionPagedUsage(tOptions
*, tOptDesc
*);
1072 extern void optionParseShell(tOptions
*);
1074 extern void optionPrintVersion(tOptions
*, tOptDesc
*);
1076 extern void optionPutShell(tOptions
*);
1078 extern void optionResetOpt(tOptions
*, tOptDesc
*);
1080 extern void optionSetMembers(tOptions
*, tOptDesc
*, char const * const *, unsigned int);
1082 extern void optionShowRange(tOptions
*, tOptDesc
*, void *, int);
1084 extern void optionStackArg(tOptions
*, tOptDesc
*);
1086 extern void optionTimeDate(tOptions
*, tOptDesc
*);
1088 extern void optionTimeVal(tOptions
*, tOptDesc
*);
1090 extern void optionUnstackArg(tOptions
*, tOptDesc
*);
1092 extern void optionUsage(tOptions
*, int);
1094 extern void optionVendorOption(tOptions
*, tOptDesc
*);
1096 extern void optionVersionStderr(tOptions
*, tOptDesc
*);
1098 extern void* text_mmap(char const*, int, int, tmap_info_t
*);
1100 extern int text_munmap(tmap_info_t
*);
1103 #endif /* AUTOOPTS_OPTIONS_H_GUARD */
1106 * c-file-style: "stroustrup"
1107 * indent-tabs-mode: nil
1109 * options.h ends here */