123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #ifndef AUTOOPTS_GENSHELL_H_GUARD
- #define AUTOOPTS_GENSHELL_H_GUARD 1
- #include <autoopts/options.h>
- #include <stdarg.h>
- #include <stdnoreturn.h>
- #define AO_TEMPLATE_VERSION 172033
- #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
- || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
- # error option template version mismatches autoopts/options.h header
- Choke Me.
- #endif
- #if GCC_VERSION > 40400
- #define NOT_REACHED __builtin_unreachable();
- #else
- #define NOT_REACHED
- #endif
- typedef enum {
- INDEX_GENSHELL_OPT_SCRIPT = 0,
- INDEX_GENSHELL_OPT_SHELL = 1,
- INDEX_GENSHELL_OPT_VERSION = 2,
- INDEX_GENSHELL_OPT_HELP = 3,
- INDEX_GENSHELL_OPT_MORE_HELP = 4
- } teGenshell_OptIndex;
- #define GENSHELL_OPTION_CT 5
- #define GENSHELLOPT_VERSION "1"
- #define GENSHELLOPT_FULL_VERSION "genshellopt 1"
- #define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n])
- #define HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n)))
- #define GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString)
- #define STATE_GENSHELL_OPT(n) (GENSHELL_DESC(n).fOptState & OPTST_SET_MASK)
- #define COUNT_GENSHELL_OPT(n) (GENSHELL_DESC(n).optOccCt)
- #define ISSEL_GENSHELL_OPT(n) (SELECTED_OPT(&GENSHELL_DESC(n)))
- #define ISUNUSED_GENSHELL_OPT(n) (UNUSED_OPT(& GENSHELL_DESC(n)))
- #define ENABLED_GENSHELL_OPT(n) (! DISABLED_OPT(& GENSHELL_DESC(n)))
- #define STACKCT_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->useCt)
- #define STACKLST_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->apzArgs)
- #define CLEAR_GENSHELL_OPT(n) STMTS( \
- GENSHELL_DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \
- if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \
- GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \
- GENSHELL_DESC(n).optCookie = NULL )
- typedef enum {
- GENSHELLOPT_EXIT_SUCCESS = 0,
- GENSHELLOPT_EXIT_FAILURE = 1,
- GENSHELLOPT_EXIT_USAGE_ERROR = 64,
- GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70
- } genshellopt_exit_code_t;
- #define VALUE_GENSHELL_OPT_SCRIPT 'o'
- #define VALUE_GENSHELL_OPT_SHELL 's'
- #define VALUE_GENSHELL_OPT_HELP '?'
- #define VALUE_GENSHELL_OPT_MORE_HELP '!'
- #define VALUE_GENSHELL_OPT_VERSION 'v'
- #define ERRSKIP_GENSHELL_OPTERR STMTS(genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP)
- #define ERRSTOP_GENSHELL_OPTERR STMTS(genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP)
- #define RESTART_GENSHELL_OPT(n) STMTS( \
- genshelloptOptions.curOptIdx = (n); \
- genshelloptOptions.pzCurOpt = NULL )
- #define START_GENSHELL_OPT RESTART_GENSHELL_OPT(1)
- #define GENSHELL_USAGE(c) (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define ch_t unsigned char
- #define cc_t const unsigned char
- #define cch_t char const
- extern tOptions genshelloptOptions;
- #if defined(ENABLE_NLS)
- # ifndef _
- # include <stdio.h>
- # ifndef HAVE_GETTEXT
- extern char * gettext(char const *);
- # else
- # include <libintl.h>
- # endif
- # ifndef ATTRIBUTE_FORMAT_ARG
- # define ATTRIBUTE_FORMAT_ARG(_a)
- # endif
- static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
- static inline char* aoGetsText(char const* pz) {
- if (pz == NULL) return NULL;
- return (char*)gettext(pz);
- }
- # define _(s) aoGetsText(s)
- # endif
- # define OPT_NO_XLAT_CFG_NAMES STMTS(genshelloptOptions.fOptSet |= \
- OPTPROC_NXLAT_OPT_CFG;)
- # define OPT_NO_XLAT_OPT_NAMES STMTS(genshelloptOptions.fOptSet |= \
- OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
- # define OPT_XLAT_CFG_NAMES STMTS(genshelloptOptions.fOptSet &= \
- ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
- # define OPT_XLAT_OPT_NAMES STMTS(genshelloptOptions.fOptSet &= \
- ~OPTPROC_NXLAT_OPT;)
- #else
- # define OPT_NO_XLAT_CFG_NAMES
- # define OPT_NO_XLAT_OPT_NAMES
- # define OPT_XLAT_CFG_NAMES
- # define OPT_XLAT_OPT_NAMES
- # ifndef _
- # define _(_s) _s
- # endif
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|