📄 options.h
字号:
/* -*- buffer-read-only: t -*- vi: set ro: * * DO NOT EDIT THIS FILE (options.h) * * It has been AutoGen-ed Saturday May 5, 2007 at 12:02:34 PM PDT * From the definitions funcs.def * and the template file options_h * * This file defines all the global structures and special values * used in the automated option processing library. * * Automated Options copyright 1992-Y Bruce Korb * * AutoOpts is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * AutoOpts is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with AutoOpts. If not, write to: * The Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301, USA. */#ifndef AUTOOPTS_OPTIONS_H_GUARD#define AUTOOPTS_OPTIONS_H_GUARD#include <sys/types.h>#if defined(HAVE_STDINT_H)# include <stdint.h>#elif defined(HAVE_INTTYPES_H)# include <inttypes.h>#endif /* HAVE_STDINT/INTTYPES_H */#if defined(HAVE_LIMITS_H)# include <limits.h>#elif defined(HAVE_SYS_LIMITS_H)# include <sys/limits.h>#endif /* HAVE_LIMITS/SYS_LIMITS_H */#if defined(HAVE_SYSEXITS_H)# include <sysexits.h>#endif /* HAVE_SYSEXITS_H */#ifndef EX_USAGE# define EX_USAGE 64#endif/* * PUBLIC DEFINES * * The following defines may be used in applications that need to test the * state of an option. To test against these masks and values, a pointer * to an option descriptor must be obtained. There are two ways: * * 1. inside an option processing procedure, it is the second argument, * conventionally "tOptDesc* pOD". * * 2. Outside of an option procedure (or to reference a different option * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )". * * See the relevant generated header file to determine which and what * values for "opt_name" are available. */#define OPTIONS_STRUCT_VERSION 118784#define OPTIONS_VERSION_STRING "29:0:4"#define OPTIONS_MINIMUM_VERSION 102400#define OPTIONS_MIN_VER_STRING "25:0:0"typedef enum { OPARG_TYPE_NONE = 0, OPARG_TYPE_STRING = 1, /* default type/ vanilla string */ OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */ OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */ OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */ OPARG_TYPE_NUMERIC = 5, /* opt arg has numeric value */ OPARG_TYPE_HIERARCHY = 6 /* option arg is hierarchical value */} teOptArgType;typedef struct optionValue { teOptArgType valType; char* pzName; union { char strVal[1]; /* OPARG_TYPE_STRING */ unsigned int enumVal; /* OPARG_TYPE_ENUMERATION */ unsigned int boolVal; /* OPARG_TYPE_BOOLEAN */ unsigned long setVal; /* OPARG_TYPE_MEMBERSHIP */ long longVal; /* OPARG_TYPE_NUMERIC */ void* nestVal; /* OPARG_TYPE_HIERARCHY */ } v;} tOptionValue;/* * Bits in the fOptState option descriptor field. */typedef enum { OPTST_SET_ID = 0, /* Set via the "SET_OPT()" macro */ OPTST_PRESET_ID = 1, /* Set via an RC/INI file */ OPTST_DEFINED_ID = 2, /* Set via a command line option */ OPTST_EQUIVALENCE_ID = 4, /* selected by equiv'ed option */ OPTST_DISABLED_ID = 5, /* option is in disabled state */ OPTST_ALLOC_ARG_ID = 6, /* pzOptArg was allocated */ OPTST_NO_INIT_ID = 8, /* option cannot be preset */ OPTST_NUMBER_OPT_ID = 9, /* opt value (flag) is any digit */ OPTST_STACKED_ID = 10, /* opt uses optionStackArg proc */ OPTST_INITENABLED_ID = 11, /* option defaults to enabled */ OPTST_ARG_TYPE_1_ID = 12, /* bit 1 of arg type enum */ OPTST_ARG_TYPE_2_ID = 13, /* bit 2 of arg type enum */ OPTST_ARG_TYPE_3_ID = 14, /* bit 3 of arg type enum */ OPTST_ARG_TYPE_4_ID = 15, /* bit 4 of arg type enum */ OPTST_ARG_OPTIONAL_ID = 16, /* the option arg not required */ OPTST_IMM_ID = 17, /* process opt on first pass */ OPTST_DISABLE_IMM_ID = 18, /* process disablement immed. */ OPTST_OMITTED_ID = 19, /* compiled out of program */ OPTST_MUST_SET_ID = 20, /* must be set or pre-set */ OPTST_DOCUMENT_ID = 21, /* opt is for doc only */ OPTST_TWICE_ID = 22, /* process opt twice - imm + reg */ OPTST_DISABLE_TWICE_ID = 23 /* process disabled option twice */} opt_state_enum_t;#define OPTST_INIT 0U#define OPTST_SET (1U << OPTST_SET_ID)#define OPTST_PRESET (1U << OPTST_PRESET_ID)#define OPTST_DEFINED (1U << OPTST_DEFINED_ID)#define OPTST_EQUIVALENCE (1U << OPTST_EQUIVALENCE_ID)#define OPTST_DISABLED (1U << OPTST_DISABLED_ID)#define OPTST_ALLOC_ARG (1U << OPTST_ALLOC_ARG_ID)#define OPTST_NO_INIT (1U << OPTST_NO_INIT_ID)#define OPTST_NUMBER_OPT (1U << OPTST_NUMBER_OPT_ID)#define OPTST_STACKED (1U << OPTST_STACKED_ID)#define OPTST_INITENABLED (1U << OPTST_INITENABLED_ID)#define OPTST_ARG_TYPE_1 (1U << OPTST_ARG_TYPE_1_ID)#define OPTST_ARG_TYPE_2 (1U << OPTST_ARG_TYPE_2_ID)#define OPTST_ARG_TYPE_3 (1U << OPTST_ARG_TYPE_3_ID)#define OPTST_ARG_TYPE_4 (1U << OPTST_ARG_TYPE_4_ID)#define OPTST_ARG_OPTIONAL (1U << OPTST_ARG_OPTIONAL_ID)#define OPTST_IMM (1U << OPTST_IMM_ID)#define OPTST_DISABLE_IMM (1U << OPTST_DISABLE_IMM_ID)#define OPTST_OMITTED (1U << OPTST_OMITTED_ID)#define OPTST_MUST_SET (1U << OPTST_MUST_SET_ID)#define OPTST_DOCUMENT (1U << OPTST_DOCUMENT_ID)#define OPTST_TWICE (1U << OPTST_TWICE_ID)#define OPTST_DISABLE_TWICE (1U << OPTST_DISABLE_TWICE_ID)#define OPT_STATE_MASK 0x00FFFF77U#define OPTST_SET_MASK ( \ OPTST_SET | \ OPTST_PRESET | \ OPTST_DEFINED )#define OPTST_MUTABLE_MASK ( \ OPTST_SET | \ OPTST_PRESET | \ OPTST_DEFINED | \ OPTST_EQUIVALENCE | \ OPTST_DISABLED | \ OPTST_ALLOC_ARG )#define OPTST_SELECTED_MASK ( \ OPTST_SET | \ OPTST_DEFINED )#define OPTST_ARG_TYPE_MASK ( \ OPTST_ARG_TYPE_1 | \ OPTST_ARG_TYPE_2 | \ OPTST_ARG_TYPE_3 | \ OPTST_ARG_TYPE_4 )#ifdef NO_OPTIONAL_OPT_ARGS# undef OPTST_ARG_OPTIONAL# define OPTST_ARG_OPTIONAL 0#endif#define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK)#define SELECTED_OPT( pod ) ((pod)->fOptState & OPTST_SELECTED_MASK)#define UNUSED_OPT( pod ) (((pod)->fOptState & OPTST_SET_MASK) == 0)#define DISABLED_OPT( pod ) ((pod)->fOptState & OPTST_DISABLED)#define OPTION_STATE( pod ) ((pod)->fOptState)#define OPTST_SET_ARGTYPE(n) ((n) << OPTST_ARG_TYPE_1_ID)#define OPTST_GET_ARGTYPE(f) (((f) & OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID)/* * PRIVATE INTERFACES * * The following values are used in the generated code to communicate * with the option library procedures. They are not for public use * and may be subject to change. *//* * Define the processing state flags */typedef enum { OPTPROC_LONGOPT_ID = 0, /* Process long style options */ OPTPROC_SHORTOPT_ID = 1, /* Process short style "flags" */ OPTPROC_ERRSTOP_ID = 2, /* Stop on argument errors */ OPTPROC_DISABLEDOPT_ID = 3, /* Current option is disabled */ OPTPROC_NO_REQ_OPT_ID = 4, /* no options are required */ OPTPROC_NUM_OPT_ID = 5, /* there is a number option */ OPTPROC_INITDONE_ID = 6, /* have initializations been done? */ OPTPROC_NEGATIONS_ID = 7, /* any negation options? */ OPTPROC_ENVIRON_ID = 8, /* check environment? */ OPTPROC_NO_ARGS_ID = 9, /* Disallow remaining arguments */ OPTPROC_ARGS_REQ_ID = 10, /* Require arguments after options */ OPTPROC_REORDER_ID = 11, /* reorder operands after options */ OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */ OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */ OPTPROC_HAS_IMMED_ID = 14, /* program defines immed options */ OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */} optproc_state_enum_t;#define OPTPROC_NONE 0U#define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID)#define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID)#define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID)#define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID)#define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID)#define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID)#define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID)#define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID)#define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID)#define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID)#define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID)#define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID)#define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID)#define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID)#define OPTPROC_HAS_IMMED (1U << OPTPROC_HAS_IMMED_ID)#define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID)#define OPTPROC_STATE_MASK 0x00087FFFU#define STMTS(s) do { s; } while (0)/* * The following must be #defined instead of typedef-ed * because "static const" cannot both be applied to a type, * tho each individually can...so they all are */#define tSCC static char const#define tCC char const#define tAoSC static char#define tAoUC unsigned char#define tAoUI unsigned int#define tAoUL unsigned long#define tAoUS unsigned short/* * It is so disgusting that there must be so many ways * of specifying TRUE and FALSE. */typedef enum { AG_FALSE = 0, AG_TRUE } ag_bool;/* * Define a structure that describes each option and * a pointer to the procedure that handles it. * The argument is the count of this flag previously seen. */typedef struct options tOptions;typedef struct optDesc tOptDesc;typedef struct optNames tOptNames;/* * The option procedures do the special processing for each * option flag that needs it. */typedef void (tOptProc)( tOptions* pOpts, tOptDesc* pOptDesc );typedef tOptProc* tpOptProc;/* * The usage procedure will never return. It calls "exit(2)" * with the "exitCode" argument passed to it. */typedef void (tUsageProc)( tOptions* pOpts, int exitCode );typedef tUsageProc* tpUsageProc;/* * Special definitions. "NOLIMIT" is the 'max' value to use when * a flag may appear multiple times without limit. "NO_EQUIVALENT" * is an illegal value for 'optIndex' (option description index). */#define NOLIMIT USHRT_MAX#define OPTION_LIMIT SHRT_MAX#define NO_EQUIVALENT (OPTION_LIMIT+1)/* * Special values for optValue. It must not be generatable from the * computation "optIndex +96". Since "optIndex" is limited to 100, ... */#define NUMBER_OPTION '#'typedef struct argList tArgList;#define MIN_ARG_ALLOC_CT 6#define INCR_ARG_ALLOC_CT 8struct argList { int useCt; int allocCt; tCC* apzArgs[ MIN_ARG_ALLOC_CT ];};typedef union { char const * argString; uintptr_t argEnum; uintptr_t argIntptr; long argInt; unsigned long argUint; unsigned int argBool;} optArgBucket_t;/* * Descriptor structure for each option. * Only the fields marked "PUBLIC" are for public use. */struct optDesc { tAoUS const optIndex; /* PUBLIC */ tAoUS const optValue; /* PUBLIC */ tAoUS optActualIndex; /* PUBLIC */ tAoUS optActualValue; /* PUBLIC */ tAoUS const optEquivIndex; /* PUBLIC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -