/*
* \file autoopts.h
*
* This file defines all the global structures and special values
* used in the automated option processing library.
*
* @group autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
*
* AutoOpts is available under any one of two licenses. The license
* in use must be one of these two and the choice is under the control
* of the user of the license.
*
* The GNU Lesser General Public License, version 3 or later
* See the files "COPYING.lgplv3" and "COPYING.gplv3"
*
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following sha256 sums:
*
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifndef EX_USAGE
/**
* Command line usage problem
*/
# define EX_USAGE 64
#endif
#ifndef EX_DATAERR
/**
* The input data was incorrect in some way.
*/
# define EX_DATAERR 64
#endif
#ifndef EX_NOINPUT
/**
* option state was requested from a file that cannot be loaded.
*/
# define EX_NOINPUT 66
#endif
#ifndef EX_SOFTWARE
/**
* AutoOpts Software failure.
*/
# define EX_SOFTWARE 70
#endif
#ifndef EX_OSERR
/**
* Command line usage problem
*/
# define EX_OSERR 71
#endif
#define NL '\n'
#ifndef C
/**
* Coercive cast. Compel an address to be interpreted as the type
* of the first argument. No complaints, just do it.
*/
#define C(_t,_p) ((_t)VOIDP(_p))
#endif
/* The __attribute__((__warn_unused_result__)) feature
is available in gcc versions 3.4 and newer,
while the typeof feature has been available since 2.7 at least. */
# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
# define ignore_val(x) ((void) (x))
# else
# define ignore_val(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
# endif
/*
* Convert the number to a list usable in a printf call
*/
#define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
typedef int tDirection;
/**
* handling option presets. Start with command line and work through
* config settings in reverse order.
*/
#define DIRECTION_PRESET -1
/**
* handling normal options. Start with first config file, then environment
* variables and finally the command line.
*/
#define DIRECTION_PROCESS 1
/**
* An initialzation phase or an option being loaded from program sources.
*/
#define DIRECTION_CALLED 0
/**
* When loading a line (or block) of text as an option, the value can
* be processed in any of several modes.
*/
typedef enum {
/**
* If the value looks like a quoted string, then process it. Double
* quoted strings are processed the way strings are in "C" programs,
* except they are treated as regular characters if the following
* character is not a well-established escape sequence. Single quoted
* strings (quoted with apostrophies) are handled the way strings are
* handled in shell scripts, *except* that backslash escapes are
* honored before backslash escapes and apostrophies.
*/
OPTION_LOAD_COOKED,
/**
* Even if the value begins with quote characters, do not do quote
* processing. Strip leading and trailing white space.
*/
OPTION_LOAD_UNCOOKED,
/**
* Keep every part of the value between the delimiters.
*/
OPTION_LOAD_KEEP
} tOptionLoadMode;
static tOptionLoadMode option_load_mode;
/**
* The pager state is used by optionPagedUsage() procedure.
* When it runs, it sets itself up to be called again on exit.
* If, however, a routine needs a child process to do some work
* before it is done, then 'pagerState' must be set to
* 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
* to run the pager program before its time.
*/
typedef enum {
PAGER_STATE_INITIAL, //@< initial option paging state
/**
* temp file created and optionPagedUsage is scheduled to run at exit
*/
PAGER_STATE_READY,
/**
* This is a child process used in creating shell script usage.
*/
PAGER_STATE_CHILD
} tePagerState;
/**
* DO option handling?
*
* Options are examined at two times: at immediate handling time and at
* normal handling time. If an option is disabled, the timing may be
* different from the handling of the undisabled option. The OPTST_DIABLED
* bit indicates the state of the currently discovered option.
* So, here's how it works:
*
* A) handling at "immediate" time, either 1 or 2:
*
* 1. OPTST_DISABLED is not set:
* IMM must be set
* DISABLE_IMM don't care
* TWICE don't care
* DISABLE_TWICE don't care
* 0 -and- 1 x x x
*
* 2. OPTST_DISABLED is set:
* IMM don't care
* DISABLE_IMM must be set
* TWICE don't care
* DISABLE_TWICE don't care
* 1 -and- x 1 x x
*/
#define DO_IMMEDIATELY(_flg) \
( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
|| ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
== (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
/**
* B) handling at "regular" time because it was not immediate
*
* 1. OPTST_DISABLED is not set:
* IMM must *NOT* be set
* DISABLE_IMM don't care
* TWICE don't care
* DISABLE_TWICE don't care
* 0 -and- 0 x x x
*
* 2. OPTST_DISABLED is set:
* IMM don't care
* DISABLE_IMM don't care
* TWICE must be set
* DISABLE_TWICE don't care
* 1 -and- x x 1 x
*/
#define DO_NORMALLY(_flg) ( \
(((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
|| (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
OPTST_DISABLED) )
/**
* C) handling at "regular" time because it is to be handled twice.
* The immediate bit was already tested and found to be set:
*
* 3. OPTST_DISABLED is not set:
* IMM is set (but don't care)
* DISABLE_IMM don't care
* TWICE must be set
* DISABLE_TWICE don't care
* 0 -and- ? x 1 x
*
* 4. OPTST_DISABLED is set:
* IMM don't care
* DISABLE_IMM is set (but don't care)
* TWICE don't care
* DISABLE_TWICE must be set
* 1 -and- x ? x 1
*/
#define DO_SECOND_TIME(_flg) ( \
(((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
OPTST_TWICE) \
|| (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
(OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
/**
* INQUERY_CALL() tests whether the option handling function has been
* called by an inquery (help text needed, or option being reset),
* or called by a set-the-option operation.
*/
#define INQUERY_CALL(_o, _d) ( \
((_o) <= OPTPROC_EMIT_LIMIT) \
|| ((_d) == NULL) \
|| (((_d)->fOptState & OPTST_RESET) != 0) )
/**
* Define and initialize all the user visible strings.
* We do not do translations. If translations are to be done, then
* the client will provide a callback for that purpose.
*/
#undef DO_TRANSLATIONS
#include "autoopts/usage-txt.h"
/**
* File pointer for usage output
*/
FILE * option_usage_fp;
/**
* If provided in the option structure
*/
static char const * program_pkgdatadir;
/**
* privately exported functions
*/
extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;