1 2/* 3 * Time-stamp: "2008-11-01 20:08:06 bkorb" 4 * 5 * autoopts.h $Id: d5e30331d37ca10ec88c592d24d8615dd6c1f0ee $ 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-2009 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 82typedef 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 * Procedure success codes 92 * 93 * USAGE: define procedures to return "tSuccess". Test their results 94 * with the SUCCEEDED, FAILED and HADGLITCH macros. 95 * 96 * Microsoft sticks its nose into user space here, so for Windows' sake, 97 * make sure all of these are undefined. 98 */ 99#undef SUCCESS 100#undef FAILURE 101#undef PROBLEM 102#undef SUCCEEDED 103#undef SUCCESSFUL 104#undef FAILED 105#undef HADGLITCH 106 107#define SUCCESS ((tSuccess) 0) 108#define FAILURE ((tSuccess)-1) 109#define PROBLEM ((tSuccess) 1) 110 111typedef int tSuccess; 112 113#define SUCCEEDED( p ) ((p) == SUCCESS) 114#define SUCCESSFUL( p ) SUCCEEDED( p ) 115#define FAILED( p ) ((p) < SUCCESS) 116#define HADGLITCH( p ) ((p) > SUCCESS) 117 118/* 119 * When loading a line (or block) of text as an option, the value can 120 * be processed in any of several modes: 121 * 122 * @table @samp 123 * @item keep 124 * Every part of the value between the delimiters is saved. 125 * 126 * @item uncooked 127 * Even if the value begins with quote characters, do not do quote processing. 128 * 129 * @item cooked 130 * If the value looks like a quoted string, then process it. 131 * Double quoted strings are processed the way strings are in "C" programs, 132 * except they are treated as regular characters if the following character 133 * is not a well-established escape sequence. 134 * Single quoted strings (quoted with apostrophies) are handled the way 135 * strings are handled in shell scripts, *except* that backslash escapes 136 * are honored before backslash escapes and apostrophies. 137 * @end table 138 */ 139typedef enum { 140 OPTION_LOAD_COOKED, 141 OPTION_LOAD_UNCOOKED, 142 OPTION_LOAD_KEEP 143} tOptionLoadMode; 144 145extern tOptionLoadMode option_load_mode; 146 147/* 148 * The pager state is used by optionPagedUsage() procedure. 149 * When it runs, it sets itself up to be called again on exit. 150 * If, however, a routine needs a child process to do some work 151 * before it is done, then 'pagerState' must be set to 152 * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try 153 * to run the pager program before its time. 154 */ 155typedef enum { 156 PAGER_STATE_INITIAL, 157 PAGER_STATE_READY, 158 PAGER_STATE_CHILD 159} tePagerState; 160 161extern tePagerState pagerState; 162 163typedef enum { 164 ENV_ALL, 165 ENV_IMM, 166 ENV_NON_IMM 167} teEnvPresetType; 168 169typedef enum { 170 TOPT_UNDEFINED = 0, 171 TOPT_SHORT, 172 TOPT_LONG, 173 TOPT_DEFAULT 174} teOptType; 175 176typedef struct { 177 tOptDesc* pOD; 178 tCC* pzOptArg; 179 tAoUL flags; 180 teOptType optType; 181} tOptState; 182#define OPTSTATE_INITIALIZER(st) \ 183 { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED } 184 185#define TEXTTO_TABLE \ 186 _TT_( LONGUSAGE ) \ 187 _TT_( USAGE ) \ 188 _TT_( VERSION ) 189#define _TT_(n) \ 190 TT_ ## n , 191 192typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo; 193 194#undef _TT_ 195 196typedef struct { 197 tCC* pzStr; 198 tCC* pzReq; 199 tCC* pzNum; 200 tCC* pzFile; 201 tCC* pzKey; 202 tCC* pzKeyL; 203 tCC* pzBool; 204 tCC* pzNest; 205 tCC* pzOpt; 206 tCC* pzNo; 207 tCC* pzBrk; 208 tCC* pzNoF; 209 tCC* pzSpc; 210 tCC* pzOptFmt; 211 tCC* pzTime; 212} arg_types_t; 213 214#define AGALOC( c, w ) ao_malloc((size_t)c) 215#define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c) 216#define AGFREE(_p) do{void*X=(void*)_p;ao_free(X);}while(0) 217#define AGDUPSTR( p, s, w ) (p = ao_strdup(s)) 218 219static void * 220ao_malloc( size_t sz ); 221 222static void * 223ao_realloc( void *p, size_t sz ); 224 225static void 226ao_free( void *p ); 227 228static char * 229ao_strdup( char const *str ); 230 231#define TAGMEM( m, t ) 232 233/* 234 * DO option handling? 235 * 236 * Options are examined at two times: at immediate handling time and at 237 * normal handling time. If an option is disabled, the timing may be 238 * different from the handling of the undisabled option. The OPTST_DIABLED 239 * bit indicates the state of the currently discovered option. 240 * So, here's how it works: 241 * 242 * A) handling at "immediate" time, either 1 or 2: 243 * 244 * 1. OPTST_DISABLED is not set: 245 * IMM must be set 246 * DISABLE_IMM don't care 247 * TWICE don't care 248 * DISABLE_TWICE don't care 249 * 0 -and- 1 x x x 250 * 251 * 2. OPTST_DISABLED is set: 252 * IMM don't care 253 * DISABLE_IMM must be set 254 * TWICE don't care 255 * DISABLE_TWICE don't care 256 * 1 -and- x 1 x x 257 */ 258#define DO_IMMEDIATELY(_flg) \ 259 ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \ 260 || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \ 261 == (OPTST_DISABLED|OPTST_DISABLE_IMM) )) 262 263/* B) handling at "regular" time because it was not immediate 264 * 265 * 1. OPTST_DISABLED is not set: 266 * IMM must *NOT* be set 267 * DISABLE_IMM don't care 268 * TWICE don't care 269 * DISABLE_TWICE don't care 270 * 0 -and- 0 x x x 271 * 272 * 2. OPTST_DISABLED is set: 273 * IMM don't care 274 * DISABLE_IMM don't care 275 * TWICE must be set 276 * DISABLE_TWICE don't care 277 * 1 -and- x x 1 x 278 */ 279#define DO_NORMALLY(_flg) ( \ 280 (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \ 281 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \ 282 OPTST_DISABLED) ) 283 284/* C) handling at "regular" time because it is to be handled twice. 285 * The immediate bit was already tested and found to be set: 286 * 287 * 3. OPTST_DISABLED is not set: 288 * IMM is set (but don't care) 289 * DISABLE_IMM don't care 290 * TWICE must be set 291 * DISABLE_TWICE don't care 292 * 0 -and- ? x 1 x 293 * 294 * 4. OPTST_DISABLED is set: 295 * IMM don't care 296 * DISABLE_IMM is set (but don't care) 297 * TWICE don't care 298 * DISABLE_TWICE must be set 299 * 1 -and- x ? x 1 300 */ 301#define DO_SECOND_TIME(_flg) ( \ 302 (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \ 303 OPTST_TWICE) \ 304 || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \ 305 (OPTST_DISABLED|OPTST_DISABLE_TWICE) )) 306 307/* 308 * text_mmap structure. Only active on platforms with mmap(2). 309 */ 310#ifdef HAVE_SYS_MMAN_H 311# include <sys/mman.h> 312#else 313# ifndef PROT_READ 314# define PROT_READ 0x01 315# endif 316# ifndef PROT_WRITE 317# define PROT_WRITE 0x02 318# endif 319# ifndef MAP_SHARED 320# define MAP_SHARED 0x01 321# endif 322# ifndef MAP_PRIVATE 323# define MAP_PRIVATE 0x02 324# endif 325#endif 326 327#ifndef MAP_FAILED 328# define MAP_FAILED ((void*)-1) 329#endif 330 331#ifndef _SC_PAGESIZE 332# ifdef _SC_PAGE_SIZE 333# define _SC_PAGESIZE _SC_PAGE_SIZE 334# endif 335#endif 336 337#ifndef HAVE_STRCHR 338extern char* strchr( char const *s, int c); 339extern char* strrchr( char const *s, int c); 340#endif 341 342/* 343 * Define and initialize all the user visible strings. 344 * We do not do translations. If translations are to be done, then 345 * the client will provide a callback for that purpose. 346 */ 347#undef DO_TRANSLATIONS 348#include "autoopts/usage-txt.h" 349 350/* 351 * File pointer for usage output 352 */ 353extern FILE* option_usage_fp; 354 355extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt; 356 357#endif /* AUTOGEN_AUTOOPTS_H */ 358/* 359 * Local Variables: 360 * mode: C 361 * c-file-style: "stroustrup" 362 * indent-tabs-mode: nil 363 * End: 364 * end of autoopts/autoopts.h */ 365