Annotation of embedaddon/ntp/sntp/libopts/autoopts/options.h, revision 1.1
1.1 ! misho 1: /* -*- buffer-read-only: t -*- vi: set ro:
! 2: *
! 3: * DO NOT EDIT THIS FILE (options.h)
! 4: *
! 5: * It has been AutoGen-ed April 29, 2011 at 03:44:02 PM by AutoGen 5.11.9
! 6: * From the definitions funcs.def
! 7: * and the template file options_h
! 8: *
! 9: * This file defines all the global structures and special values
! 10: * used in the automated option processing library.
! 11: *
! 12: * Automated Options Copyright (C) 1992-2011 by Bruce Korb
! 13: *
! 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.
! 18: *
! 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.
! 23: *
! 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/>.";
! 26:
! 27: */
! 28: #ifndef AUTOOPTS_OPTIONS_H_GUARD
! 29: #define AUTOOPTS_OPTIONS_H_GUARD 1
! 30: #include <sys/types.h>
! 31: #include <stdio.h>
! 32:
! 33: #if defined(HAVE_STDINT_H)
! 34: # include <stdint.h>
! 35: #elif defined(HAVE_INTTYPES_H)
! 36: # include <inttypes.h>
! 37: #endif /* HAVE_STDINT/INTTYPES_H */
! 38:
! 39: #if defined(HAVE_LIMITS_H)
! 40: # include <limits.h>
! 41: #elif defined(HAVE_SYS_LIMITS_H)
! 42: # include <sys/limits.h>
! 43: #endif /* HAVE_LIMITS/SYS_LIMITS_H */
! 44:
! 45: #if defined(HAVE_SYSEXITS_H)
! 46: # include <sysexits.h>
! 47: #endif /* HAVE_SYSEXITS_H */
! 48:
! 49: #ifndef EX_USAGE
! 50: # define EX_USAGE 64
! 51: #endif
! 52:
! 53: /*
! 54: * PUBLIC DEFINES
! 55: *
! 56: * The following defines may be used in applications that need to test the
! 57: * state of an option. To test against these masks and values, a pointer
! 58: * to an option descriptor must be obtained. There are two ways:
! 59: *
! 60: * 1. inside an option processing procedure, it is the second argument,
! 61: * conventionally "tOptDesc* pOD".
! 62: *
! 63: * 2. Outside of an option procedure (or to reference a different option
! 64: * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )".
! 65: *
! 66: * See the relevant generated header file to determine which and what
! 67: * values for "opt_name" are available.
! 68: */
! 69: #define OPTIONS_STRUCT_VERSION 143360
! 70: #define OPTIONS_VERSION_STRING "35:0:10"
! 71: #define OPTIONS_MINIMUM_VERSION 102400
! 72: #define OPTIONS_MIN_VER_STRING "25:0:0"
! 73:
! 74: typedef enum {
! 75: OPARG_TYPE_NONE = 0,
! 76: OPARG_TYPE_STRING = 1, /* default type/ vanilla string */
! 77: OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */
! 78: OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */
! 79: OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */
! 80: OPARG_TYPE_NUMERIC = 5, /* opt arg is a long int */
! 81: OPARG_TYPE_HIERARCHY = 6, /* option arg is hierarchical value */
! 82: OPARG_TYPE_FILE = 7, /* option arg names a file */
! 83: OPARG_TYPE_TIME = 8, /* opt arg is a time duration */
! 84: OPARG_TYPE_FLOAT = 9, /* opt arg is a floating point num */
! 85: OPARG_TYPE_DOUBLE = 10, /* opt arg is a double prec. float */
! 86: OPARG_TYPE_LONG_DOUBLE = 11, /* opt arg is a long double prec. */
! 87: OPARG_TYPE_LONG_LONG = 12 /* opt arg is a long long int */
! 88: } teOptArgType;
! 89:
! 90: typedef struct optionValue {
! 91: teOptArgType valType;
! 92: char* pzName;
! 93: union {
! 94: char strVal[1]; /* OPARG_TYPE_STRING */
! 95: unsigned int enumVal; /* OPARG_TYPE_ENUMERATION */
! 96: unsigned int boolVal; /* OPARG_TYPE_BOOLEAN */
! 97: unsigned long setVal; /* OPARG_TYPE_MEMBERSHIP */
! 98: long longVal; /* OPARG_TYPE_NUMERIC */
! 99: void* nestVal; /* OPARG_TYPE_HIERARCHY */
! 100: } v;
! 101: } tOptionValue;
! 102:
! 103: typedef enum {
! 104: FTYPE_MODE_MAY_EXIST = 0x00,
! 105: FTYPE_MODE_MUST_EXIST = 0x01,
! 106: FTYPE_MODE_MUST_NOT_EXIST = 0x02,
! 107: FTYPE_MODE_EXIST_MASK = 0x03,
! 108: FTYPE_MODE_NO_OPEN = 0x00,
! 109: FTYPE_MODE_OPEN_FD = 0x10,
! 110: FTYPE_MODE_FOPEN_FP = 0x20,
! 111: FTYPE_MODE_OPEN_MASK = 0x30
! 112: } teOptFileType;
! 113:
! 114: typedef union {
! 115: int file_flags;
! 116: char const * file_mode;
! 117: } tuFileMode;
! 118:
! 119: typedef struct argList tArgList;
! 120: #define MIN_ARG_ALLOC_CT 6
! 121: #define INCR_ARG_ALLOC_CT 8
! 122: struct argList {
! 123: int useCt;
! 124: int allocCt;
! 125: char const * apzArgs[MIN_ARG_ALLOC_CT];
! 126: };
! 127:
! 128: /*
! 129: * Bits in the fOptState option descriptor field.
! 130: */
! 131: typedef enum {
! 132: OPTST_SET_ID = 0, /* Set via the "SET_OPT()" macro */
! 133: OPTST_PRESET_ID = 1, /* Set via an RC/INI file */
! 134: OPTST_DEFINED_ID = 2, /* Set via a command line option */
! 135: OPTST_RESET_ID = 3, /* Reset via command line option */
! 136: OPTST_EQUIVALENCE_ID = 4, /* selected by equiv'ed option */
! 137: OPTST_DISABLED_ID = 5, /* option is in disabled state */
! 138: OPTST_ALLOC_ARG_ID = 6, /* pzOptArg was allocated */
! 139: OPTST_NO_INIT_ID = 8, /* option cannot be preset */
! 140: OPTST_NUMBER_OPT_ID = 9, /* opt value (flag) is any digit */
! 141: OPTST_STACKED_ID = 10, /* opt uses optionStackArg proc */
! 142: OPTST_INITENABLED_ID = 11, /* option defaults to enabled */
! 143: OPTST_ARG_TYPE_1_ID = 12, /* bit 1 of arg type enum */
! 144: OPTST_ARG_TYPE_2_ID = 13, /* bit 2 of arg type enum */
! 145: OPTST_ARG_TYPE_3_ID = 14, /* bit 3 of arg type enum */
! 146: OPTST_ARG_TYPE_4_ID = 15, /* bit 4 of arg type enum */
! 147: OPTST_ARG_OPTIONAL_ID = 16, /* the option arg not required */
! 148: OPTST_IMM_ID = 17, /* process opt on first pass */
! 149: OPTST_DISABLE_IMM_ID = 18, /* process disablement immed. */
! 150: OPTST_OMITTED_ID = 19, /* compiled out of program */
! 151: OPTST_MUST_SET_ID = 20, /* must be set or pre-set */
! 152: OPTST_DOCUMENT_ID = 21, /* opt is for doc only */
! 153: OPTST_TWICE_ID = 22, /* process opt twice - imm + reg */
! 154: OPTST_DISABLE_TWICE_ID = 23, /* process disabled option twice */
! 155: OPTST_SCALED_NUM_ID = 24, /* scaled integer value */
! 156: OPTST_NO_COMMAND_ID = 25, /* disable from cmd line */
! 157: OPTST_DEPRECATED_ID = 26 /* support is being removed */
! 158: } opt_state_enum_t;
! 159:
! 160: #define OPTST_INIT 0U
! 161: #define OPTST_SET (1U << OPTST_SET_ID)
! 162: #define OPTST_PRESET (1U << OPTST_PRESET_ID)
! 163: #define OPTST_DEFINED (1U << OPTST_DEFINED_ID)
! 164: #define OPTST_RESET (1U << OPTST_RESET_ID)
! 165: #define OPTST_EQUIVALENCE (1U << OPTST_EQUIVALENCE_ID)
! 166: #define OPTST_DISABLED (1U << OPTST_DISABLED_ID)
! 167: #define OPTST_ALLOC_ARG (1U << OPTST_ALLOC_ARG_ID)
! 168: #define OPTST_NO_INIT (1U << OPTST_NO_INIT_ID)
! 169: #define OPTST_NUMBER_OPT (1U << OPTST_NUMBER_OPT_ID)
! 170: #define OPTST_STACKED (1U << OPTST_STACKED_ID)
! 171: #define OPTST_INITENABLED (1U << OPTST_INITENABLED_ID)
! 172: #define OPTST_ARG_TYPE_1 (1U << OPTST_ARG_TYPE_1_ID)
! 173: #define OPTST_ARG_TYPE_2 (1U << OPTST_ARG_TYPE_2_ID)
! 174: #define OPTST_ARG_TYPE_3 (1U << OPTST_ARG_TYPE_3_ID)
! 175: #define OPTST_ARG_TYPE_4 (1U << OPTST_ARG_TYPE_4_ID)
! 176: #define OPTST_ARG_OPTIONAL (1U << OPTST_ARG_OPTIONAL_ID)
! 177: #define OPTST_IMM (1U << OPTST_IMM_ID)
! 178: #define OPTST_DISABLE_IMM (1U << OPTST_DISABLE_IMM_ID)
! 179: #define OPTST_OMITTED (1U << OPTST_OMITTED_ID)
! 180: #define OPTST_MUST_SET (1U << OPTST_MUST_SET_ID)
! 181: #define OPTST_DOCUMENT (1U << OPTST_DOCUMENT_ID)
! 182: #define OPTST_TWICE (1U << OPTST_TWICE_ID)
! 183: #define OPTST_DISABLE_TWICE (1U << OPTST_DISABLE_TWICE_ID)
! 184: #define OPTST_SCALED_NUM (1U << OPTST_SCALED_NUM_ID)
! 185: #define OPTST_NO_COMMAND (1U << OPTST_NO_COMMAND_ID)
! 186: #define OPTST_DEPRECATED (1U << OPTST_DEPRECATED_ID)
! 187: #define OPT_STATE_MASK 0x07FFFF7FU
! 188:
! 189: #define OPTST_SET_MASK ( \
! 190: OPTST_DEFINED | OPTST_PRESET | OPTST_RESET | \
! 191: OPTST_SET \
! 192: /* 0x0000000FU */ )
! 193:
! 194: #define OPTST_MUTABLE_MASK ( \
! 195: OPTST_ALLOC_ARG | OPTST_DEFINED | \
! 196: OPTST_DISABLED | OPTST_EQUIVALENCE | \
! 197: OPTST_PRESET | OPTST_RESET | \
! 198: OPTST_SET \
! 199: /* 0x0000007FU */ )
! 200:
! 201: #define OPTST_SELECTED_MASK ( \
! 202: OPTST_DEFINED | OPTST_SET \
! 203: /* 0x00000005U */ )
! 204:
! 205: #define OPTST_ARG_TYPE_MASK ( \
! 206: OPTST_ARG_TYPE_1 | OPTST_ARG_TYPE_2 | OPTST_ARG_TYPE_3 | \
! 207: OPTST_ARG_TYPE_4 \
! 208: /* 0x0000F000U */ )
! 209:
! 210: #define OPTST_DO_NOT_SAVE_MASK ( \
! 211: OPTST_DOCUMENT | OPTST_NO_INIT | OPTST_OMITTED \
! 212: /* 0x00280100U */ )
! 213:
! 214: #define OPTST_NO_USAGE_MASK ( \
! 215: OPTST_DEPRECATED | OPTST_NO_COMMAND | OPTST_OMITTED \
! 216: /* 0x06080000U */ )
! 217:
! 218: #ifdef NO_OPTIONAL_OPT_ARGS
! 219: # undef OPTST_ARG_OPTIONAL
! 220: # define OPTST_ARG_OPTIONAL 0
! 221: #endif
! 222:
! 223: #define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK)
! 224:
! 225: #define SELECTED_OPT(_od) ((_od)->fOptState & OPTST_SELECTED_MASK)
! 226: #define UNUSED_OPT( _od) (((_od)->fOptState & OPTST_SET_MASK) == 0)
! 227: #define DISABLED_OPT(_od) ((_od)->fOptState & OPTST_DISABLED)
! 228: #define OPTION_STATE(_od) ((_od)->fOptState)
! 229: #define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_1_ID)
! 230: #define OPTST_GET_ARGTYPE(_f) (((_f)&OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID)
! 231:
! 232: /*
! 233: * PRIVATE INTERFACES
! 234: *
! 235: * The following values are used in the generated code to communicate
! 236: * with the option library procedures. They are not for public use
! 237: * and may be subject to change.
! 238: */
! 239:
! 240: /*
! 241: * Define the processing state flags
! 242: */
! 243: typedef enum {
! 244: OPTPROC_LONGOPT_ID = 0, /* Process long style options */
! 245: OPTPROC_SHORTOPT_ID = 1, /* Process short style "flags" */
! 246: OPTPROC_ERRSTOP_ID = 2, /* Stop on argument errors */
! 247: OPTPROC_DISABLEDOPT_ID = 3, /* Current option is disabled */
! 248: OPTPROC_NO_REQ_OPT_ID = 4, /* no options are required */
! 249: OPTPROC_NUM_OPT_ID = 5, /* there is a number option */
! 250: OPTPROC_INITDONE_ID = 6, /* have inits been done? */
! 251: OPTPROC_NEGATIONS_ID = 7, /* any negation options? */
! 252: OPTPROC_ENVIRON_ID = 8, /* check environment? */
! 253: OPTPROC_NO_ARGS_ID = 9, /* Disallow remaining arguments */
! 254: OPTPROC_ARGS_REQ_ID = 10, /* Require args after options */
! 255: OPTPROC_REORDER_ID = 11, /* reorder operands after opts */
! 256: OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */
! 257: OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */
! 258: OPTPROC_MISUSE_ID = 14, /* no usage on usage error */
! 259: OPTPROC_NXLAT_OPT_CFG_ID = 16, /* suppress for config only */
! 260: OPTPROC_NXLAT_OPT_ID = 17, /* suppress xlation always */
! 261: OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */
! 262: } optproc_state_enum_t;
! 263:
! 264: #define OPTPROC_NONE 0U
! 265: #define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID)
! 266: #define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID)
! 267: #define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID)
! 268: #define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID)
! 269: #define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID)
! 270: #define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID)
! 271: #define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID)
! 272: #define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID)
! 273: #define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID)
! 274: #define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID)
! 275: #define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID)
! 276: #define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID)
! 277: #define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID)
! 278: #define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID)
! 279: #define OPTPROC_MISUSE (1U << OPTPROC_MISUSE_ID)
! 280: #define OPTPROC_NXLAT_OPT_CFG (1U << OPTPROC_NXLAT_OPT_CFG_ID)
! 281: #define OPTPROC_NXLAT_OPT (1U << OPTPROC_NXLAT_OPT_ID)
! 282: #define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID)
! 283: #define OPTPROC_STATE_MASK 0x000B7FFFU
! 284:
! 285: #define OPTPROC_NO_XLAT_MASK ( \
! 286: OPTPROC_NXLAT_OPT | OPTPROC_NXLAT_OPT_CFG \
! 287: /* 0x00030000U */ )
! 288:
! 289: #define STMTS(s) do { s; } while (0)
! 290:
! 291: /*
! 292: * The following must be #defined instead of typedef-ed
! 293: * because "static const" cannot both be applied to a type,
! 294: * tho each individually can...so they all are
! 295: */
! 296: #define tSCC static char const
! 297: #define tCC char const
! 298: #define tAoSC static char
! 299: #define tAoUC unsigned char
! 300: #define tAoUI unsigned int
! 301: #define tAoUL unsigned long
! 302: #define tAoUS unsigned short
! 303:
! 304: /*
! 305: * It is so disgusting that there must be so many ways
! 306: * of specifying TRUE and FALSE.
! 307: */
! 308: typedef enum { AG_FALSE = 0, AG_TRUE } ag_bool;
! 309:
! 310: /*
! 311: * Define a structure that describes each option and
! 312: * a pointer to the procedure that handles it.
! 313: * The argument is the count of this flag previously seen.
! 314: */
! 315: typedef struct options tOptions;
! 316: typedef struct optDesc tOptDesc;
! 317: typedef struct optNames tOptNames;
! 318: #define OPTPROC_EMIT_USAGE ((tOptions *)0x01UL)
! 319: #define OPTPROC_EMIT_SHELL ((tOptions *)0x02UL)
! 320: #define OPTPROC_RETURN_VALNAME ((tOptions *)0x03UL)
! 321: #define OPTPROC_EMIT_LIMIT ((tOptions *)0x0FUL)
! 322:
! 323: /*
! 324: * The option procedures do the special processing for each
! 325: * option flag that needs it.
! 326: */
! 327: typedef void (tOptProc)(tOptions* pOpts, tOptDesc* pOptDesc);
! 328: typedef tOptProc* tpOptProc;
! 329:
! 330: /*
! 331: * The usage procedure will never return. It calls "exit(2)"
! 332: * with the "exitCode" argument passed to it.
! 333: */
! 334: // coverity[+kill]
! 335: typedef void (tUsageProc)(tOptions* pOpts, int exitCode);
! 336: typedef tUsageProc* tpUsageProc;
! 337:
! 338: /*
! 339: * Special definitions. "NOLIMIT" is the 'max' value to use when
! 340: * a flag may appear multiple times without limit. "NO_EQUIVALENT"
! 341: * is an illegal value for 'optIndex' (option description index).
! 342: */
! 343: #define NOLIMIT USHRT_MAX
! 344: #define OPTION_LIMIT SHRT_MAX
! 345: #define NO_EQUIVALENT (OPTION_LIMIT+1)
! 346:
! 347: typedef union {
! 348: char const * argString;
! 349: uintptr_t argEnum;
! 350: uintptr_t argIntptr;
! 351: long argInt;
! 352: unsigned long argUint;
! 353: unsigned int argBool;
! 354: FILE * argFp;
! 355: int argFd;
! 356: } optArgBucket_t;
! 357:
! 358: #define pzLastArg optArg.argString
! 359:
! 360: /*
! 361: * Descriptor structure for each option.
! 362: * Only the fields marked "PUBLIC" are for public use.
! 363: */
! 364: struct optDesc {
! 365: tAoUS const optIndex; /* PUBLIC */
! 366: tAoUS const optValue; /* PUBLIC */
! 367: tAoUS optActualIndex; /* PUBLIC */
! 368: tAoUS optActualValue; /* PUBLIC */
! 369:
! 370: tAoUS const optEquivIndex; /* PUBLIC */
! 371: tAoUS const optMinCt;
! 372: tAoUS const optMaxCt;
! 373: tAoUS optOccCt; /* PUBLIC */
! 374:
! 375: tAoUI fOptState; /* PUBLIC */
! 376: tAoUI reserved;
! 377: optArgBucket_t optArg; /* PUBLIC */
! 378: void* optCookie; /* PUBLIC */
! 379:
! 380: int const * const pOptMust;
! 381: int const * const pOptCant;
! 382: tpOptProc const pOptProc;
! 383: char const* const pzText;
! 384:
! 385: char const* const pz_NAME;
! 386: char const* const pz_Name;
! 387: char const* const pz_DisableName;
! 388: char const* const pz_DisablePfx;
! 389: };
! 390:
! 391: /*
! 392: * Some options need special processing, so we store their
! 393: * indexes in a known place:
! 394: */
! 395: typedef struct optSpecIndex tOptSpecIndex;
! 396: struct optSpecIndex {
! 397: const tAoUS more_help;
! 398: const tAoUS save_opts;
! 399: const tAoUS number_option;
! 400: const tAoUS default_opt;
! 401: };
! 402:
! 403: /*
! 404: * The procedure generated for translating option text
! 405: */
! 406: typedef void (tOptionXlateProc)(void);
! 407:
! 408: /*
! 409: * Everything marked "PUBLIC" is also marked "const".
! 410: * Public access is not a license to modify. Other fields
! 411: * are used and modified by the library. They are also
! 412: * subject to change without any notice. Do not even
! 413: * look at these outside of libopts.
! 414: */
! 415: struct options {
! 416: int const structVersion;
! 417: int origArgCt;
! 418: char** origArgVect;
! 419: unsigned int fOptSet;
! 420: unsigned int curOptIdx;
! 421: char* pzCurOpt;
! 422:
! 423: char const* const pzProgPath; /* PUBLIC */
! 424: char const* const pzProgName; /* PUBLIC */
! 425: char const* const pzPROGNAME; /* PUBLIC */
! 426: char const* const pzRcName; /* PUBLIC */
! 427: char const* const pzCopyright; /* PUBLIC */
! 428: char const* const pzCopyNotice; /* PUBLIC */
! 429: char const* const pzFullVersion; /* PUBLIC */
! 430: char const* const* const papzHomeList;
! 431: char const* const pzUsageTitle;
! 432: char const* const pzExplain;
! 433: char const* const pzDetail;
! 434: tOptDesc* const pOptDesc; /* PUBLIC */
! 435: char const* const pzBugAddr; /* PUBLIC */
! 436:
! 437: void* pExtensions;
! 438: void* pSavedState;
! 439:
! 440: // coverity[+kill]
! 441: tpUsageProc pUsageProc;
! 442: tOptionXlateProc* pTransProc;
! 443:
! 444: tOptSpecIndex specOptIdx;
! 445: int const optCt;
! 446: int const presetOptCt;
! 447: char const * pzFullUsage;
! 448: char const * pzShortUsage;
! 449: /* PUBLIC: */
! 450: optArgBucket_t const * const originalOptArgArray;
! 451: void * const * const originalOptArgCookie;
! 452: char const * const pzPkgDataDir;
! 453: char const * const pzPackager;
! 454: };
! 455:
! 456: /*
! 457: * Versions where in various fields first appear:
! 458: * ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero)
! 459: */
! 460: #define originalOptArgArray_STRUCT_VERSION 131072 /* AO_CURRENT = 32 */
! 461: #define HAS_originalOptArgArray(_opt) \
! 462: ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION)
! 463:
! 464: #define pzPkgDataDir_STRUCT_VERSION 139264 /* AO_CURRENT = 34 */
! 465: #define HAS_pzPkgDataDir(_opt) \
! 466: ((_opt)->structVersion >= pzPkgDataDir_STRUCT_VERSION)
! 467:
! 468: /*
! 469: * "token list" structure returned by "string_tokenize()"
! 470: */
! 471: typedef struct {
! 472: unsigned long tkn_ct;
! 473: unsigned char* tkn_list[1];
! 474: } token_list_t;
! 475:
! 476: /*
! 477: * Hide the interface - it pollutes a POSIX claim, but leave it for
! 478: * anyone #include-ing this header
! 479: */
! 480: #define strneqvcmp option_strneqvcmp
! 481: #define streqvcmp option_streqvcmp
! 482: #define streqvmap option_streqvmap
! 483: #define strequate option_strequate
! 484: #define strtransform option_strtransform
! 485:
! 486: /*
! 487: * This is an output only structure used by text_mmap and text_munmap.
! 488: * Clients must not alter the contents and must provide it to both
! 489: * the text_mmap and text_munmap procedures. BE ADVISED: if you are
! 490: * mapping the file with PROT_WRITE the NUL byte at the end MIGHT NOT
! 491: * BE WRITABLE. In any event, that byte is not be written back
! 492: * to the source file. ALSO: if "txt_data" is valid and "txt_errno"
! 493: * is not zero, then there *may* not be a terminating NUL.
! 494: */
! 495: typedef struct {
! 496: void* txt_data; /* text file data */
! 497: size_t txt_size; /* actual file size */
! 498: size_t txt_full_size; /* mmaped mem size */
! 499: int txt_fd; /* file descriptor */
! 500: int txt_zero_fd; /* fd for /dev/zero */
! 501: int txt_errno; /* warning code */
! 502: int txt_prot; /* "prot" flags */
! 503: int txt_flags; /* mapping type */
! 504: int txt_alloc; /* if we malloced memory */
! 505: } tmap_info_t;
! 506:
! 507: #define TEXT_MMAP_FAILED_ADDR(a) ((void*)(a) == (void*)MAP_FAILED)
! 508:
! 509: #ifdef __cplusplus
! 510: #define CPLUSPLUS_OPENER extern "C" {
! 511: CPLUSPLUS_OPENER
! 512: #define CPLUSPLUS_CLOSER }
! 513: #else
! 514: #define CPLUSPLUS_CLOSER
! 515: #endif
! 516:
! 517: /*
! 518: * The following routines may be coded into AutoOpts client code:
! 519: */
! 520:
! 521: /* From: tokenize.c line 166
! 522: *
! 523: * ao_string_tokenize - tokenize an input string
! 524: *
! 525: * Arguments:
! 526: * string string to be tokenized
! 527: *
! 528: * Returns: token_list_t* - pointer to a structure that lists each token
! 529: *
! 530: * This function will convert one input string into a list of strings.
! 531: * The list of strings is derived by separating the input based on
! 532: * white space separation. However, if the input contains either single
! 533: * or double quote characters, then the text after that character up to
! 534: * a matching quote will become the string in the list.
! 535: *
! 536: * The returned pointer should be deallocated with @code{free(3C)} when
! 537: * are done using the data. The data are placed in a single block of
! 538: * allocated memory. Do not deallocate individual token/strings.
! 539: *
! 540: * The structure pointed to will contain at least these two fields:
! 541: * @table @samp
! 542: * @item tkn_ct
! 543: * The number of tokens found in the input string.
! 544: * @item tok_list
! 545: * An array of @code{tkn_ct + 1} pointers to substring tokens, with
! 546: * the last pointer set to NULL.
! 547: * @end table
! 548: *
! 549: * There are two types of quoted strings: single quoted (@code{'}) and
! 550: * double quoted (@code{"}). Singly quoted strings are fairly raw in that
! 551: * escape characters (@code{\\}) are simply another character, except when
! 552: * preceding the following characters:
! 553: * @example
! 554: * @code{\\} double backslashes reduce to one
! 555: * @code{'} incorporates the single quote into the string
! 556: * @code{\n} suppresses both the backslash and newline character
! 557: * @end example
! 558: *
! 559: * Double quote strings are formed according to the rules of string
! 560: * constants in ANSI-C programs.
! 561: */
! 562: extern token_list_t* ao_string_tokenize(char const*);
! 563:
! 564:
! 565: /* From: configfile.c line 80
! 566: *
! 567: * configFileLoad - parse a configuration file
! 568: *
! 569: * Arguments:
! 570: * pzFile the file to load
! 571: *
! 572: * Returns: const tOptionValue* - An allocated, compound value structure
! 573: *
! 574: * This routine will load a named configuration file and parse the
! 575: * text as a hierarchically valued option. The option descriptor
! 576: * created from an option definition file is not used via this interface.
! 577: * The returned value is "named" with the input file name and is of
! 578: * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to
! 579: * @code{optionGetValue()}, @code{optionNextValue()} and
! 580: * @code{optionUnloadNested()}.
! 581: */
! 582: extern const tOptionValue* configFileLoad(char const*);
! 583:
! 584:
! 585: /* From: configfile.c line 1059
! 586: *
! 587: * optionFileLoad - Load the locatable config files, in order
! 588: *
! 589: * Arguments:
! 590: * pOpts program options descriptor
! 591: * pzProg program name
! 592: *
! 593: * Returns: int - 0 -> SUCCESS, -1 -> FAILURE
! 594: *
! 595: * This function looks in all the specified directories for a configuration
! 596: * file ("rc" file or "ini" file) and processes any found twice. The first
! 597: * time through, they are processed in reverse order (last file first). At
! 598: * that time, only "immediate action" configurables are processed. For
! 599: * example, if the last named file specifies not processing any more
! 600: * configuration files, then no more configuration files will be processed.
! 601: * Such an option in the @strong{first} named directory will have no effect.
! 602: *
! 603: * Once the immediate action configurables have been handled, then the
! 604: * directories are handled in normal, forward order. In that way, later
! 605: * config files can override the settings of earlier config files.
! 606: *
! 607: * See the AutoOpts documentation for a thorough discussion of the
! 608: * config file format.
! 609: *
! 610: * Configuration files not found or not decipherable are simply ignored.
! 611: */
! 612: extern int optionFileLoad(tOptions*, char const*);
! 613:
! 614:
! 615: /* From: configfile.c line 212
! 616: *
! 617: * optionFindNextValue - find a hierarcicaly valued option instance
! 618: *
! 619: * Arguments:
! 620: * pOptDesc an option with a nested arg type
! 621: * pPrevVal the last entry
! 622: * name name of value to find
! 623: * value the matching value
! 624: *
! 625: * Returns: const tOptionValue* - a compound value structure
! 626: *
! 627: * This routine will find the next entry in a nested value option or
! 628: * configurable. It will search through the list and return the next entry
! 629: * that matches the criteria.
! 630: */
! 631: extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionValue*, char const*, char const*);
! 632:
! 633:
! 634: /* From: configfile.c line 138
! 635: *
! 636: * optionFindValue - find a hierarcicaly valued option instance
! 637: *
! 638: * Arguments:
! 639: * pOptDesc an option with a nested arg type
! 640: * name name of value to find
! 641: * value the matching value
! 642: *
! 643: * Returns: const tOptionValue* - a compound value structure
! 644: *
! 645: * This routine will find an entry in a nested value option or configurable.
! 646: * It will search through the list and return a matching entry.
! 647: */
! 648: extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char const*);
! 649:
! 650:
! 651: /* From: restore.c line 166
! 652: *
! 653: * optionFree - free allocated option processing memory
! 654: *
! 655: * Arguments:
! 656: * pOpts program options descriptor
! 657: *
! 658: * AutoOpts sometimes allocates memory and puts pointers to it in the
! 659: * option state structures. This routine deallocates all such memory.
! 660: */
! 661: extern void optionFree(tOptions*);
! 662:
! 663:
! 664: /* From: configfile.c line 281
! 665: *
! 666: * optionGetValue - get a specific value from a hierarcical list
! 667: *
! 668: * Arguments:
! 669: * pOptValue a hierarchcal value
! 670: * valueName name of value to get
! 671: *
! 672: * Returns: const tOptionValue* - a compound value structure
! 673: *
! 674: * This routine will find an entry in a nested value option or configurable.
! 675: * If "valueName" is NULL, then the first entry is returned. Otherwise,
! 676: * the first entry with a name that exactly matches the argument will be
! 677: * returned.
! 678: */
! 679: extern const tOptionValue* optionGetValue(const tOptionValue*, char const*);
! 680:
! 681:
! 682: /* From: load.c line 478
! 683: *
! 684: * optionLoadLine - process a string for an option name and value
! 685: *
! 686: * Arguments:
! 687: * pOpts program options descriptor
! 688: * pzLine NUL-terminated text
! 689: *
! 690: * This is a client program callable routine for setting options from, for
! 691: * example, the contents of a file that they read in. Only one option may
! 692: * appear in the text. It will be treated as a normal (non-preset) option.
! 693: *
! 694: * When passed a pointer to the option struct and a string, it will find
! 695: * the option named by the first token on the string and set the option
! 696: * argument to the remainder of the string. The caller must NUL terminate
! 697: * the string. Any embedded new lines will be included in the option
! 698: * argument. If the input looks like one or more quoted strings, then the
! 699: * input will be "cooked". The "cooking" is identical to the string
! 700: * formation used in AutoGen definition files (@pxref{basic expression}),
! 701: * except that you may not use backquotes.
! 702: */
! 703: extern void optionLoadLine(tOptions*, char const*);
! 704:
! 705:
! 706: /* From: configfile.c line 340
! 707: *
! 708: * optionNextValue - get the next value from a hierarchical list
! 709: *
! 710: * Arguments:
! 711: * pOptValue a hierarchcal list value
! 712: * pOldValue a value from this list
! 713: *
! 714: * Returns: const tOptionValue* - a compound value structure
! 715: *
! 716: * This routine will return the next entry after the entry passed in. At the
! 717: * end of the list, NULL will be returned. If the entry is not found on the
! 718: * list, NULL will be returned and "@var{errno}" will be set to EINVAL.
! 719: * The "@var{pOldValue}" must have been gotten from a prior call to this
! 720: * routine or to "@code{opitonGetValue()}".
! 721: */
! 722: extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionValue*);
! 723:
! 724:
! 725: /* From: usage.c line 195
! 726: *
! 727: * optionOnlyUsage - Print usage text for just the options
! 728: *
! 729: * Arguments:
! 730: * pOpts program options descriptor
! 731: * ex_code exit code for calling exit(3)
! 732: *
! 733: * This routine will print only the usage for each option.
! 734: * This function may be used when the emitted usage must incorporate
! 735: * information not available to AutoOpts.
! 736: */
! 737: extern void optionOnlyUsage(tOptions*, int);
! 738:
! 739:
! 740: /* From: autoopts.c line 1065
! 741: *
! 742: * optionProcess - this is the main option processing routine
! 743: *
! 744: * Arguments:
! 745: * pOpts program options descriptor
! 746: * argc program arg count
! 747: * argv program arg vector
! 748: *
! 749: * Returns: int - the count of the arguments processed
! 750: *
! 751: * This is the main entry point for processing options. It is intended
! 752: * that this procedure be called once at the beginning of the execution of
! 753: * a program. Depending on options selected earlier, it is sometimes
! 754: * necessary to stop and restart option processing, or to select completely
! 755: * different sets of options. This can be done easily, but you generally
! 756: * do not want to do this.
! 757: *
! 758: * The number of arguments processed always includes the program name.
! 759: * If one of the arguments is "--", then it is counted and the processing
! 760: * stops. If an error was encountered and errors are to be tolerated, then
! 761: * the returned value is the index of the argument causing the error.
! 762: * A hyphen by itself ("-") will also cause processing to stop and will
! 763: * @emph{not} be counted among the processed arguments. A hyphen by itself
! 764: * is treated as an operand. Encountering an operand stops option
! 765: * processing.
! 766: */
! 767: extern int optionProcess(tOptions*, int, char**);
! 768:
! 769:
! 770: /* From: restore.c line 123
! 771: *
! 772: * optionRestore - restore option state from memory copy
! 773: *
! 774: * Arguments:
! 775: * pOpts program options descriptor
! 776: *
! 777: * Copy back the option state from saved memory.
! 778: * The allocated memory is left intact, so this routine can be
! 779: * called repeatedly without having to call optionSaveState again.
! 780: * If you are restoring a state that was saved before the first call
! 781: * to optionProcess(3AO), then you may change the contents of the
! 782: * argc/argv parameters to optionProcess.
! 783: */
! 784: extern void optionRestore(tOptions*);
! 785:
! 786:
! 787: /* From: save.c line 664
! 788: *
! 789: * optionSaveFile - saves the option state to a file
! 790: *
! 791: * Arguments:
! 792: * pOpts program options descriptor
! 793: *
! 794: * This routine will save the state of option processing to a file. The name
! 795: * of that file can be specified with the argument to the @code{--save-opts}
! 796: * option, or by appending the @code{rcfile} attribute to the last
! 797: * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it
! 798: * will default to @code{.@i{programname}rc}. If you wish to specify another
! 799: * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro.
! 800: *
! 801: * The recommend usage is as follows:
! 802: * @example
! 803: * optionProcess(&progOptions, argc, argv);
! 804: * if (i_want_a_non_standard_place_for_this)
! 805: * SET_OPT_SAVE_OPTS("myfilename");
! 806: * optionSaveFile(&progOptions);
! 807: * @end example
! 808: */
! 809: extern void optionSaveFile(tOptions*);
! 810:
! 811:
! 812: /* From: restore.c line 71
! 813: *
! 814: * optionSaveState - saves the option state to memory
! 815: *
! 816: * Arguments:
! 817: * pOpts program options descriptor
! 818: *
! 819: * This routine will allocate enough memory to save the current option
! 820: * processing state. If this routine has been called before, that memory
! 821: * will be reused. You may only save one copy of the option state. This
! 822: * routine may be called before optionProcess(3AO). If you do call it
! 823: * before the first call to optionProcess, then you may also change the
! 824: * contents of argc/argv after you call optionRestore(3AO)
! 825: *
! 826: * In fact, more strongly put: it is safest to only use this function
! 827: * before having processed any options. In particular, the saving and
! 828: * restoring of stacked string arguments and hierarchical values is
! 829: * disabled. The values are not saved.
! 830: */
! 831: extern void optionSaveState(tOptions*);
! 832:
! 833:
! 834: /* From: nested.c line 551
! 835: *
! 836: * optionUnloadNested - Deallocate the memory for a nested value
! 837: *
! 838: * Arguments:
! 839: * pOptVal the hierarchical value
! 840: *
! 841: * A nested value needs to be deallocated. The pointer passed in should
! 842: * have been gotten from a call to @code{configFileLoad()} (See
! 843: * @pxref{libopts-configFileLoad}).
! 844: */
! 845: extern void optionUnloadNested(tOptionValue const *);
! 846:
! 847:
! 848: /* From: version.c line 31
! 849: *
! 850: * optionVersion - return the compiled AutoOpts version number
! 851: *
! 852: * Returns: char const* - the version string in constant memory
! 853: *
! 854: * Returns the full version string compiled into the library.
! 855: * The returned string cannot be modified.
! 856: */
! 857: extern char const* optionVersion(void);
! 858:
! 859:
! 860: /* From: ../compat/pathfind.c line 29
! 861: *
! 862: * pathfind - fild a file in a list of directories
! 863: *
! 864: * Arguments:
! 865: * path colon separated list of search directories
! 866: * file the name of the file to look for
! 867: * mode the mode bits that must be set to match
! 868: *
! 869: * Returns: char* - the path to the located file
! 870: *
! 871: * the pathfind function is available only if HAVE_PATHFIND is not defined
! 872: *
! 873: * pathfind looks for a a file with name "FILE" and "MODE" access
! 874: * along colon delimited "PATH", and returns the full pathname as a
! 875: * string, or NULL if not found. If "FILE" contains a slash, then
! 876: * it is treated as a relative or absolute path and "PATH" is ignored.
! 877: *
! 878: * @strong{NOTE}: this function is compiled into @file{libopts} only if
! 879: * it is not natively supplied.
! 880: *
! 881: * The "MODE" argument is a string of option letters chosen from the
! 882: * list below:
! 883: * @example
! 884: * Letter Meaning
! 885: * r readable
! 886: * w writable
! 887: * x executable
! 888: * f normal file (NOT IMPLEMENTED)
! 889: * b block special (NOT IMPLEMENTED)
! 890: * c character special (NOT IMPLEMENTED)
! 891: * d directory (NOT IMPLEMENTED)
! 892: * p FIFO (pipe) (NOT IMPLEMENTED)
! 893: * u set user ID bit (NOT IMPLEMENTED)
! 894: * g set group ID bit (NOT IMPLEMENTED)
! 895: * k sticky bit (NOT IMPLEMENTED)
! 896: * s size nonzero (NOT IMPLEMENTED)
! 897: * @end example
! 898: */
! 899: #ifndef HAVE_PATHFIND
! 900: extern char* pathfind(char const*, char const*, char const*);
! 901: #endif /* HAVE_PATHFIND */
! 902:
! 903:
! 904: /* From: streqvcmp.c line 209
! 905: *
! 906: * strequate - map a list of characters to the same value
! 907: *
! 908: * Arguments:
! 909: * ch_list characters to equivalence
! 910: *
! 911: * Each character in the input string get mapped to the first character
! 912: * in the string.
! 913: * This function name is mapped to option_strequate so as to not conflict
! 914: * with the POSIX name space.
! 915: */
! 916: extern void strequate(char const*);
! 917:
! 918:
! 919: /* From: streqvcmp.c line 119
! 920: *
! 921: * streqvcmp - compare two strings with an equivalence mapping
! 922: *
! 923: * Arguments:
! 924: * str1 first string
! 925: * str2 second string
! 926: *
! 927: * Returns: int - the difference between two differing characters
! 928: *
! 929: * Using a character mapping, two strings are compared for "equivalence".
! 930: * Each input character is mapped to a comparison character and the
! 931: * mapped-to characters are compared for the two NUL terminated input strings.
! 932: * This function name is mapped to option_streqvcmp so as to not conflict
! 933: * with the POSIX name space.
! 934: */
! 935: extern int streqvcmp(char const*, char const*);
! 936:
! 937:
! 938: /* From: streqvcmp.c line 156
! 939: *
! 940: * streqvmap - Set the character mappings for the streqv functions
! 941: *
! 942: * Arguments:
! 943: * From Input character
! 944: * To Mapped-to character
! 945: * ct compare length
! 946: *
! 947: * Set the character mapping. If the count (@code{ct}) is set to zero, then
! 948: * the map is cleared by setting all entries in the map to their index
! 949: * value. Otherwise, the "@code{From}" character is mapped to the "@code{To}"
! 950: * character. If @code{ct} is greater than 1, then @code{From} and @code{To}
! 951: * are incremented and the process repeated until @code{ct} entries have been
! 952: * set. For example,
! 953: * @example
! 954: * streqvmap('a', 'A', 26);
! 955: * @end example
! 956: * @noindent
! 957: * will alter the mapping so that all English lower case letters
! 958: * will map to upper case.
! 959: *
! 960: * This function name is mapped to option_streqvmap so as to not conflict
! 961: * with the POSIX name space.
! 962: */
! 963: extern void streqvmap(char, char, int);
! 964:
! 965:
! 966: /* From: streqvcmp.c line 78
! 967: *
! 968: * strneqvcmp - compare two strings with an equivalence mapping
! 969: *
! 970: * Arguments:
! 971: * str1 first string
! 972: * str2 second string
! 973: * ct compare length
! 974: *
! 975: * Returns: int - the difference between two differing characters
! 976: *
! 977: * Using a character mapping, two strings are compared for "equivalence".
! 978: * Each input character is mapped to a comparison character and the
! 979: * mapped-to characters are compared for the two NUL terminated input strings.
! 980: * The comparison is limited to @code{ct} bytes.
! 981: * This function name is mapped to option_strneqvcmp so as to not conflict
! 982: * with the POSIX name space.
! 983: */
! 984: extern int strneqvcmp(char const*, char const*, int);
! 985:
! 986:
! 987: /* From: streqvcmp.c line 235
! 988: *
! 989: * strtransform - convert a string into its mapped-to value
! 990: *
! 991: * Arguments:
! 992: * dest output string
! 993: * src input string
! 994: *
! 995: * Each character in the input string is mapped and the mapped-to
! 996: * character is put into the output.
! 997: * This function name is mapped to option_strtransform so as to not conflict
! 998: * with the POSIX name space.
! 999: *
! 1000: * The source and destination may be the same.
! 1001: */
! 1002: extern void strtransform(char*, char const*);
! 1003:
! 1004: /* AutoOpts PRIVATE FUNCTIONS: */
! 1005: tOptProc optionStackArg, optionUnstackArg, optionBooleanVal, optionNumericVal;
! 1006:
! 1007: extern char* ao_string_cook(char*, int*);
! 1008:
! 1009: extern unsigned int ao_string_cook_escape_char(char const*, char*, unsigned int);
! 1010:
! 1011: extern void genshelloptUsage(tOptions*, int);
! 1012:
! 1013: extern void optionBooleanVal(tOptions*, tOptDesc*);
! 1014:
! 1015: extern uintptr_t optionEnumerationVal(tOptions*, tOptDesc*, char const * const *, unsigned int);
! 1016:
! 1017: extern void optionFileCheck(tOptions*, tOptDesc*, teOptFileType, tuFileMode);
! 1018:
! 1019: extern char const * optionKeywordName(tOptDesc*, unsigned int);
! 1020:
! 1021: extern void optionLoadOpt(tOptions*, tOptDesc*);
! 1022:
! 1023: extern ag_bool optionMakePath(char*, int, char const*, char const*);
! 1024:
! 1025: extern void optionNestedVal(tOptions*, tOptDesc*);
! 1026:
! 1027: extern void optionNumericVal(tOptions*, tOptDesc*);
! 1028:
! 1029: extern void optionPagedUsage(tOptions*, tOptDesc*);
! 1030:
! 1031: extern void optionParseShell(tOptions*);
! 1032:
! 1033: extern void optionPrintVersion(tOptions*, tOptDesc*);
! 1034:
! 1035: extern void optionPutShell(tOptions*);
! 1036:
! 1037: extern void optionResetOpt(tOptions*, tOptDesc*);
! 1038:
! 1039: extern void optionSetMembers(tOptions*, tOptDesc*, char const * const *, unsigned int);
! 1040:
! 1041: extern void optionShowRange(tOptions*, tOptDesc*, void *, int);
! 1042:
! 1043: extern void optionStackArg(tOptions*, tOptDesc*);
! 1044:
! 1045: extern void optionTimeDate(tOptions*, tOptDesc*);
! 1046:
! 1047: extern void optionTimeVal(tOptions*, tOptDesc*);
! 1048:
! 1049: extern void optionUnstackArg(tOptions*, tOptDesc*);
! 1050:
! 1051: extern void optionUsage(tOptions*, int);
! 1052:
! 1053: extern void optionVersionStderr(tOptions*, tOptDesc*);
! 1054:
! 1055: extern void* text_mmap(char const*, int, int, tmap_info_t*);
! 1056:
! 1057: extern int text_munmap(tmap_info_t*);
! 1058:
! 1059: CPLUSPLUS_CLOSER
! 1060: #endif /* AUTOOPTS_OPTIONS_H_GUARD */
! 1061: /*
! 1062: * Local Variables:
! 1063: * c-file-style: "stroustrup"
! 1064: * indent-tabs-mode: nil
! 1065: * End:
! 1066: * options.h ends here */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>