xref: /freebsd/contrib/ntp/sntp/libopts/autoopts/options.h (revision a466cc55373fc3cf86837f09da729535b57e69a1)
1ea906c41SOllivier Robert /*   -*- buffer-read-only: t -*- vi: set ro:
2ea906c41SOllivier Robert  *
3ea906c41SOllivier Robert  *  DO NOT EDIT THIS FILE   (options.h)
4ea906c41SOllivier Robert  *
5276da39aSCy Schubert  *  It has been AutoGen-ed
6ea906c41SOllivier Robert  *  From the definitions    funcs.def
7ea906c41SOllivier Robert  *  and the template file   options_h
8ea906c41SOllivier Robert  *
9ea906c41SOllivier Robert  *  This file defines all the global structures and special values
10ea906c41SOllivier Robert  *  used in the automated option processing library.
11ea906c41SOllivier Robert  *
12*a466cc55SCy Schubert  *  Automated Options Copyright (C) 1992-2018 by Bruce Korb
13ea906c41SOllivier Robert  *
142b15cb3dSCy Schubert  *  This file is part of AutoOpts, a companion to AutoGen.
152b15cb3dSCy Schubert  *  AutoOpts is free software.
16*a466cc55SCy Schubert  *  AutoOpts is Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
17ea906c41SOllivier Robert  *
182b15cb3dSCy Schubert  *  AutoOpts is available under any one of two licenses.  The license
192b15cb3dSCy Schubert  *  in use must be one of these two and the choice is under the control
202b15cb3dSCy Schubert  *  of the user of the license.
21ea906c41SOllivier Robert  *
222b15cb3dSCy Schubert  *   The GNU Lesser General Public License, version 3 or later
232b15cb3dSCy Schubert  *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
242b15cb3dSCy Schubert  *
252b15cb3dSCy Schubert  *   The Modified Berkeley Software Distribution License
262b15cb3dSCy Schubert  *      See the file "COPYING.mbsd"
272b15cb3dSCy Schubert  *
282b15cb3dSCy Schubert  *  These files have the following sha256 sums:
292b15cb3dSCy Schubert  *
302b15cb3dSCy Schubert  *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
312b15cb3dSCy Schubert  *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
322b15cb3dSCy Schubert  *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
33ea906c41SOllivier Robert  */
34ea906c41SOllivier Robert #ifndef AUTOOPTS_OPTIONS_H_GUARD
352b15cb3dSCy Schubert #define AUTOOPTS_OPTIONS_H_GUARD 1
362b15cb3dSCy Schubert /** \file options.h
372b15cb3dSCy Schubert  *
382b15cb3dSCy Schubert  * @addtogroup autoopts
392b15cb3dSCy Schubert  * @{
402b15cb3dSCy Schubert  */
41ea906c41SOllivier Robert #include <sys/types.h>
422b15cb3dSCy Schubert #include <stdio.h>
43ea906c41SOllivier Robert 
442b15cb3dSCy Schubert #ifndef COMPAT_H_GUARD
452b15cb3dSCy Schubert /*
462b15cb3dSCy Schubert  * This is needed for test compilations where the "compat.h"
472b15cb3dSCy Schubert  * header is not usually available.
482b15cb3dSCy Schubert  */
49ea906c41SOllivier Robert #  if defined(HAVE_STDINT_H)
50ea906c41SOllivier Robert #    include <stdint.h>
51ea906c41SOllivier Robert #  elif defined(HAVE_INTTYPES_H)
52ea906c41SOllivier Robert #    include <inttypes.h>
53ea906c41SOllivier Robert #  endif /* HAVE_STDINT/INTTYPES_H */
54ea906c41SOllivier Robert 
55ea906c41SOllivier Robert #  if defined(HAVE_LIMITS_H)
56ea906c41SOllivier Robert #    include <limits.h>
57ea906c41SOllivier Robert #  elif defined(HAVE_SYS_LIMITS_H)
58ea906c41SOllivier Robert #    include <sys/limits.h>
59ea906c41SOllivier Robert #  endif /* HAVE_LIMITS/SYS_LIMITS_H */
60ea906c41SOllivier Robert 
61ea906c41SOllivier Robert #  if defined(HAVE_SYSEXITS_H)
62ea906c41SOllivier Robert #    include <sysexits.h>
63ea906c41SOllivier Robert #  endif /* HAVE_SYSEXITS_H */
64ea906c41SOllivier Robert 
652b15cb3dSCy Schubert #  if defined(HAVE_STDBOOL_H)
662b15cb3dSCy Schubert #    include <stdbool.h>
67*a466cc55SCy Schubert #  elif ! defined(bool)
682b15cb3dSCy Schubert      typedef enum { false = 0, true = 1 } _Bool;
692b15cb3dSCy Schubert #    define bool _Bool
70ea906c41SOllivier Robert 
712b15cb3dSCy Schubert      /* The other macros must be usable in preprocessor directives.  */
722b15cb3dSCy Schubert #    define false 0
732b15cb3dSCy Schubert #    define true 1
742b15cb3dSCy Schubert #  endif /* HAVE_SYSEXITS_H */
752b15cb3dSCy Schubert #endif /* COMPAT_H_GUARD */
762b15cb3dSCy Schubert // END-CONFIGURED-HEADERS
772b15cb3dSCy Schubert 
782b15cb3dSCy Schubert /**
792b15cb3dSCy Schubert  * Defined to abnormal value of EX_USAGE.  Used to indicate that paged usage
802b15cb3dSCy Schubert  * was requested.  It is used to distinguish a --usage from a --help request.
812b15cb3dSCy Schubert  * --usage is abbreviated and --help gives as much help as possible.
822b15cb3dSCy Schubert  */
832b15cb3dSCy Schubert #define AO_EXIT_REQ_USAGE 10064
842b15cb3dSCy Schubert 
85276da39aSCy Schubert #undef  VOIDP
86276da39aSCy Schubert /**
87276da39aSCy Schubert  * Coerce a value into a void pointer with no const or volatile attributes.
88276da39aSCy Schubert  * Somewhere along the line, the above set of includes need to set up
89276da39aSCy Schubert  * the "uintptr_t" type.
90276da39aSCy Schubert  */
91276da39aSCy Schubert #define VOIDP(_a)  ((void *)(uintptr_t)(_a))
92276da39aSCy Schubert 
932b15cb3dSCy Schubert /**
94ea906c41SOllivier Robert  *  PUBLIC DEFINES
95ea906c41SOllivier Robert  *
96ea906c41SOllivier Robert  *  The following defines may be used in applications that need to test the
97ea906c41SOllivier Robert  *  state of an option.  To test against these masks and values, a pointer
98ea906c41SOllivier Robert  *  to an option descriptor must be obtained.  There are two ways:
99ea906c41SOllivier Robert  *
100ea906c41SOllivier Robert  *  1. inside an option processing procedure, it is the second argument,
101ea906c41SOllivier Robert  *     conventionally "tOptDesc * pOD".
102ea906c41SOllivier Robert  *
103ea906c41SOllivier Robert  *  2. Outside of an option procedure (or to reference a different option
104ea906c41SOllivier Robert  *     descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )".
105ea906c41SOllivier Robert  *
106ea906c41SOllivier Robert  *  See the relevant generated header file to determine which and what
107ea906c41SOllivier Robert  *  values for "opt_name" are available.
1082b15cb3dSCy Schubert  * @group version
1092b15cb3dSCy Schubert  * @{
110ea906c41SOllivier Robert  */
1112b15cb3dSCy Schubert /// autoopts structure version
112*a466cc55SCy Schubert #define OPTIONS_STRUCT_VERSION      172033
1132b15cb3dSCy Schubert /// autoopts structure version string
114*a466cc55SCy Schubert #define OPTIONS_VERSION_STRING      "42:1:17"
1152b15cb3dSCy Schubert /// minimum version the autoopts library supports
116ea906c41SOllivier Robert #define OPTIONS_MINIMUM_VERSION     102400
1172b15cb3dSCy Schubert /// minimum version the autoopts library supports as a string
118ea906c41SOllivier Robert #define OPTIONS_MIN_VER_STRING      "25:0:0"
1192b15cb3dSCy Schubert /// the display version of the autoopts library, as a string
120*a466cc55SCy Schubert #define OPTIONS_DOTTED_VERSION      "42.1"
1212b15cb3dSCy Schubert /// convert a version/release number pair to an integer value
1222b15cb3dSCy Schubert #define OPTIONS_VER_TO_NUM(_v, _r)  (((_v) * 4096) + (_r))
1232b15cb3dSCy Schubert /// @}
124ea906c41SOllivier Robert 
1252b15cb3dSCy Schubert /**
1262b15cb3dSCy Schubert  * Option argument types.  This must fit in the OPTST_ARG_TYPE_MASK
1272b15cb3dSCy Schubert  * field of the fOptState field of an option descriptor (tOptDesc).
1282b15cb3dSCy Schubert  * It will be a problem to extend beyond 4 bits.
1292b15cb3dSCy Schubert  */
130ea906c41SOllivier Robert typedef enum {
1312b15cb3dSCy Schubert     OPARG_TYPE_NONE         =  0, ///< does not take an argument
1322b15cb3dSCy Schubert     OPARG_TYPE_STRING       =  1, ///< default type/ vanilla string
1332b15cb3dSCy Schubert     OPARG_TYPE_ENUMERATION  =  2, ///< opt arg is an enum (keyword list)
1342b15cb3dSCy Schubert     OPARG_TYPE_BOOLEAN      =  3, ///< opt arg is boolean-valued
1352b15cb3dSCy Schubert     OPARG_TYPE_MEMBERSHIP   =  4, ///< opt arg sets set membership bits
1362b15cb3dSCy Schubert     OPARG_TYPE_NUMERIC      =  5, ///< opt arg is a long int
1372b15cb3dSCy Schubert     OPARG_TYPE_HIERARCHY    =  6, ///< option arg is hierarchical value
1382b15cb3dSCy Schubert     OPARG_TYPE_FILE         =  7, ///< option arg names a file
1392b15cb3dSCy Schubert     OPARG_TYPE_TIME         =  8, ///< opt arg is a time duration
1402b15cb3dSCy Schubert     OPARG_TYPE_FLOAT        =  9, ///< opt arg is a floating point num
1412b15cb3dSCy Schubert     OPARG_TYPE_DOUBLE       = 10, ///< opt arg is a double prec. float
1422b15cb3dSCy Schubert     OPARG_TYPE_LONG_DOUBLE  = 11, ///< opt arg is a long double prec.
143*a466cc55SCy Schubert     OPARG_TYPE_LONG_LONG    = 12, ///< opt arg is a long long int
144*a466cc55SCy Schubert     OPARG_TYPE_STATIC       = 13  ///<
145ea906c41SOllivier Robert } teOptArgType;
146ea906c41SOllivier Robert 
1472b15cb3dSCy Schubert /**
1482b15cb3dSCy Schubert  * value descriptor for sub options
1492b15cb3dSCy Schubert  */
150ea906c41SOllivier Robert typedef struct optionValue {
1512b15cb3dSCy Schubert     teOptArgType        valType;        ///< which argument type
1522b15cb3dSCy Schubert     char *              pzName;         ///< name of the sub-option
153ea906c41SOllivier Robert     union {
1542b15cb3dSCy Schubert         char            strVal[1];      ///< OPARG_TYPE_STRING
1552b15cb3dSCy Schubert         unsigned int    enumVal;        ///< OPARG_TYPE_ENUMERATION
1562b15cb3dSCy Schubert         unsigned int    boolVal;        ///< OPARG_TYPE_BOOLEAN
1572b15cb3dSCy Schubert         unsigned long   setVal;         ///< OPARG_TYPE_MEMBERSHIP
1582b15cb3dSCy Schubert         long            longVal;        ///< OPARG_TYPE_NUMERIC
1592b15cb3dSCy Schubert         void *          nestVal;        ///< OPARG_TYPE_HIERARCHY
160ea906c41SOllivier Robert     } v;
161ea906c41SOllivier Robert } tOptionValue;
162ea906c41SOllivier Robert 
1632b15cb3dSCy Schubert /**
1642b15cb3dSCy Schubert  * file argument state and handling.
165ea906c41SOllivier Robert  */
166ea906c41SOllivier Robert typedef enum {
1672b15cb3dSCy Schubert     FTYPE_MODE_MAY_EXIST        = 0x00, ///< may or may not exist
1682b15cb3dSCy Schubert     FTYPE_MODE_MUST_EXIST       = 0x01, ///< must pre-exist
1692b15cb3dSCy Schubert     FTYPE_MODE_MUST_NOT_EXIST   = 0x02, ///< must *not* pre-exist
1702b15cb3dSCy Schubert     FTYPE_MODE_EXIST_MASK       = 0x03, ///< mask for these bits
1712b15cb3dSCy Schubert     FTYPE_MODE_NO_OPEN          = 0x00, ///< leave file closed
1722b15cb3dSCy Schubert     FTYPE_MODE_OPEN_FD          = 0x10, ///< call open(2)
1732b15cb3dSCy Schubert     FTYPE_MODE_FOPEN_FP         = 0x20, ///< call fopen(3)
1742b15cb3dSCy Schubert     FTYPE_MODE_OPEN_MASK        = 0x30  ///< open/fopen/not open
1752b15cb3dSCy Schubert } teOptFileType;
176ea906c41SOllivier Robert 
1772b15cb3dSCy Schubert /**
1782b15cb3dSCy Schubert  * the open flag bits or the mode string, depending on the open type.
1792b15cb3dSCy Schubert  */
1802b15cb3dSCy Schubert typedef union {
1812b15cb3dSCy Schubert     int             file_flags;  ///< open(2) flag bits
1822b15cb3dSCy Schubert     char const *    file_mode;   ///< fopen(3) mode string
1832b15cb3dSCy Schubert } tuFileMode;
184ea906c41SOllivier Robert 
1852b15cb3dSCy Schubert /// initial number of option argument holders to allocate
1862b15cb3dSCy Schubert #define MIN_ARG_ALLOC_CT   6
1872b15cb3dSCy Schubert /// amount by which to increment the argument holder allocation.
1882b15cb3dSCy Schubert #define INCR_ARG_ALLOC_CT  8
1892b15cb3dSCy Schubert /**
1902b15cb3dSCy Schubert  * an argument list.  When an option appears multiple times and
1912b15cb3dSCy Schubert  * the values get "stacked".  \a apzArgs  holds 8 pointers initially
1922b15cb3dSCy Schubert  * and is incremented by \a INCR_ARG_ALLOC_CT as needed.
1932b15cb3dSCy Schubert  */
1942b15cb3dSCy Schubert typedef struct {
1952b15cb3dSCy Schubert     int             useCt;  ///< elements in use
196ea906c41SOllivier Robert 
1972b15cb3dSCy Schubert     /// allocated elements, mininum \a MIN_ARG_ALLOC_CT
1982b15cb3dSCy Schubert     /// steps by \a INCR_ARG_ALLOC_CT
1992b15cb3dSCy Schubert     int             allocCt;
2002b15cb3dSCy Schubert     char const *    apzArgs[MIN_ARG_ALLOC_CT]; ///< element array
2012b15cb3dSCy Schubert } tArgList;
202ea906c41SOllivier Robert 
2032b15cb3dSCy Schubert /**
2042b15cb3dSCy Schubert  *  Bits in the fOptState option descriptor field.
2052b15cb3dSCy Schubert  * @{
2062b15cb3dSCy Schubert  */
207ea906c41SOllivier Robert 
2082b15cb3dSCy Schubert /** integral type for holding opt_state masks */
2092b15cb3dSCy Schubert typedef uint32_t opt_state_mask_t;
2102b15cb3dSCy Schubert 
2112b15cb3dSCy Schubert #define OPTST_ARG_TYPE_SHIFT 12
2122b15cb3dSCy Schubert /** bits defined for opt_state_mask_t */
2132b15cb3dSCy Schubert /** Set via the "SET_OPT()" macro */
2142b15cb3dSCy Schubert #define OPTST_SET              0x0000001U
2152b15cb3dSCy Schubert /** Set via an RC/INI file */
2162b15cb3dSCy Schubert #define OPTST_PRESET           0x0000002U
2172b15cb3dSCy Schubert /** Set via a command line option */
2182b15cb3dSCy Schubert #define OPTST_DEFINED          0x0000004U
2192b15cb3dSCy Schubert /** Reset via command line option */
2202b15cb3dSCy Schubert #define OPTST_RESET            0x0000008U
2212b15cb3dSCy Schubert /** selected by equiv'ed option */
2222b15cb3dSCy Schubert #define OPTST_EQUIVALENCE      0x0000010U
2232b15cb3dSCy Schubert /** option is in disabled state */
2242b15cb3dSCy Schubert #define OPTST_DISABLED         0x0000020U
2252b15cb3dSCy Schubert /** pzOptArg was allocated */
2262b15cb3dSCy Schubert #define OPTST_ALLOC_ARG        0x0000040U
2272b15cb3dSCy Schubert /** option cannot be preset */
2282b15cb3dSCy Schubert #define OPTST_NO_INIT          0x0000100U
2292b15cb3dSCy Schubert /** opt value (flag) is any digit */
2302b15cb3dSCy Schubert #define OPTST_NUMBER_OPT       0x0000200U
2312b15cb3dSCy Schubert /** opt uses optionStackArg proc */
2322b15cb3dSCy Schubert #define OPTST_STACKED          0x0000400U
2332b15cb3dSCy Schubert /** option defaults to enabled */
2342b15cb3dSCy Schubert #define OPTST_INITENABLED      0x0000800U
2352b15cb3dSCy Schubert /** bit 1 of arg type enum */
2362b15cb3dSCy Schubert #define OPTST_ARG_TYPE_1       0x0001000U
2372b15cb3dSCy Schubert /** bit 2 of arg type enum */
2382b15cb3dSCy Schubert #define OPTST_ARG_TYPE_2       0x0002000U
2392b15cb3dSCy Schubert /** bit 3 of arg type enum */
2402b15cb3dSCy Schubert #define OPTST_ARG_TYPE_3       0x0004000U
2412b15cb3dSCy Schubert /** bit 4 of arg type enum */
2422b15cb3dSCy Schubert #define OPTST_ARG_TYPE_4       0x0008000U
2432b15cb3dSCy Schubert /** the option arg not required */
2442b15cb3dSCy Schubert #define OPTST_ARG_OPTIONAL     0x0010000U
2452b15cb3dSCy Schubert /** process opt on first pass */
2462b15cb3dSCy Schubert #define OPTST_IMM              0x0020000U
2472b15cb3dSCy Schubert /** process disablement immed. */
2482b15cb3dSCy Schubert #define OPTST_DISABLE_IMM      0x0040000U
2492b15cb3dSCy Schubert /** compiled out of program */
2502b15cb3dSCy Schubert #define OPTST_OMITTED          0x0080000U
2512b15cb3dSCy Schubert /** must be set or pre-set */
2522b15cb3dSCy Schubert #define OPTST_MUST_SET         0x0100000U
2532b15cb3dSCy Schubert /** opt is for doc only */
2542b15cb3dSCy Schubert #define OPTST_DOCUMENT         0x0200000U
2552b15cb3dSCy Schubert /** process opt twice - imm + reg */
2562b15cb3dSCy Schubert #define OPTST_TWICE            0x0400000U
2572b15cb3dSCy Schubert /** process disabled option twice */
2582b15cb3dSCy Schubert #define OPTST_DISABLE_TWICE    0x0800000U
2592b15cb3dSCy Schubert /** scaled integer value */
2602b15cb3dSCy Schubert #define OPTST_SCALED_NUM       0x1000000U
2612b15cb3dSCy Schubert /** disable from cmd line */
2622b15cb3dSCy Schubert #define OPTST_NO_COMMAND       0x2000000U
2632b15cb3dSCy Schubert /** support is being removed */
2642b15cb3dSCy Schubert #define OPTST_DEPRECATED       0x4000000U
2652b15cb3dSCy Schubert /** alias for other option */
2662b15cb3dSCy Schubert #define OPTST_ALIAS            0x8000000U
2672b15cb3dSCy Schubert 
2682b15cb3dSCy Schubert /** bits in SET mask:
2692b15cb3dSCy Schubert  *  set     preset  reset   defined */
2702b15cb3dSCy Schubert #define OPTST_SET_MASK         0x000000FU
2712b15cb3dSCy Schubert 
2722b15cb3dSCy Schubert /** bits in MUTABLE mask:
2732b15cb3dSCy Schubert  *  set         preset      reset       defined     equivalence disabled
2742b15cb3dSCy Schubert  *  alloc_arg */
2752b15cb3dSCy Schubert #define OPTST_MUTABLE_MASK     0x000007FU
2762b15cb3dSCy Schubert 
2772b15cb3dSCy Schubert /** bits omitted from PERSISTENT mask:
2782b15cb3dSCy Schubert  *  mutable_mask */
2792b15cb3dSCy Schubert #define OPTST_PERSISTENT_MASK  0xFFFFF00U
2802b15cb3dSCy Schubert 
2812b15cb3dSCy Schubert /** bits in SELECTED mask:
2822b15cb3dSCy Schubert  *  set     defined */
2832b15cb3dSCy Schubert #define OPTST_SELECTED_MASK    0x0000005U
2842b15cb3dSCy Schubert 
2852b15cb3dSCy Schubert /** bits in ARG_TYPE mask:
2862b15cb3dSCy Schubert  *  arg_type_1 arg_type_2 arg_type_3 arg_type_4 */
2872b15cb3dSCy Schubert #define OPTST_ARG_TYPE_MASK    0x000F000U
2882b15cb3dSCy Schubert 
2892b15cb3dSCy Schubert /** bits in NO_USAGE mask:
2902b15cb3dSCy Schubert  *  omitted    no_command deprecated */
2912b15cb3dSCy Schubert #define OPTST_NO_USAGE_MASK    0x6080000U
2922b15cb3dSCy Schubert 
2932b15cb3dSCy Schubert /** bits in IMMUTABLE mask:
2942b15cb3dSCy Schubert  *  document omitted */
2952b15cb3dSCy Schubert #define OPTST_IMMUTABLE_MASK   0x0280000U
2962b15cb3dSCy Schubert 
2972b15cb3dSCy Schubert /** bits in DO_NOT_SAVE mask:
2982b15cb3dSCy Schubert  *  document omitted  no_init */
2992b15cb3dSCy Schubert #define OPTST_DO_NOT_SAVE_MASK 0x0280100U
3002b15cb3dSCy Schubert 
3012b15cb3dSCy Schubert /** bits in NO_OUTPUT mask:
3022b15cb3dSCy Schubert  *  document omitted  alias */
3032b15cb3dSCy Schubert #define OPTST_NO_OUTPUT_MASK   0x8280000U
3042b15cb3dSCy Schubert 
3052b15cb3dSCy Schubert /** all bits in opt_state_mask_t masks */
3062b15cb3dSCy Schubert #define OPTST_MASK_ALL         0xFFFFF7FU
3072b15cb3dSCy Schubert 
3082b15cb3dSCy Schubert /** no bits in opt_state_mask_t */
3092b15cb3dSCy Schubert #define OPTST_INIT             0x0000000U
3102b15cb3dSCy Schubert /** @} */
311ea906c41SOllivier Robert 
312ea906c41SOllivier Robert #ifdef NO_OPTIONAL_OPT_ARGS
313ea906c41SOllivier Robert # undef  OPTST_ARG_OPTIONAL
314ea906c41SOllivier Robert # define OPTST_ARG_OPTIONAL   0
315ea906c41SOllivier Robert #endif
316ea906c41SOllivier Robert 
3172b15cb3dSCy Schubert #define VENDOR_OPTION_VALUE   'W'
318ea906c41SOllivier Robert 
3192b15cb3dSCy Schubert #define SELECTED_OPT(_od)     ((_od)->fOptState  & OPTST_SELECTED_MASK)
3202b15cb3dSCy Schubert #define UNUSED_OPT(  _od)     (((_od)->fOptState & OPTST_SET_MASK) == 0)
3212b15cb3dSCy Schubert #define DISABLED_OPT(_od)     ((_od)->fOptState  & OPTST_DISABLED)
3222b15cb3dSCy Schubert #define OPTION_STATE(_od)     ((_od)->fOptState)
3232b15cb3dSCy Schubert #define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_SHIFT)
3242b15cb3dSCy Schubert #define OPTST_GET_ARGTYPE(_f) \
3252b15cb3dSCy Schubert     (((_f)&OPTST_ARG_TYPE_MASK) >> OPTST_ARG_TYPE_SHIFT)
326ea906c41SOllivier Robert 
3272b15cb3dSCy Schubert /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3282b15cb3dSCy Schubert  *
329ea906c41SOllivier Robert  *  PRIVATE INTERFACES
330ea906c41SOllivier Robert  *
331ea906c41SOllivier Robert  *  The following values are used in the generated code to communicate
332ea906c41SOllivier Robert  *  with the option library procedures.  They are not for public use
333ea906c41SOllivier Robert  *  and may be subject to change.
334ea906c41SOllivier Robert  */
335ea906c41SOllivier Robert 
3362b15cb3dSCy Schubert /**
337ea906c41SOllivier Robert  *  Define the processing state flags
3382b15cb3dSCy Schubert  * @{
3392b15cb3dSCy Schubert  */
3402b15cb3dSCy Schubert 
3412b15cb3dSCy Schubert /** integral type for holding proc_state masks */
3422b15cb3dSCy Schubert typedef uint32_t proc_state_mask_t;
3432b15cb3dSCy Schubert 
3442b15cb3dSCy Schubert /** bits defined for proc_state_mask_t */
3452b15cb3dSCy Schubert /** Process long style options */
3462b15cb3dSCy Schubert #define OPTPROC_LONGOPT       0x000001U
3472b15cb3dSCy Schubert /** Process short style "flags" */
3482b15cb3dSCy Schubert #define OPTPROC_SHORTOPT      0x000002U
3492b15cb3dSCy Schubert /** Stop on argument errors */
3502b15cb3dSCy Schubert #define OPTPROC_ERRSTOP       0x000004U
3512b15cb3dSCy Schubert /** Current option is disabled */
3522b15cb3dSCy Schubert #define OPTPROC_DISABLEDOPT   0x000008U
3532b15cb3dSCy Schubert /** no options are required */
3542b15cb3dSCy Schubert #define OPTPROC_NO_REQ_OPT    0x000010U
3552b15cb3dSCy Schubert /** there is a number option */
3562b15cb3dSCy Schubert #define OPTPROC_NUM_OPT       0x000020U
3572b15cb3dSCy Schubert /** have inits been done? */
3582b15cb3dSCy Schubert #define OPTPROC_INITDONE      0x000040U
3592b15cb3dSCy Schubert /** any negation options? */
3602b15cb3dSCy Schubert #define OPTPROC_NEGATIONS     0x000080U
3612b15cb3dSCy Schubert /** check environment? */
3622b15cb3dSCy Schubert #define OPTPROC_ENVIRON       0x000100U
3632b15cb3dSCy Schubert /** Disallow remaining arguments */
3642b15cb3dSCy Schubert #define OPTPROC_NO_ARGS       0x000200U
3652b15cb3dSCy Schubert /** Require args after options */
3662b15cb3dSCy Schubert #define OPTPROC_ARGS_REQ      0x000400U
3672b15cb3dSCy Schubert /** reorder operands after opts */
3682b15cb3dSCy Schubert #define OPTPROC_REORDER       0x000800U
3692b15cb3dSCy Schubert /** emit usage in GNU style */
3702b15cb3dSCy Schubert #define OPTPROC_GNUUSAGE      0x001000U
3712b15cb3dSCy Schubert /** Translate strings in tOptions */
3722b15cb3dSCy Schubert #define OPTPROC_TRANSLATE     0x002000U
3732b15cb3dSCy Schubert /** no usage on usage error */
3742b15cb3dSCy Schubert #define OPTPROC_MISUSE        0x004000U
3752b15cb3dSCy Schubert /** immediate options active */
3762b15cb3dSCy Schubert #define OPTPROC_IMMEDIATE     0x008000U
3772b15cb3dSCy Schubert /** suppress for config only */
3782b15cb3dSCy Schubert #define OPTPROC_NXLAT_OPT_CFG 0x010000U
3792b15cb3dSCy Schubert /** suppress xlation always */
3802b15cb3dSCy Schubert #define OPTPROC_NXLAT_OPT     0x020000U
3812b15cb3dSCy Schubert /** vendor options active */
3822b15cb3dSCy Schubert #define OPTPROC_VENDOR_OPT    0x040000U
3832b15cb3dSCy Schubert /** opt processing in preset state */
3842b15cb3dSCy Schubert #define OPTPROC_PRESETTING    0x080000U
3852b15cb3dSCy Schubert /** Ignore pzFullUsage, compute usage text */
3862b15cb3dSCy Schubert #define OPTPROC_COMPUTE       0x100000U
3872b15cb3dSCy Schubert /** Program outputs digested option state for shell scripts.  Usage text
3882b15cb3dSCy Schubert   * always written to stderr */
3892b15cb3dSCy Schubert #define OPTPROC_SHELL_OUTPUT  0x200000U
3902b15cb3dSCy Schubert 
3912b15cb3dSCy Schubert /** bits in NO_XLAT mask:
3922b15cb3dSCy Schubert  *  nxlat_opt_cfg nxlat_opt */
3932b15cb3dSCy Schubert #define OPTPROC_NO_XLAT_MASK  0x030000U
3942b15cb3dSCy Schubert 
3952b15cb3dSCy Schubert /** all bits in proc_state_mask_t masks */
3962b15cb3dSCy Schubert #define OPTPROC_MASK_ALL      0x3FFFFFU
3972b15cb3dSCy Schubert 
3982b15cb3dSCy Schubert /** no bits in proc_state_mask_t */
3992b15cb3dSCy Schubert #define OPTPROC_NONE          0x000000U
4002b15cb3dSCy Schubert /** @} */
4012b15cb3dSCy Schubert 
4022b15cb3dSCy Schubert #define STMTS(s)  do { s; } while (false)
4032b15cb3dSCy Schubert 
4042b15cb3dSCy Schubert /**
4052b15cb3dSCy Schubert  *  Abbreviation for const memory character.
4062b15cb3dSCy Schubert  */
4072b15cb3dSCy Schubert #define tCC         char const
4082b15cb3dSCy Schubert 
4092b15cb3dSCy Schubert /**
4102b15cb3dSCy Schubert  * Magical values for the program's option pointer
4112b15cb3dSCy Schubert  * @{
412ea906c41SOllivier Robert  */
413ea906c41SOllivier Robert typedef enum {
4142b15cb3dSCy Schubert     OP_VAL_EMIT_USAGE       = 1,  ///< request for usage
4152b15cb3dSCy Schubert     OP_VAL_EMIT_SHELL       = 2,  ///< emit value for Bourne shell evaluation
4162b15cb3dSCy Schubert     OP_VAL_RETURN_VALNAME   = 3,  ///< return the value as a string
4172b15cb3dSCy Schubert     OP_VAL_EMIT_LIMIT       = 15  ///< limit for magic values
4182b15cb3dSCy Schubert } opt_proc_vals_t;
419ea906c41SOllivier Robert 
4202b15cb3dSCy Schubert /// \a OPT_VAL_EMIT_USAGE cast as a pointer
4212b15cb3dSCy Schubert #define OPTPROC_EMIT_USAGE      ((tOptions *)OP_VAL_EMIT_USAGE)
422ea906c41SOllivier Robert 
4232b15cb3dSCy Schubert /// \a OPT_VAL_EMIT_SHELL cast as a pointer
4242b15cb3dSCy Schubert #define OPTPROC_EMIT_SHELL      ((tOptions *)OP_VAL_EMIT_SHELL)
425ea906c41SOllivier Robert 
4262b15cb3dSCy Schubert /// \a OPT_VAL_RETURN_VALNAME cast as a pointer
4272b15cb3dSCy Schubert #define OPTPROC_RETURN_VALNAME  ((tOptions *)OP_VAL_RETURN_VALNAME)
4282b15cb3dSCy Schubert 
4292b15cb3dSCy Schubert /// \a OPT_VAL_EMIT_LIMIT cast as a pointer
4302b15cb3dSCy Schubert #define OPTPROC_EMIT_LIMIT      ((tOptions *)OP_VAL_EMIT_LIMIT)
4312b15cb3dSCy Schubert /** @} */
4322b15cb3dSCy Schubert 
4332b15cb3dSCy Schubert /** group option processing procedure types
4342b15cb3dSCy Schubert  * @{
435ea906c41SOllivier Robert  */
4362b15cb3dSCy Schubert /** forward declaration for tOptDesc */
4372b15cb3dSCy Schubert typedef struct opt_desc tOptDesc;
4382b15cb3dSCy Schubert /** forward declaration for tOptiond */
439ea906c41SOllivier Robert typedef struct options  tOptions;
440ea906c41SOllivier Robert 
4412b15cb3dSCy Schubert /**
442ea906c41SOllivier Robert  *  The option procedures do the special processing for each
443ea906c41SOllivier Robert  *  option flag that needs it.
444ea906c41SOllivier Robert  */
445ea906c41SOllivier Robert typedef void (tOptProc)(tOptions * pOpts, tOptDesc * pOptDesc);
4462b15cb3dSCy Schubert 
4472b15cb3dSCy Schubert /**
4482b15cb3dSCy Schubert  * a pointer to an option processing procedure
4492b15cb3dSCy Schubert  */
450ea906c41SOllivier Robert typedef tOptProc * tpOptProc;
451ea906c41SOllivier Robert 
4522b15cb3dSCy Schubert /**
453ea906c41SOllivier Robert  *  The usage procedure will never return.  It calls "exit(2)"
454ea906c41SOllivier Robert  *  with the "exitCode" argument passed to it.
455ea906c41SOllivier Robert  */
4562b15cb3dSCy Schubert // coverity[+kill]
457ea906c41SOllivier Robert typedef void (tUsageProc)(tOptions * pOpts, int exitCode);
458ea906c41SOllivier Robert 
4592b15cb3dSCy Schubert /**
4602b15cb3dSCy Schubert  * a pointer to a procedure that prints usage and exits.
4612b15cb3dSCy Schubert  */
4622b15cb3dSCy Schubert typedef tUsageProc * tpUsageProc;
4632b15cb3dSCy Schubert /** @} */
4642b15cb3dSCy Schubert 
4652b15cb3dSCy Schubert /**
466ea906c41SOllivier Robert  *  Special definitions.  "NOLIMIT" is the 'max' value to use when
467ea906c41SOllivier Robert  *  a flag may appear multiple times without limit.  "NO_EQUIVALENT"
468ea906c41SOllivier Robert  *  is an illegal value for 'optIndex' (option description index).
4692b15cb3dSCy Schubert  * @{
470ea906c41SOllivier Robert  */
4712b15cb3dSCy Schubert #define NOLIMIT          USHRT_MAX  ///< no occurrance count limit
4722b15cb3dSCy Schubert #define OPTION_LIMIT     SHRT_MAX   ///< maximum number of option types
4732b15cb3dSCy Schubert /// option index to indicate no equivalance or alias
474ea906c41SOllivier Robert #define NO_EQUIVALENT    (OPTION_LIMIT+1)
4752b15cb3dSCy Schubert /** @} */
476ea906c41SOllivier Robert 
4772b15cb3dSCy Schubert /**
4782b15cb3dSCy Schubert  * Option argument value.  Which is valid is determined by:
4792b15cb3dSCy Schubert  * (fOptState & OPTST_ARG_TYPE_MASK) >> OPTST_ARG_TYPE_SHIFT
4802b15cb3dSCy Schubert  * which will yield one of the teOptArgType values.
481ea906c41SOllivier Robert  */
482ea906c41SOllivier Robert typedef union {
4832b15cb3dSCy Schubert     char const *    argString;  ///< as a string
4842b15cb3dSCy Schubert     uintptr_t       argEnum;    ///< as an enumeration value
4852b15cb3dSCy Schubert     uintptr_t       argIntptr;  ///< as an integer big enough to hold pointer
4862b15cb3dSCy Schubert     long            argInt;     ///< as a long integer
4872b15cb3dSCy Schubert     unsigned long   argUint;    ///< as an unsigned long ingeger
4882b15cb3dSCy Schubert     unsigned int    argBool;    ///< as a boolean value
4892b15cb3dSCy Schubert     FILE *          argFp;      ///< as a FILE * pointer
4902b15cb3dSCy Schubert     int             argFd;      ///< as a file descriptor (int)
4912b15cb3dSCy Schubert } opt_arg_union_t;
492ea906c41SOllivier Robert 
4932b15cb3dSCy Schubert /// Compatibility define: \a pzLastArg is now \a optArg.argString
4942b15cb3dSCy Schubert #define             pzLastArg       optArg.argString
4952b15cb3dSCy Schubert /// The old amorphous argument bucket is now the opt_arg_union_t union.
4962b15cb3dSCy Schubert #define             optArgBucket_t  opt_arg_union_t
4972b15cb3dSCy Schubert 
4982b15cb3dSCy Schubert /**
4992b15cb3dSCy Schubert  * Enumeration of AutoOpts defined options.  The enumeration is used in
5002b15cb3dSCy Schubert  * marking each option that is defined by AutoOpts so libopts can find
5012b15cb3dSCy Schubert  * the correct descriptor.  This renders \a option_spec_idx_t redundant.
5022b15cb3dSCy Schubert  */
5032b15cb3dSCy Schubert typedef enum {
5042b15cb3dSCy Schubert     AOUSE_USER_DEFINED = 0,     ///< user specified option
5052b15cb3dSCy Schubert     AOUSE_RESET_OPTION,         ///< reset option state option
5062b15cb3dSCy Schubert     AOUSE_VERSION,              ///< request version
5072b15cb3dSCy Schubert     AOUSE_HELP,                 ///< request usage help
5082b15cb3dSCy Schubert     AOUSE_MORE_HELP,            ///< request paged usage
5092b15cb3dSCy Schubert     AOUSE_USAGE,                ///< request short usage
5102b15cb3dSCy Schubert     AOUSE_SAVE_OPTS,            ///< save option state
5112b15cb3dSCy Schubert     AOUSE_LOAD_OPTS,            ///< load options from file
5122b15cb3dSCy Schubert     AOUSE_VENDOR_OPT            ///< specify a vendor option
5132b15cb3dSCy Schubert } opt_usage_t;
5142b15cb3dSCy Schubert 
5152b15cb3dSCy Schubert /**
516ea906c41SOllivier Robert  *  Descriptor structure for each option.
517ea906c41SOllivier Robert  *  Only the fields marked "PUBLIC" are for public use.
518ea906c41SOllivier Robert  */
5192b15cb3dSCy Schubert struct opt_desc {
5202b15cb3dSCy Schubert     /// Public, the index of this descriptor
5212b15cb3dSCy Schubert     uint16_t const      optIndex;
5222b15cb3dSCy Schubert     /// Public, the flag character (value)
5232b15cb3dSCy Schubert     uint16_t const      optValue;
5242b15cb3dSCy Schubert     /// Public, the index of the option used to activate option
5252b15cb3dSCy Schubert     uint16_t            optActualIndex;
5262b15cb3dSCy Schubert     /// Public, the flag character of the activating option
5272b15cb3dSCy Schubert     uint16_t            optActualValue;
528ea906c41SOllivier Robert 
5292b15cb3dSCy Schubert     /// Public, the index of the equivalenced-to option.
5302b15cb3dSCy Schubert     /// This is NO_EQUIVALENT unless activated.
5312b15cb3dSCy Schubert     uint16_t const      optEquivIndex;
5322b15cb3dSCy Schubert     /// Private, the minimum occurrance count
5332b15cb3dSCy Schubert     uint16_t const      optMinCt;
5342b15cb3dSCy Schubert     /// Private, the maximum occurrance count (NOLIMIT, if unlimited)
5352b15cb3dSCy Schubert     uint16_t const      optMaxCt;
5362b15cb3dSCy Schubert     /// Public, the actual occurrance count
5372b15cb3dSCy Schubert     uint16_t            optOccCt;
538ea906c41SOllivier Robert 
5392b15cb3dSCy Schubert     /// Public, the option processing state
5402b15cb3dSCy Schubert     opt_state_mask_t    fOptState;
5412b15cb3dSCy Schubert     /// Private, how the option is used (opt_usage_t)
5422b15cb3dSCy Schubert     uint32_t            optUsage;
5432b15cb3dSCy Schubert     /// Public, The current option argument value
5442b15cb3dSCy Schubert     opt_arg_union_t     optArg;
5452b15cb3dSCy Schubert     /// Public, data that is actually private to the code that handles
5462b15cb3dSCy Schubert     /// this particular option.  It is public IFF you have your own
5472b15cb3dSCy Schubert     /// handling function.
5482b15cb3dSCy Schubert     void *              optCookie;
549ea906c41SOllivier Robert 
5502b15cb3dSCy Schubert     /// Private, a list of options that must be specified when this option
5512b15cb3dSCy Schubert     /// has been specified
5522b15cb3dSCy Schubert     int const  * const  pOptMust;
553ea906c41SOllivier Robert 
5542b15cb3dSCy Schubert     /// Private, a list of options that cannot be specified when this option
5552b15cb3dSCy Schubert     /// has been specified
5562b15cb3dSCy Schubert     int const  * const  pOptCant;
5572b15cb3dSCy Schubert 
5582b15cb3dSCy Schubert     /// Private, the function to call for handling this option
5592b15cb3dSCy Schubert     tpOptProc    const  pOptProc;
5602b15cb3dSCy Schubert 
5612b15cb3dSCy Schubert     /// Private, usage information about this option
5622b15cb3dSCy Schubert     char const * const  pzText;
5632b15cb3dSCy Schubert 
5642b15cb3dSCy Schubert     /// Public, the UPPER CASE, shell variable name syntax name of the option
5652b15cb3dSCy Schubert     char const * const  pz_NAME;
5662b15cb3dSCy Schubert 
5672b15cb3dSCy Schubert     /// the unmodified name of the option
5682b15cb3dSCy Schubert     char const * const  pz_Name;
5692b15cb3dSCy Schubert 
5702b15cb3dSCy Schubert     /// the option name to use to disable the option.  Long options names
5712b15cb3dSCy Schubert     /// must be active.
5722b15cb3dSCy Schubert     char const * const  pz_DisableName;
5732b15cb3dSCy Schubert 
5742b15cb3dSCy Schubert     /// the special prefix that makes the normal option name become the
5752b15cb3dSCy Schubert     /// disablement name.
5762b15cb3dSCy Schubert     char const * const  pz_DisablePfx;
577ea906c41SOllivier Robert };
578ea906c41SOllivier Robert 
5792b15cb3dSCy Schubert /**
580ea906c41SOllivier Robert  *  Some options need special processing, so we store their
5812b15cb3dSCy Schubert  *  indexes in a known place.
582ea906c41SOllivier Robert  */
5832b15cb3dSCy Schubert typedef struct {
5842b15cb3dSCy Schubert     uint16_t const  more_help;      ///< passes help text through pager
5852b15cb3dSCy Schubert     uint16_t const  save_opts;      ///< stores option state to a file
5862b15cb3dSCy Schubert     uint16_t const  number_option;  ///< the option "name" is an integer
5872b15cb3dSCy Schubert     /// all arguments are options, this is the default option that must
5882b15cb3dSCy Schubert     /// take an argument.  That argument is the unrecognized option.
5892b15cb3dSCy Schubert     uint16_t const  default_opt;
5902b15cb3dSCy Schubert } option_spec_idx_t;
591ea906c41SOllivier Robert 
5922b15cb3dSCy Schubert /**
593ea906c41SOllivier Robert  *  The procedure generated for translating option text
594ea906c41SOllivier Robert  */
595ea906c41SOllivier Robert typedef void (tOptionXlateProc)(void);
596ea906c41SOllivier Robert 
5972b15cb3dSCy Schubert /**
5982b15cb3dSCy Schubert  * Everything marked "PUBLIC" is also marked "const".  Public access is not
5992b15cb3dSCy Schubert  * a license to modify.  Other fields are used and modified by the library.
6002b15cb3dSCy Schubert  * They are also subject to change without any notice.
6012b15cb3dSCy Schubert  * Do not even look at these outside of libopts.
6022b15cb3dSCy Schubert  */
603ea906c41SOllivier Robert struct options {
6042b15cb3dSCy Schubert     int const                   structVersion; ///< The version of this struct
6052b15cb3dSCy Schubert     unsigned int                origArgCt;     ///< program argument count
6062b15cb3dSCy Schubert     char **                     origArgVect;   ///< program argument vector
6072b15cb3dSCy Schubert     proc_state_mask_t           fOptSet;       ///< option proc. state flags
6082b15cb3dSCy Schubert     unsigned int                curOptIdx;     ///< current option index
6092b15cb3dSCy Schubert     char *                      pzCurOpt;      ///< current option text
610ea906c41SOllivier Robert 
6112b15cb3dSCy Schubert     /// Public, the full path of the program
6122b15cb3dSCy Schubert     char const * const          pzProgPath;
6132b15cb3dSCy Schubert     /// Public, the name of the executable, without any path
6142b15cb3dSCy Schubert     char const * const          pzProgName;
6152b15cb3dSCy Schubert     /// Public, the upper-cased, shell variable syntax-ed program name
616ea906c41SOllivier Robert     char const * const          pzPROGNAME;
6172b15cb3dSCy Schubert     /// the name of the "rc file" (configuration file)
618ea906c41SOllivier Robert     char const * const          pzRcName;
6192b15cb3dSCy Schubert     /// the copyright text
620ea906c41SOllivier Robert     char const * const          pzCopyright;
6212b15cb3dSCy Schubert     /// the full copyright notice
622ea906c41SOllivier Robert     char const * const          pzCopyNotice;
6232b15cb3dSCy Schubert     /// a string with the program name, project name and version
624ea906c41SOllivier Robert     char const * const          pzFullVersion;
6252b15cb3dSCy Schubert     /// a list of pointers to directories to search for the config file
626ea906c41SOllivier Robert     char const * const *        const papzHomeList;
6272b15cb3dSCy Schubert     /// the title line for usage
628ea906c41SOllivier Robert     char const * const          pzUsageTitle;
6292b15cb3dSCy Schubert     /// some added explanation for what this program is trying to do
630ea906c41SOllivier Robert     char const * const          pzExplain;
6312b15cb3dSCy Schubert     /// a detailed explanation of the program's purpose, for use when
6322b15cb3dSCy Schubert     /// full help has been requested
633ea906c41SOllivier Robert     char const * const          pzDetail;
6342b15cb3dSCy Schubert     /// The public array of option descriptors
635ea906c41SOllivier Robert     tOptDesc   * const          pOptDesc;
6362b15cb3dSCy Schubert     /// the email address for reporting bugs
637ea906c41SOllivier Robert     char const * const          pzBugAddr;
638ea906c41SOllivier Robert 
6392b15cb3dSCy Schubert     /// Reserved for future use
640ea906c41SOllivier Robert     void *                      pExtensions;
6412b15cb3dSCy Schubert     /// A copy of the option state when optionSaveState was called.
642ea906c41SOllivier Robert     void *                      pSavedState;
643ea906c41SOllivier Robert 
6442b15cb3dSCy Schubert     /// The procedure to call to print usage text
645*a466cc55SCy Schubert     /* __attribute__((__noreturn__)) */
6462b15cb3dSCy Schubert     // coverity[+kill]
647ea906c41SOllivier Robert     tpUsageProc                 pUsageProc;
6482b15cb3dSCy Schubert     /// The procedure to call to translate translatable option messages
649ea906c41SOllivier Robert     tOptionXlateProc *          pTransProc;
650ea906c41SOllivier Robert 
6512b15cb3dSCy Schubert     /// Special option indexes.
6522b15cb3dSCy Schubert     option_spec_idx_t           specOptIdx;
6532b15cb3dSCy Schubert     /// the total number of options for the program
654ea906c41SOllivier Robert     int const                   optCt;
6552b15cb3dSCy Schubert     /// The number of "presettable" options, though some may be marked
6562b15cb3dSCy Schubert     /// "no-preset".  Includes all user specified options, plus a few
6572b15cb3dSCy Schubert     /// that are specified by AutoOpts.
658ea906c41SOllivier Robert     int const                   presetOptCt;
6592b15cb3dSCy Schubert     /// user specified full usage text
6602b15cb3dSCy Schubert     char const *                pzFullUsage;
6612b15cb3dSCy Schubert     /// user specifed short usage (usage error triggered) message
6622b15cb3dSCy Schubert     char const *                pzShortUsage;
6632b15cb3dSCy Schubert     /// The option argument settings active when optionSaveState was called
6642b15cb3dSCy Schubert     opt_arg_union_t const * const originalOptArgArray;
6652b15cb3dSCy Schubert     /// any saved cookie value
6662b15cb3dSCy Schubert     void * const * const        originalOptArgCookie;
6672b15cb3dSCy Schubert     /// the package data directory (e.g. global configuration files)
6682b15cb3dSCy Schubert     char const * const          pzPkgDataDir;
6692b15cb3dSCy Schubert     /// email address of the project packager
6702b15cb3dSCy Schubert     char const * const          pzPackager;
671ea906c41SOllivier Robert };
672ea906c41SOllivier Robert 
673ea906c41SOllivier Robert /*
6742b15cb3dSCy Schubert  *  Versions where in various fields first appear:
6752b15cb3dSCy Schubert  *  ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero)
6762b15cb3dSCy Schubert  */
6772b15cb3dSCy Schubert /**
6782b15cb3dSCy Schubert  * The version that first stored the original argument vector
6792b15cb3dSCy Schubert  */
6802b15cb3dSCy Schubert #define originalOptArgArray_STRUCT_VERSION  0x20000 /* AO_CURRENT = 32 */
6812b15cb3dSCy Schubert #define HAS_originalOptArgArray(_opt) \
6822b15cb3dSCy Schubert     ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION)
6832b15cb3dSCy Schubert 
6842b15cb3dSCy Schubert /**
6852b15cb3dSCy Schubert  * The version that first stored the package data directory
6862b15cb3dSCy Schubert  */
6872b15cb3dSCy Schubert #define pzPkgDataDir_STRUCT_VERSION  0x22000 /* AO_CURRENT = 34 */
6882b15cb3dSCy Schubert #define HAS_pzPkgDataDir(_opt) \
6892b15cb3dSCy Schubert     ((_opt)->structVersion >= pzPkgDataDir_STRUCT_VERSION)
6902b15cb3dSCy Schubert 
6912b15cb3dSCy Schubert /**
6922b15cb3dSCy Schubert  * The version that first stored the option usage in each option descriptor
6932b15cb3dSCy Schubert  */
6942b15cb3dSCy Schubert #define opt_usage_t_STRUCT_VERSION  0x26000 /* AO_CURRENT = 38 */
6952b15cb3dSCy Schubert #define HAS_opt_usage_t(_opt) \
6962b15cb3dSCy Schubert     ((_opt)->structVersion >= opt_usage_t_STRUCT_VERSION)
6972b15cb3dSCy Schubert 
6982b15cb3dSCy Schubert /**
699ea906c41SOllivier Robert  *  "token list" structure returned by "string_tokenize()"
700ea906c41SOllivier Robert  */
701ea906c41SOllivier Robert typedef struct {
7022b15cb3dSCy Schubert     unsigned long   tkn_ct;      ///< number of tokens found
7032b15cb3dSCy Schubert     unsigned char * tkn_list[1]; ///< array of pointers to tokens
704ea906c41SOllivier Robert } token_list_t;
705ea906c41SOllivier Robert 
706ea906c41SOllivier Robert /*
707ea906c41SOllivier Robert  *  Hide the interface - it pollutes a POSIX claim, but leave it for
708ea906c41SOllivier Robert  *  anyone #include-ing this header
709ea906c41SOllivier Robert  */
710ea906c41SOllivier Robert #define strneqvcmp      option_strneqvcmp
711ea906c41SOllivier Robert #define streqvcmp       option_streqvcmp
712ea906c41SOllivier Robert #define streqvmap       option_streqvmap
713ea906c41SOllivier Robert #define strequate       option_strequate
714ea906c41SOllivier Robert #define strtransform    option_strtransform
715ea906c41SOllivier Robert 
7162b15cb3dSCy Schubert /**
7172b15cb3dSCy Schubert  *  Everything needed to be known about an mmap-ed file.
7182b15cb3dSCy Schubert  *
719ea906c41SOllivier Robert  *  This is an output only structure used by text_mmap and text_munmap.
720ea906c41SOllivier Robert  *  Clients must not alter the contents and must provide it to both
721ea906c41SOllivier Robert  *  the text_mmap and text_munmap procedures.  BE ADVISED: if you are
722ea906c41SOllivier Robert  *  mapping the file with PROT_WRITE the NUL byte at the end MIGHT NOT
723ea906c41SOllivier Robert  *  BE WRITABLE.  In any event, that byte is not be written back
724ea906c41SOllivier Robert  *  to the source file.  ALSO: if "txt_data" is valid and "txt_errno"
725ea906c41SOllivier Robert  *  is not zero, then there *may* not be a terminating NUL.
726ea906c41SOllivier Robert  */
727ea906c41SOllivier Robert typedef struct {
7282b15cb3dSCy Schubert     void *      txt_data;      ///< text file data
7292b15cb3dSCy Schubert     size_t      txt_size;      ///< actual file size
7302b15cb3dSCy Schubert     size_t      txt_full_size; ///< mmaped mem size
7312b15cb3dSCy Schubert     int         txt_fd;        ///< file descriptor
7322b15cb3dSCy Schubert     int         txt_zero_fd;   ///< fd for /dev/zero
7332b15cb3dSCy Schubert     int         txt_errno;     ///< warning code
7342b15cb3dSCy Schubert     int         txt_prot;      ///< "prot" flags
7352b15cb3dSCy Schubert     int         txt_flags;     ///< mapping type
736ea906c41SOllivier Robert } tmap_info_t;
737ea906c41SOllivier Robert 
7382b15cb3dSCy Schubert /**
7392b15cb3dSCy Schubert  * mmap result wrapper that yields "true" when mmap has failed.
7402b15cb3dSCy Schubert  */
741276da39aSCy Schubert #define TEXT_MMAP_FAILED_ADDR(a)  (VOIDP(a) == VOIDP(MAP_FAILED))
742ea906c41SOllivier Robert 
743ea906c41SOllivier Robert #ifdef  __cplusplus
7442b15cb3dSCy Schubert #define CPLUSPLUS_OPENER extern "C" {
7452b15cb3dSCy Schubert CPLUSPLUS_OPENER
746ea906c41SOllivier Robert #define CPLUSPLUS_CLOSER }
747ea906c41SOllivier Robert #else
748ea906c41SOllivier Robert #define CPLUSPLUS_CLOSER
749ea906c41SOllivier Robert #endif
750ea906c41SOllivier Robert 
7512b15cb3dSCy Schubert /**
752ea906c41SOllivier Robert  *  The following routines may be coded into AutoOpts client code:
753ea906c41SOllivier Robert  */
754ea906c41SOllivier Robert 
7552b15cb3dSCy Schubert /**
756ea906c41SOllivier Robert  * ao_string_tokenize - tokenize an input string
757ea906c41SOllivier Robert  *
758ea906c41SOllivier Robert  *  This function will convert one input string into a list of strings.
759ea906c41SOllivier Robert  *  The list of strings is derived by separating the input based on
760ea906c41SOllivier Robert  *  white space separation.  However, if the input contains either single
761ea906c41SOllivier Robert  *  or double quote characters, then the text after that character up to
762ea906c41SOllivier Robert  *  a matching quote will become the string in the list.
763ea906c41SOllivier Robert  *
764ea906c41SOllivier Robert  *  The returned pointer should be deallocated with @code{free(3C)} when
765ea906c41SOllivier Robert  *  are done using the data.  The data are placed in a single block of
766ea906c41SOllivier Robert  *  allocated memory.  Do not deallocate individual token/strings.
767ea906c41SOllivier Robert  *
768ea906c41SOllivier Robert  *  The structure pointed to will contain at least these two fields:
769ea906c41SOllivier Robert  *  @table @samp
770ea906c41SOllivier Robert  *  @item tkn_ct
771ea906c41SOllivier Robert  *  The number of tokens found in the input string.
772ea906c41SOllivier Robert  *  @item tok_list
773ea906c41SOllivier Robert  *  An array of @code{tkn_ct + 1} pointers to substring tokens, with
774ea906c41SOllivier Robert  *  the last pointer set to NULL.
775ea906c41SOllivier Robert  *  @end table
776ea906c41SOllivier Robert  *
777ea906c41SOllivier Robert  *  There are two types of quoted strings: single quoted (@code{'}) and
778ea906c41SOllivier Robert  *  double quoted (@code{"}).  Singly quoted strings are fairly raw in that
779ea906c41SOllivier Robert  *  escape characters (@code{\\}) are simply another character, except when
780ea906c41SOllivier Robert  *  preceding the following characters:
781ea906c41SOllivier Robert  *  @example
782ea906c41SOllivier Robert  *  @code{\\}  double backslashes reduce to one
783ea906c41SOllivier Robert  *  @code{'}   incorporates the single quote into the string
784ea906c41SOllivier Robert  *  @code{\n}  suppresses both the backslash and newline character
785ea906c41SOllivier Robert  *  @end example
786ea906c41SOllivier Robert  *
787ea906c41SOllivier Robert  *  Double quote strings are formed according to the rules of string
788ea906c41SOllivier Robert  *  constants in ANSI-C programs.
7892b15cb3dSCy Schubert  *
7902b15cb3dSCy Schubert  * @param string       string to be tokenized
7912b15cb3dSCy Schubert  *
7922b15cb3dSCy Schubert  * @return token_list_t * - pointer to a structure that lists each token
793ea906c41SOllivier Robert  */
794ea906c41SOllivier Robert extern token_list_t * ao_string_tokenize(char const *);
795ea906c41SOllivier Robert 
796ea906c41SOllivier Robert 
7972b15cb3dSCy Schubert /**
798ea906c41SOllivier Robert  * configFileLoad - parse a configuration file
799ea906c41SOllivier Robert  *
800ea906c41SOllivier Robert  *  This routine will load a named configuration file and parse the
801ea906c41SOllivier Robert  *  text as a hierarchically valued option.  The option descriptor
802ea906c41SOllivier Robert  *  created from an option definition file is not used via this interface.
803ea906c41SOllivier Robert  *  The returned value is "named" with the input file name and is of
804ea906c41SOllivier Robert  *  type "@code{OPARG_TYPE_HIERARCHY}".  It may be used in calls to
805ea906c41SOllivier Robert  *  @code{optionGetValue()}, @code{optionNextValue()} and
806ea906c41SOllivier Robert  *  @code{optionUnloadNested()}.
8072b15cb3dSCy Schubert  *
8082b15cb3dSCy Schubert  * @param fname        the file to load
8092b15cb3dSCy Schubert  *
8102b15cb3dSCy Schubert  * @return const tOptionValue * - An allocated, compound value structure
811ea906c41SOllivier Robert  */
812ea906c41SOllivier Robert extern const tOptionValue * configFileLoad(char const *);
813ea906c41SOllivier Robert 
814ea906c41SOllivier Robert 
8152b15cb3dSCy Schubert /**
816ea906c41SOllivier Robert  * optionFileLoad - Load the locatable config files, in order
817ea906c41SOllivier Robert  *
818ea906c41SOllivier Robert  *  This function looks in all the specified directories for a configuration
819ea906c41SOllivier Robert  *  file ("rc" file or "ini" file) and processes any found twice.  The first
820ea906c41SOllivier Robert  *  time through, they are processed in reverse order (last file first).  At
821ea906c41SOllivier Robert  *  that time, only "immediate action" configurables are processed.  For
822ea906c41SOllivier Robert  *  example, if the last named file specifies not processing any more
823ea906c41SOllivier Robert  *  configuration files, then no more configuration files will be processed.
824ea906c41SOllivier Robert  *  Such an option in the @strong{first} named directory will have no effect.
825ea906c41SOllivier Robert  *
826ea906c41SOllivier Robert  *  Once the immediate action configurables have been handled, then the
827ea906c41SOllivier Robert  *  directories are handled in normal, forward order.  In that way, later
828ea906c41SOllivier Robert  *  config files can override the settings of earlier config files.
829ea906c41SOllivier Robert  *
830ea906c41SOllivier Robert  *  See the AutoOpts documentation for a thorough discussion of the
831ea906c41SOllivier Robert  *  config file format.
832ea906c41SOllivier Robert  *
833ea906c41SOllivier Robert  *  Configuration files not found or not decipherable are simply ignored.
8342b15cb3dSCy Schubert  *
8352b15cb3dSCy Schubert  * @param opts         program options descriptor
8362b15cb3dSCy Schubert  * @param prog         program name
8372b15cb3dSCy Schubert  *
8382b15cb3dSCy Schubert  * @return int - 0 -> SUCCESS, -1 -> FAILURE
839ea906c41SOllivier Robert  */
840ea906c41SOllivier Robert extern int optionFileLoad(tOptions *, char const *);
841ea906c41SOllivier Robert 
842ea906c41SOllivier Robert 
8432b15cb3dSCy Schubert /**
844ea906c41SOllivier Robert  * optionFindNextValue - find a hierarcicaly valued option instance
845ea906c41SOllivier Robert  *
846ea906c41SOllivier Robert  *  This routine will find the next entry in a nested value option or
847ea906c41SOllivier Robert  *  configurable.  It will search through the list and return the next entry
848ea906c41SOllivier Robert  *  that matches the criteria.
8492b15cb3dSCy Schubert  *
8502b15cb3dSCy Schubert  * @param odesc        an option with a nested arg type
8512b15cb3dSCy Schubert  * @param pPrevVal     the last entry
8522b15cb3dSCy Schubert  * @param name         name of value to find
8532b15cb3dSCy Schubert  * @param value        the matching value
8542b15cb3dSCy Schubert  *
8552b15cb3dSCy Schubert  * @return const tOptionValue * - a compound value structure
856ea906c41SOllivier Robert  */
857ea906c41SOllivier Robert extern const tOptionValue * optionFindNextValue(const tOptDesc *, const tOptionValue *, char const *, char const *);
858ea906c41SOllivier Robert 
859ea906c41SOllivier Robert 
8602b15cb3dSCy Schubert /**
861ea906c41SOllivier Robert  * optionFindValue - find a hierarcicaly valued option instance
862ea906c41SOllivier Robert  *
863ea906c41SOllivier Robert  *  This routine will find an entry in a nested value option or configurable.
864ea906c41SOllivier Robert  *  It will search through the list and return a matching entry.
8652b15cb3dSCy Schubert  *
8662b15cb3dSCy Schubert  * @param odesc        an option with a nested arg type
8672b15cb3dSCy Schubert  * @param name         name of value to find
8682b15cb3dSCy Schubert  * @param val          the matching value
8692b15cb3dSCy Schubert  *
8702b15cb3dSCy Schubert  * @return const tOptionValue * - a compound value structure
871ea906c41SOllivier Robert  */
872ea906c41SOllivier Robert extern const tOptionValue * optionFindValue(const tOptDesc *, char const *, char const *);
873ea906c41SOllivier Robert 
874ea906c41SOllivier Robert 
8752b15cb3dSCy Schubert /**
876ea906c41SOllivier Robert  * optionFree - free allocated option processing memory
877ea906c41SOllivier Robert  *
878ea906c41SOllivier Robert  *  AutoOpts sometimes allocates memory and puts pointers to it in the
879ea906c41SOllivier Robert  *  option state structures.  This routine deallocates all such memory.
8802b15cb3dSCy Schubert  *
8812b15cb3dSCy Schubert  * @param pOpts        program options descriptor
882ea906c41SOllivier Robert  */
883ea906c41SOllivier Robert extern void optionFree(tOptions *);
884ea906c41SOllivier Robert 
885ea906c41SOllivier Robert 
8862b15cb3dSCy Schubert /**
887ea906c41SOllivier Robert  * optionGetValue - get a specific value from a hierarcical list
888ea906c41SOllivier Robert  *
889ea906c41SOllivier Robert  *  This routine will find an entry in a nested value option or configurable.
890ea906c41SOllivier Robert  *  If "valueName" is NULL, then the first entry is returned.  Otherwise,
891ea906c41SOllivier Robert  *  the first entry with a name that exactly matches the argument will be
8922b15cb3dSCy Schubert  *  returned.  If there is no matching value, NULL is returned and errno is
8932b15cb3dSCy Schubert  *  set to ENOENT. If the provided option value is not a hierarchical value,
8942b15cb3dSCy Schubert  *  NULL is also returned and errno is set to EINVAL.
8952b15cb3dSCy Schubert  *
8962b15cb3dSCy Schubert  * @param pOptValue    a hierarchcal value
8972b15cb3dSCy Schubert  * @param valueName    name of value to get
8982b15cb3dSCy Schubert  *
8992b15cb3dSCy Schubert  * @return const tOptionValue * - a compound value structure
900ea906c41SOllivier Robert  */
901ea906c41SOllivier Robert extern const tOptionValue * optionGetValue(const tOptionValue *, char const *);
902ea906c41SOllivier Robert 
903ea906c41SOllivier Robert 
9042b15cb3dSCy Schubert /**
905ea906c41SOllivier Robert  * optionLoadLine - process a string for an option name and value
906ea906c41SOllivier Robert  *
907ea906c41SOllivier Robert  *  This is a client program callable routine for setting options from, for
908ea906c41SOllivier Robert  *  example, the contents of a file that they read in.  Only one option may
909ea906c41SOllivier Robert  *  appear in the text.  It will be treated as a normal (non-preset) option.
910ea906c41SOllivier Robert  *
911ea906c41SOllivier Robert  *  When passed a pointer to the option struct and a string, it will find
912ea906c41SOllivier Robert  *  the option named by the first token on the string and set the option
913ea906c41SOllivier Robert  *  argument to the remainder of the string.  The caller must NUL terminate
9142b15cb3dSCy Schubert  *  the string.  The caller need not skip over any introductory hyphens.
9152b15cb3dSCy Schubert  *  Any embedded new lines will be included in the option
916ea906c41SOllivier Robert  *  argument.  If the input looks like one or more quoted strings, then the
917ea906c41SOllivier Robert  *  input will be "cooked".  The "cooking" is identical to the string
918ea906c41SOllivier Robert  *  formation used in AutoGen definition files (@pxref{basic expression}),
919ea906c41SOllivier Robert  *  except that you may not use backquotes.
9202b15cb3dSCy Schubert  *
9212b15cb3dSCy Schubert  * @param opts         program options descriptor
9222b15cb3dSCy Schubert  * @param line         NUL-terminated text
923ea906c41SOllivier Robert  */
924ea906c41SOllivier Robert extern void optionLoadLine(tOptions *, char const *);
925ea906c41SOllivier Robert 
926ea906c41SOllivier Robert 
9272b15cb3dSCy Schubert /**
9282b15cb3dSCy Schubert  * optionMemberList - Get the list of members of a bit mask set
929ea906c41SOllivier Robert  *
9302b15cb3dSCy Schubert  *  This converts the OPT_VALUE_name mask value to a allocated string.
9312b15cb3dSCy Schubert  *  It is the caller's responsibility to free the string.
9322b15cb3dSCy Schubert  *
9332b15cb3dSCy Schubert  * @param od           the set membership option description
9342b15cb3dSCy Schubert  *
9352b15cb3dSCy Schubert  * @return char * - the names of the set bits
9362b15cb3dSCy Schubert  */
9372b15cb3dSCy Schubert extern char * optionMemberList(tOptDesc *);
9382b15cb3dSCy Schubert 
9392b15cb3dSCy Schubert 
9402b15cb3dSCy Schubert /**
941ea906c41SOllivier Robert  * optionNextValue - get the next value from a hierarchical list
942ea906c41SOllivier Robert  *
943ea906c41SOllivier Robert  *  This routine will return the next entry after the entry passed in.  At the
944ea906c41SOllivier Robert  *  end of the list, NULL will be returned.  If the entry is not found on the
945ea906c41SOllivier Robert  *  list, NULL will be returned and "@var{errno}" will be set to EINVAL.
946ea906c41SOllivier Robert  *  The "@var{pOldValue}" must have been gotten from a prior call to this
947ea906c41SOllivier Robert  *  routine or to "@code{opitonGetValue()}".
9482b15cb3dSCy Schubert  *
9492b15cb3dSCy Schubert  * @param pOptValue    a hierarchcal list value
9502b15cb3dSCy Schubert  * @param pOldValue    a value from this list
9512b15cb3dSCy Schubert  *
9522b15cb3dSCy Schubert  * @return const tOptionValue * - a compound value structure
953ea906c41SOllivier Robert  */
954ea906c41SOllivier Robert extern const tOptionValue * optionNextValue(const tOptionValue *, const tOptionValue *);
955ea906c41SOllivier Robert 
956ea906c41SOllivier Robert 
9572b15cb3dSCy Schubert /**
958ea906c41SOllivier Robert  * optionOnlyUsage - Print usage text for just the options
959ea906c41SOllivier Robert  *
960ea906c41SOllivier Robert  *  This routine will print only the usage for each option.
961ea906c41SOllivier Robert  *  This function may be used when the emitted usage must incorporate
962ea906c41SOllivier Robert  *  information not available to AutoOpts.
9632b15cb3dSCy Schubert  *
9642b15cb3dSCy Schubert  * @param pOpts        program options descriptor
9652b15cb3dSCy Schubert  * @param ex_code      exit code for calling exit(3)
966ea906c41SOllivier Robert  */
967ea906c41SOllivier Robert extern void optionOnlyUsage(tOptions *, int);
968ea906c41SOllivier Robert 
969ea906c41SOllivier Robert 
9702b15cb3dSCy Schubert /**
9712b15cb3dSCy Schubert  * optionPrintVersion - Print the program version
972ea906c41SOllivier Robert  *
9732b15cb3dSCy Schubert  *  This routine will print the version to stdout.
9742b15cb3dSCy Schubert  *
9752b15cb3dSCy Schubert  * @param opts         program options descriptor
9762b15cb3dSCy Schubert  * @param od           the descriptor for this arg
9772b15cb3dSCy Schubert  */
9782b15cb3dSCy Schubert extern void optionPrintVersion(tOptions *, tOptDesc *);
9792b15cb3dSCy Schubert 
9802b15cb3dSCy Schubert 
9812b15cb3dSCy Schubert /**
9822b15cb3dSCy Schubert  * optionPrintVersionAndReturn - Print the program version
9832b15cb3dSCy Schubert  *
9842b15cb3dSCy Schubert  *  This routine will print the version to stdout and return
9852b15cb3dSCy Schubert  *  instead of exiting.  Please see the source for the
9862b15cb3dSCy Schubert  *  @code{print_ver} funtion for details on selecting how
9872b15cb3dSCy Schubert  *  verbose to be after this function returns.
9882b15cb3dSCy Schubert  *
9892b15cb3dSCy Schubert  * @param opts         program options descriptor
9902b15cb3dSCy Schubert  * @param od           the descriptor for this arg
9912b15cb3dSCy Schubert  */
9922b15cb3dSCy Schubert extern void optionPrintVersionAndReturn(tOptions *, tOptDesc *);
9932b15cb3dSCy Schubert 
9942b15cb3dSCy Schubert 
9952b15cb3dSCy Schubert /**
996ea906c41SOllivier Robert  * optionProcess - this is the main option processing routine
997ea906c41SOllivier Robert  *
998ea906c41SOllivier Robert  *  This is the main entry point for processing options.  It is intended
999ea906c41SOllivier Robert  *  that this procedure be called once at the beginning of the execution of
1000ea906c41SOllivier Robert  *  a program.  Depending on options selected earlier, it is sometimes
1001ea906c41SOllivier Robert  *  necessary to stop and restart option processing, or to select completely
1002ea906c41SOllivier Robert  *  different sets of options.  This can be done easily, but you generally
1003ea906c41SOllivier Robert  *  do not want to do this.
1004ea906c41SOllivier Robert  *
1005ea906c41SOllivier Robert  *  The number of arguments processed always includes the program name.
1006ea906c41SOllivier Robert  *  If one of the arguments is "--", then it is counted and the processing
1007ea906c41SOllivier Robert  *  stops.  If an error was encountered and errors are to be tolerated, then
1008ea906c41SOllivier Robert  *  the returned value is the index of the argument causing the error.
1009ea906c41SOllivier Robert  *  A hyphen by itself ("-") will also cause processing to stop and will
1010ea906c41SOllivier Robert  *  @emph{not} be counted among the processed arguments.  A hyphen by itself
1011ea906c41SOllivier Robert  *  is treated as an operand.  Encountering an operand stops option
1012ea906c41SOllivier Robert  *  processing.
10132b15cb3dSCy Schubert  *
10142b15cb3dSCy Schubert  * @param opts         program options descriptor
10152b15cb3dSCy Schubert  * @param a_ct         program arg count
10162b15cb3dSCy Schubert  * @param a_v          program arg vector
10172b15cb3dSCy Schubert  *
10182b15cb3dSCy Schubert  * @return int - the count of the arguments processed
1019ea906c41SOllivier Robert  */
1020ea906c41SOllivier Robert extern int optionProcess(tOptions *, int, char **);
1021ea906c41SOllivier Robert 
1022ea906c41SOllivier Robert 
10232b15cb3dSCy Schubert /**
1024ea906c41SOllivier Robert  * optionRestore - restore option state from memory copy
1025ea906c41SOllivier Robert  *
1026ea906c41SOllivier Robert  *  Copy back the option state from saved memory.
1027ea906c41SOllivier Robert  *  The allocated memory is left intact, so this routine can be
1028ea906c41SOllivier Robert  *  called repeatedly without having to call optionSaveState again.
1029ea906c41SOllivier Robert  *  If you are restoring a state that was saved before the first call
1030ea906c41SOllivier Robert  *  to optionProcess(3AO), then you may change the contents of the
1031ea906c41SOllivier Robert  *  argc/argv parameters to optionProcess.
10322b15cb3dSCy Schubert  *
10332b15cb3dSCy Schubert  * @param pOpts        program options descriptor
1034ea906c41SOllivier Robert  */
1035ea906c41SOllivier Robert extern void optionRestore(tOptions *);
1036ea906c41SOllivier Robert 
1037ea906c41SOllivier Robert 
10382b15cb3dSCy Schubert /**
1039ea906c41SOllivier Robert  * optionSaveFile - saves the option state to a file
1040ea906c41SOllivier Robert  *
1041ea906c41SOllivier Robert  *  This routine will save the state of option processing to a file.  The name
1042ea906c41SOllivier Robert  *  of that file can be specified with the argument to the @code{--save-opts}
1043ea906c41SOllivier Robert  *  option, or by appending the @code{rcfile} attribute to the last
1044ea906c41SOllivier Robert  *  @code{homerc} attribute.  If no @code{rcfile} attribute was specified, it
1045ea906c41SOllivier Robert  *  will default to @code{.@i{programname}rc}.  If you wish to specify another
1046ea906c41SOllivier Robert  *  file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro.
10472b15cb3dSCy Schubert  *
10482b15cb3dSCy Schubert  *  The recommend usage is as follows:
10492b15cb3dSCy Schubert  *  @example
10502b15cb3dSCy Schubert  *  optionProcess(&progOptions, argc, argv);
10512b15cb3dSCy Schubert  *  if (i_want_a_non_standard_place_for_this)
10522b15cb3dSCy Schubert  *  SET_OPT_SAVE_OPTS("myfilename");
10532b15cb3dSCy Schubert  *  optionSaveFile(&progOptions);
10542b15cb3dSCy Schubert  *  @end example
10552b15cb3dSCy Schubert  *
10562b15cb3dSCy Schubert  * @param opts         program options descriptor
1057ea906c41SOllivier Robert  */
1058ea906c41SOllivier Robert extern void optionSaveFile(tOptions *);
1059ea906c41SOllivier Robert 
1060ea906c41SOllivier Robert 
10612b15cb3dSCy Schubert /**
1062ea906c41SOllivier Robert  * optionSaveState - saves the option state to memory
1063ea906c41SOllivier Robert  *
1064ea906c41SOllivier Robert  *  This routine will allocate enough memory to save the current option
1065ea906c41SOllivier Robert  *  processing state.  If this routine has been called before, that memory
1066ea906c41SOllivier Robert  *  will be reused.  You may only save one copy of the option state.  This
1067ea906c41SOllivier Robert  *  routine may be called before optionProcess(3AO).  If you do call it
1068ea906c41SOllivier Robert  *  before the first call to optionProcess, then you may also change the
1069ea906c41SOllivier Robert  *  contents of argc/argv after you call optionRestore(3AO)
1070ea906c41SOllivier Robert  *
1071ea906c41SOllivier Robert  *  In fact, more strongly put: it is safest to only use this function
1072ea906c41SOllivier Robert  *  before having processed any options.  In particular, the saving and
1073ea906c41SOllivier Robert  *  restoring of stacked string arguments and hierarchical values is
1074ea906c41SOllivier Robert  *  disabled.  The values are not saved.
10752b15cb3dSCy Schubert  *
10762b15cb3dSCy Schubert  * @param pOpts        program options descriptor
1077ea906c41SOllivier Robert  */
1078ea906c41SOllivier Robert extern void optionSaveState(tOptions *);
1079ea906c41SOllivier Robert 
1080ea906c41SOllivier Robert 
10812b15cb3dSCy Schubert /**
1082ea906c41SOllivier Robert  * optionUnloadNested - Deallocate the memory for a nested value
1083ea906c41SOllivier Robert  *
1084ea906c41SOllivier Robert  *  A nested value needs to be deallocated.  The pointer passed in should
1085ea906c41SOllivier Robert  *  have been gotten from a call to @code{configFileLoad()} (See
1086ea906c41SOllivier Robert  *  @pxref{libopts-configFileLoad}).
10872b15cb3dSCy Schubert  *
10882b15cb3dSCy Schubert  * @param pOptVal      the hierarchical value
1089ea906c41SOllivier Robert  */
1090ea906c41SOllivier Robert extern void optionUnloadNested(tOptionValue const *);
1091ea906c41SOllivier Robert 
1092ea906c41SOllivier Robert 
10932b15cb3dSCy Schubert /**
1094ea906c41SOllivier Robert  * optionVersion - return the compiled AutoOpts version number
1095ea906c41SOllivier Robert  *
1096ea906c41SOllivier Robert  *  Returns the full version string compiled into the library.
1097ea906c41SOllivier Robert  *  The returned string cannot be modified.
10982b15cb3dSCy Schubert  *
10992b15cb3dSCy Schubert  * @return char const * - the version string in constant memory
1100ea906c41SOllivier Robert  */
1101ea906c41SOllivier Robert extern char const * optionVersion(void);
1102ea906c41SOllivier Robert 
1103ea906c41SOllivier Robert 
11042b15cb3dSCy Schubert /**
1105ea906c41SOllivier Robert  * strequate - map a list of characters to the same value
1106ea906c41SOllivier Robert  *
1107ea906c41SOllivier Robert  *  Each character in the input string get mapped to the first character
1108ea906c41SOllivier Robert  *  in the string.
1109ea906c41SOllivier Robert  *  This function name is mapped to option_strequate so as to not conflict
1110ea906c41SOllivier Robert  *  with the POSIX name space.
11112b15cb3dSCy Schubert  *
11122b15cb3dSCy Schubert  * @param ch_list      characters to equivalence
1113ea906c41SOllivier Robert  */
1114ea906c41SOllivier Robert extern void strequate(char const *);
1115ea906c41SOllivier Robert 
1116ea906c41SOllivier Robert 
11172b15cb3dSCy Schubert /**
1118ea906c41SOllivier Robert  * streqvcmp - compare two strings with an equivalence mapping
1119ea906c41SOllivier Robert  *
1120ea906c41SOllivier Robert  *  Using a character mapping, two strings are compared for "equivalence".
1121ea906c41SOllivier Robert  *  Each input character is mapped to a comparison character and the
1122ea906c41SOllivier Robert  *  mapped-to characters are compared for the two NUL terminated input strings.
1123ea906c41SOllivier Robert  *  This function name is mapped to option_streqvcmp so as to not conflict
1124ea906c41SOllivier Robert  *  with the POSIX name space.
11252b15cb3dSCy Schubert  *
11262b15cb3dSCy Schubert  * @param str1         first string
11272b15cb3dSCy Schubert  * @param str2         second string
11282b15cb3dSCy Schubert  *
11292b15cb3dSCy Schubert  * @return int - the difference between two differing characters
1130ea906c41SOllivier Robert  */
1131ea906c41SOllivier Robert extern int streqvcmp(char const *, char const *);
1132ea906c41SOllivier Robert 
1133ea906c41SOllivier Robert 
11342b15cb3dSCy Schubert /**
1135ea906c41SOllivier Robert  * streqvmap - Set the character mappings for the streqv functions
1136ea906c41SOllivier Robert  *
1137ea906c41SOllivier Robert  *  Set the character mapping.  If the count (@code{ct}) is set to zero, then
1138ea906c41SOllivier Robert  *  the map is cleared by setting all entries in the map to their index
1139ea906c41SOllivier Robert  *  value.  Otherwise, the "@code{From}" character is mapped to the "@code{To}"
1140ea906c41SOllivier Robert  *  character.  If @code{ct} is greater than 1, then @code{From} and @code{To}
1141ea906c41SOllivier Robert  *  are incremented and the process repeated until @code{ct} entries have been
1142ea906c41SOllivier Robert  *  set. For example,
1143ea906c41SOllivier Robert  *  @example
1144ea906c41SOllivier Robert  *  streqvmap('a', 'A', 26);
1145ea906c41SOllivier Robert  *  @end example
1146ea906c41SOllivier Robert  *  @noindent
1147ea906c41SOllivier Robert  *  will alter the mapping so that all English lower case letters
1148ea906c41SOllivier Robert  *  will map to upper case.
1149ea906c41SOllivier Robert  *
1150ea906c41SOllivier Robert  *  This function name is mapped to option_streqvmap so as to not conflict
1151ea906c41SOllivier Robert  *  with the POSIX name space.
11522b15cb3dSCy Schubert  *
11532b15cb3dSCy Schubert  * @param from         Input character
11542b15cb3dSCy Schubert  * @param to           Mapped-to character
11552b15cb3dSCy Schubert  * @param ct           compare length
1156ea906c41SOllivier Robert  */
1157ea906c41SOllivier Robert extern void streqvmap(char, char, int);
1158ea906c41SOllivier Robert 
1159ea906c41SOllivier Robert 
11602b15cb3dSCy Schubert /**
1161ea906c41SOllivier Robert  * strneqvcmp - compare two strings with an equivalence mapping
1162ea906c41SOllivier Robert  *
1163ea906c41SOllivier Robert  *  Using a character mapping, two strings are compared for "equivalence".
1164ea906c41SOllivier Robert  *  Each input character is mapped to a comparison character and the
1165ea906c41SOllivier Robert  *  mapped-to characters are compared for the two NUL terminated input strings.
1166ea906c41SOllivier Robert  *  The comparison is limited to @code{ct} bytes.
1167ea906c41SOllivier Robert  *  This function name is mapped to option_strneqvcmp so as to not conflict
1168ea906c41SOllivier Robert  *  with the POSIX name space.
11692b15cb3dSCy Schubert  *
11702b15cb3dSCy Schubert  * @param str1         first string
11712b15cb3dSCy Schubert  * @param str2         second string
11722b15cb3dSCy Schubert  * @param ct           compare length
11732b15cb3dSCy Schubert  *
11742b15cb3dSCy Schubert  * @return int - the difference between two differing characters
1175ea906c41SOllivier Robert  */
1176ea906c41SOllivier Robert extern int strneqvcmp(char const *, char const *, int);
1177ea906c41SOllivier Robert 
1178ea906c41SOllivier Robert 
11792b15cb3dSCy Schubert /**
1180ea906c41SOllivier Robert  * strtransform - convert a string into its mapped-to value
1181ea906c41SOllivier Robert  *
1182ea906c41SOllivier Robert  *  Each character in the input string is mapped and the mapped-to
1183ea906c41SOllivier Robert  *  character is put into the output.
1184ea906c41SOllivier Robert  *  This function name is mapped to option_strtransform so as to not conflict
1185ea906c41SOllivier Robert  *  with the POSIX name space.
11862b15cb3dSCy Schubert  *
11872b15cb3dSCy Schubert  *  The source and destination may be the same.
11882b15cb3dSCy Schubert  *
11892b15cb3dSCy Schubert  * @param dest         output string
11902b15cb3dSCy Schubert  * @param src          input string
1191ea906c41SOllivier Robert  */
1192ea906c41SOllivier Robert extern void strtransform(char *, char const *);
1193ea906c41SOllivier Robert 
1194ea906c41SOllivier Robert /*  AutoOpts PRIVATE FUNCTIONS:  */
1195ea906c41SOllivier Robert tOptProc optionStackArg, optionUnstackArg, optionBooleanVal, optionNumericVal;
1196ea906c41SOllivier Robert 
1197ea906c41SOllivier Robert extern char * ao_string_cook(char *, int *);
1198ea906c41SOllivier Robert 
1199ea906c41SOllivier Robert extern unsigned int ao_string_cook_escape_char(char const *, char *, unsigned int);
1200ea906c41SOllivier Robert 
1201ea906c41SOllivier Robert extern void genshelloptUsage(tOptions *, int);
1202ea906c41SOllivier Robert 
12032b15cb3dSCy Schubert extern int optionAlias(tOptions *, tOptDesc *, unsigned int);
12042b15cb3dSCy Schubert 
1205ea906c41SOllivier Robert extern void optionBooleanVal(tOptions *, tOptDesc *);
1206ea906c41SOllivier Robert 
1207ea906c41SOllivier Robert extern uintptr_t optionEnumerationVal(tOptions *, tOptDesc *, char const * const *, unsigned int);
1208ea906c41SOllivier Robert 
12092b15cb3dSCy Schubert extern void optionFileCheck(tOptions *, tOptDesc *, teOptFileType, tuFileMode);
12102b15cb3dSCy Schubert 
1211ea906c41SOllivier Robert extern char const * optionKeywordName(tOptDesc *, unsigned int);
1212ea906c41SOllivier Robert 
1213ea906c41SOllivier Robert extern void optionLoadOpt(tOptions *, tOptDesc *);
1214ea906c41SOllivier Robert 
12152b15cb3dSCy Schubert extern bool optionMakePath(char *, int, char const *, char const *);
1216ea906c41SOllivier Robert 
1217ea906c41SOllivier Robert extern void optionNestedVal(tOptions *, tOptDesc *);
1218ea906c41SOllivier Robert 
1219ea906c41SOllivier Robert extern void optionNumericVal(tOptions *, tOptDesc *);
1220ea906c41SOllivier Robert 
1221ea906c41SOllivier Robert extern void optionPagedUsage(tOptions *, tOptDesc *);
1222ea906c41SOllivier Robert 
1223ea906c41SOllivier Robert extern void optionParseShell(tOptions *);
1224ea906c41SOllivier Robert 
12252b15cb3dSCy Schubert extern void optionPrintParagraphs(char const *, bool, FILE *);
1226ea906c41SOllivier Robert 
1227ea906c41SOllivier Robert extern void optionPutShell(tOptions *);
1228ea906c41SOllivier Robert 
12292b15cb3dSCy Schubert extern char const * optionQuoteString(char const *, char const *);
12302b15cb3dSCy Schubert 
12312b15cb3dSCy Schubert extern void optionResetOpt(tOptions *, tOptDesc *);
12322b15cb3dSCy Schubert 
1233ea906c41SOllivier Robert extern void optionSetMembers(tOptions *, tOptDesc *, char const * const *, unsigned int);
1234ea906c41SOllivier Robert 
1235276da39aSCy Schubert extern void optionShowRange(tOptions *, tOptDesc *, void *, int);
12362b15cb3dSCy Schubert 
1237ea906c41SOllivier Robert extern void optionStackArg(tOptions *, tOptDesc *);
1238ea906c41SOllivier Robert 
12392b15cb3dSCy Schubert extern void optionTimeDate(tOptions *, tOptDesc *);
12402b15cb3dSCy Schubert 
12412b15cb3dSCy Schubert extern void optionTimeVal(tOptions *, tOptDesc *);
12422b15cb3dSCy Schubert 
1243ea906c41SOllivier Robert extern void optionUnstackArg(tOptions *, tOptDesc *);
1244ea906c41SOllivier Robert 
1245ea906c41SOllivier Robert extern void optionUsage(tOptions *, int);
1246ea906c41SOllivier Robert 
12472b15cb3dSCy Schubert extern void optionVendorOption(tOptions *, tOptDesc *);
12482b15cb3dSCy Schubert 
1249ea906c41SOllivier Robert extern void optionVersionStderr(tOptions *, tOptDesc *);
1250ea906c41SOllivier Robert 
1251ea906c41SOllivier Robert extern void * text_mmap(char const *, int, int, tmap_info_t *);
1252ea906c41SOllivier Robert 
1253ea906c41SOllivier Robert extern int text_munmap(tmap_info_t *);
1254ea906c41SOllivier Robert 
1255ea906c41SOllivier Robert CPLUSPLUS_CLOSER
1256ea906c41SOllivier Robert #endif /* AUTOOPTS_OPTIONS_H_GUARD */
12572b15cb3dSCy Schubert /** @}
12582b15cb3dSCy Schubert  *
1259ea906c41SOllivier Robert  * Local Variables:
1260ea906c41SOllivier Robert  * c-file-style: "stroustrup"
1261ea906c41SOllivier Robert  * indent-tabs-mode: nil
1262ea906c41SOllivier Robert  * End:
1263ea906c41SOllivier Robert  * options.h ends here */
1264