Annotation of embedaddon/ntp/sntp/libopts/autoopts.h, revision 1.1.1.1

1.1       misho       1: 
                      2: /*
                      3:  *  \file autoopts.h
                      4:  *
                      5:  *  Time-stamp:      "2011-03-25 17:51:34 bkorb"
                      6:  *
                      7:  *  This file defines all the global structures and special values
                      8:  *  used in the automated option processing library.
                      9:  *
                     10:  *  This file is part of AutoOpts, a companion to AutoGen.
                     11:  *  AutoOpts is free software.
                     12:  *  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
                     13:  *
                     14:  *  AutoOpts is available under any one of two licenses.  The license
                     15:  *  in use must be one of these two and the choice is under the control
                     16:  *  of the user of the license.
                     17:  *
                     18:  *   The GNU Lesser General Public License, version 3 or later
                     19:  *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
                     20:  *
                     21:  *   The Modified Berkeley Software Distribution License
                     22:  *      See the file "COPYING.mbsd"
                     23:  *
                     24:  *  These files have the following md5sums:
                     25:  *
                     26:  *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
                     27:  *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
                     28:  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
                     29:  */
                     30: 
                     31: #ifndef AUTOGEN_AUTOOPTS_H
                     32: #define AUTOGEN_AUTOOPTS_H
                     33: 
                     34: #include "compat/compat.h"
                     35: #include "ag-char-map.h"
                     36: 
                     37: #define AO_NAME_LIMIT           127
                     38: #define AO_NAME_SIZE            ((size_t)(AO_NAME_LIMIT + 1))
                     39: 
                     40: #ifndef AG_PATH_MAX
                     41: #  ifdef PATH_MAX
                     42: #    define AG_PATH_MAX         ((size_t)PATH_MAX)
                     43: #  else
                     44: #    define AG_PATH_MAX         ((size_t)4096)
                     45: #  endif
                     46: #else
                     47: #  if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
                     48: #     undef  AG_PATH_MAX
                     49: #     define AG_PATH_MAX        ((size_t)PATH_MAX)
                     50: #  endif
                     51: #endif
                     52: 
                     53: #undef  EXPORT
                     54: #define EXPORT
                     55: 
                     56: #if defined(_WIN32) && !defined(__CYGWIN__)
                     57: # define DIRCH                  '\\'
                     58: #else
                     59: # define DIRCH                  '/'
                     60: #endif
                     61: 
                     62: #ifndef EX_NOINPUT
                     63: #  define EX_NOINPUT            66
                     64: #endif
                     65: #ifndef EX_SOFTWARE
                     66: #  define EX_SOFTWARE           70
                     67: #endif
                     68: #ifndef EX_CONFIG
                     69: #  define EX_CONFIG             78
                     70: #endif
                     71: 
                     72: /*
                     73:  *  Convert the number to a list usable in a printf call
                     74:  */
                     75: #define NUM_TO_VER(n)           ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
                     76: 
                     77: #define NAMED_OPTS(po) \
                     78:         (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
                     79: 
                     80: #define SKIP_OPT(p)  (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
                     81: 
                     82: typedef int tDirection;
                     83: #define DIRECTION_PRESET        -1
                     84: #define DIRECTION_PROCESS       1
                     85: #define DIRECTION_CALLED        0
                     86: 
                     87: #define PROCESSING(d)           ((d)>0)
                     88: #define PRESETTING(d)           ((d)<0)
                     89: 
                     90: /*
                     91:  *  When loading a line (or block) of text as an option, the value can
                     92:  *  be processed in any of several modes:
                     93:  *
                     94:  *  @table @samp
                     95:  *  @item keep
                     96:  *  Every part of the value between the delimiters is saved.
                     97:  *
                     98:  *  @item uncooked
                     99:  *  Even if the value begins with quote characters, do not do quote processing.
                    100:  *
                    101:  *  @item cooked
                    102:  *  If the value looks like a quoted string, then process it.
                    103:  *  Double quoted strings are processed the way strings are in "C" programs,
                    104:  *  except they are treated as regular characters if the following character
                    105:  *  is not a well-established escape sequence.
                    106:  *  Single quoted strings (quoted with apostrophies) are handled the way
                    107:  *  strings are handled in shell scripts, *except* that backslash escapes
                    108:  *  are honored before backslash escapes and apostrophies.
                    109:  *  @end table
                    110:  */
                    111: typedef enum {
                    112:     OPTION_LOAD_COOKED,
                    113:     OPTION_LOAD_UNCOOKED,
                    114:     OPTION_LOAD_KEEP
                    115: } tOptionLoadMode;
                    116: 
                    117: static tOptionLoadMode option_load_mode;
                    118: 
                    119: /*
                    120:  *  The pager state is used by optionPagedUsage() procedure.
                    121:  *  When it runs, it sets itself up to be called again on exit.
                    122:  *  If, however, a routine needs a child process to do some work
                    123:  *  before it is done, then 'pagerState' must be set to
                    124:  *  'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
                    125:  *  to run the pager program before its time.
                    126:  */
                    127: typedef enum {
                    128:     PAGER_STATE_INITIAL,
                    129:     PAGER_STATE_READY,
                    130:     PAGER_STATE_CHILD
                    131: } tePagerState;
                    132: 
                    133: typedef enum {
                    134:     ENV_ALL,
                    135:     ENV_IMM,
                    136:     ENV_NON_IMM
                    137: } teEnvPresetType;
                    138: 
                    139: typedef enum {
                    140:     TOPT_UNDEFINED = 0,
                    141:     TOPT_SHORT,
                    142:     TOPT_LONG,
                    143:     TOPT_DEFAULT
                    144: } teOptType;
                    145: 
                    146: typedef struct {
                    147:     tOptDesc*  pOD;
                    148:     tCC*       pzOptArg;
                    149:     tAoUL      flags;
                    150:     teOptType  optType;
                    151: } tOptState;
                    152: #define OPTSTATE_INITIALIZER(st) \
                    153:     { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
                    154: 
                    155: #define TEXTTO_TABLE \
                    156:         _TT_(LONGUSAGE) \
                    157:         _TT_(USAGE) \
                    158:         _TT_(VERSION)
                    159: #define _TT_(n) \
                    160:         TT_ ## n ,
                    161: 
                    162: typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
                    163: 
                    164: #undef _TT_
                    165: 
                    166: typedef struct {
                    167:     char const * pzStr;
                    168:     char const * pzReq;
                    169:     char const * pzNum;
                    170:     char const * pzFile;
                    171:     char const * pzKey;
                    172:     char const * pzKeyL;
                    173:     char const * pzBool;
                    174:     char const * pzNest;
                    175:     char const * pzOpt;
                    176:     char const * pzNo;
                    177:     char const * pzBrk;
                    178:     char const * pzNoF;
                    179:     char const * pzSpc;
                    180:     char const * pzOptFmt;
                    181:     char const * pzTime;
                    182: } arg_types_t;
                    183: 
                    184: #define AGALOC(c, w)          ao_malloc((size_t)c)
                    185: #define AGREALOC(p, c, w)     ao_realloc((void*)p, (size_t)c)
                    186: #define AGFREE(_p)            free((void *)_p)
                    187: #define AGDUPSTR(p, s, w)     (p = ao_strdup(s))
                    188: 
                    189: static void *
                    190: ao_malloc(size_t sz);
                    191: 
                    192: static void *
                    193: ao_realloc(void *p, size_t sz);
                    194: 
                    195: #define ao_free(_p) free((void *)_p)
                    196: 
                    197: static char *
                    198: ao_strdup(char const *str);
                    199: 
                    200: #define TAGMEM(m, t)
                    201: 
                    202: /*
                    203:  *  DO option handling?
                    204:  *
                    205:  *  Options are examined at two times:  at immediate handling time and at
                    206:  *  normal handling time.  If an option is disabled, the timing may be
                    207:  *  different from the handling of the undisabled option.  The OPTST_DIABLED
                    208:  *  bit indicates the state of the currently discovered option.
                    209:  *  So, here's how it works:
                    210:  *
                    211:  *  A) handling at "immediate" time, either 1 or 2:
                    212:  *
                    213:  *  1.  OPTST_DISABLED is not set:
                    214:  *      IMM           must be set
                    215:  *      DISABLE_IMM   don't care
                    216:  *      TWICE         don't care
                    217:  *      DISABLE_TWICE don't care
                    218:  *      0 -and-  1 x x x
                    219:  *
                    220:  *  2.  OPTST_DISABLED is set:
                    221:  *      IMM           don't care
                    222:  *      DISABLE_IMM   must be set
                    223:  *      TWICE         don't care
                    224:  *      DISABLE_TWICE don't care
                    225:  *      1 -and-  x 1 x x
                    226:  */
                    227: #define DO_IMMEDIATELY(_flg) \
                    228:     (  (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
                    229:     || (   ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM))    \
                    230:         == (OPTST_DISABLED|OPTST_DISABLE_IMM)  ))
                    231: 
                    232: /*  B) handling at "regular" time because it was not immediate
                    233:  *
                    234:  *  1.  OPTST_DISABLED is not set:
                    235:  *      IMM           must *NOT* be set
                    236:  *      DISABLE_IMM   don't care
                    237:  *      TWICE         don't care
                    238:  *      DISABLE_TWICE don't care
                    239:  *      0 -and-  0 x x x
                    240:  *
                    241:  *  2.  OPTST_DISABLED is set:
                    242:  *      IMM           don't care
                    243:  *      DISABLE_IMM   don't care
                    244:  *      TWICE         must be set
                    245:  *      DISABLE_TWICE don't care
                    246:  *      1 -and-  x x 1 x
                    247:  */
                    248: #define DO_NORMALLY(_flg) ( \
                    249:        (((_flg) & (OPTST_DISABLED|OPTST_IMM))            == 0)  \
                    250:     || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM))    ==     \
                    251:                   OPTST_DISABLED)  )
                    252: 
                    253: /*  C)  handling at "regular" time because it is to be handled twice.
                    254:  *      The immediate bit was already tested and found to be set:
                    255:  *
                    256:  *  3.  OPTST_DISABLED is not set:
                    257:  *      IMM           is set (but don't care)
                    258:  *      DISABLE_IMM   don't care
                    259:  *      TWICE         must be set
                    260:  *      DISABLE_TWICE don't care
                    261:  *      0 -and-  ? x 1 x
                    262:  *
                    263:  *  4.  OPTST_DISABLED is set:
                    264:  *      IMM           don't care
                    265:  *      DISABLE_IMM   is set (but don't care)
                    266:  *      TWICE         don't care
                    267:  *      DISABLE_TWICE must be set
                    268:  *      1 -and-  x ? x 1
                    269:  */
                    270: #define DO_SECOND_TIME(_flg) ( \
                    271:        (((_flg) & (OPTST_DISABLED|OPTST_TWICE))          ==     \
                    272:                   OPTST_TWICE)                                  \
                    273:     || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE))  ==     \
                    274:                   (OPTST_DISABLED|OPTST_DISABLE_TWICE)  ))
                    275: 
                    276: /*
                    277:  *  text_mmap structure.  Only active on platforms with mmap(2).
                    278:  */
                    279: #ifdef HAVE_SYS_MMAN_H
                    280: #  include <sys/mman.h>
                    281: #else
                    282: #  ifndef  PROT_READ
                    283: #   define PROT_READ            0x01
                    284: #  endif
                    285: #  ifndef  PROT_WRITE
                    286: #   define PROT_WRITE           0x02
                    287: #  endif
                    288: #  ifndef  MAP_SHARED
                    289: #   define MAP_SHARED           0x01
                    290: #  endif
                    291: #  ifndef  MAP_PRIVATE
                    292: #   define MAP_PRIVATE          0x02
                    293: #  endif
                    294: #endif
                    295: 
                    296: #ifndef MAP_FAILED
                    297: #  define  MAP_FAILED           ((void*)-1)
                    298: #endif
                    299: 
                    300: #ifndef  _SC_PAGESIZE
                    301: # ifdef  _SC_PAGE_SIZE
                    302: #  define _SC_PAGESIZE          _SC_PAGE_SIZE
                    303: # endif
                    304: #endif
                    305: 
                    306: #ifndef HAVE_STRCHR
                    307: extern char* strchr(char const *s, int c);
                    308: extern char* strrchr(char const *s, int c);
                    309: #endif
                    310: 
                    311: /*
                    312:  *  Define and initialize all the user visible strings.
                    313:  *  We do not do translations.  If translations are to be done, then
                    314:  *  the client will provide a callback for that purpose.
                    315:  */
                    316: #undef DO_TRANSLATIONS
                    317: #include "autoopts/usage-txt.h"
                    318: 
                    319: /*
                    320:  *  File pointer for usage output
                    321:  */
                    322: FILE * option_usage_fp;
                    323: static char const * program_pkgdatadir;
                    324: 
                    325: extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
                    326: 
                    327: #endif /* AUTOGEN_AUTOOPTS_H */
                    328: /*
                    329:  * Local Variables:
                    330:  * mode: C
                    331:  * c-file-style: "stroustrup"
                    332:  * indent-tabs-mode: nil
                    333:  * End:
                    334:  * end of autoopts/autoopts.h */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>