| version 1.26, 2002/04/04 17:10:58 |
version 1.27, 2002/04/05 03:31:21 |
| Line 110 enum cfg_error { |
|
| Line 110 enum cfg_error { |
|
| * |
* |
| * By default are @ref CFG_SKIP_FIRST, @ref CFG_POSIXLY_LEFTOVERS and |
* By default are @ref CFG_SKIP_FIRST, @ref CFG_POSIXLY_LEFTOVERS and |
| * @ref CFG_NORMAL_LEFTOVERS initialized. |
* @ref CFG_NORMAL_LEFTOVERS initialized. |
| |
* @todo CFG_APPEND, CFG_OVERWRITE, CFG_APPEND_MULTI_ONLY |
| */ |
*/ |
| enum cfg_flag { |
enum cfg_flag { |
| |
|
|
|
| CFG_NORMAL_LEFTOVERS = 0, |
CFG_NORMAL_LEFTOVERS = 0, |
| |
|
| /** Strict leftover arguments initialization in file. */ |
/** Strict leftover arguments initialization in file. */ |
| CFG_STRICT_LEFTOVERS = 16 |
CFG_STRICT_LEFTOVERS = 16, |
| |
|
| |
/* Ignore all quotations in options arguments. */ |
| |
/* |
| |
CFG_USE_QUOTE = 0, |
| |
CFG_IGNORE_QUOTE = 16 |
| |
*/ |
| |
/* Advanced quotations are things like option = va"'l'"ue |
| |
which resolves to va'l'ue. |
| |
|
| |
We really want this strange stuff? Any volunter? |
| |
|
| |
CFG_ADVANCED_QUOTE = 32 + 16 |
| |
*/ |
| |
|
| /* Ignore all quotations in options arguments. */ |
|
| /* |
|
| CFG_USE_QUOTE = 0, |
|
| CFG_IGNORE_QUOTE = 16 |
|
| */ |
|
| /* Advanced quotations are things like option = va"'l'"ue |
|
| which resolves to va'l'ue. |
|
| |
|
| We really want this strange stuff? Any volunter? |
|
| |
|
| CFG_ADVANCED_QUOTE = 32 + 16 |
|
| */ |
|
| |
|
| /* TODO: |
|
| CFG_APPEND, |
|
| CFG_OVERWRITE, |
|
| CFG_APPEND_MULTI_ONLY |
|
| */ |
|
| }; |
}; |
| |
|
| |
/** |
| |
* Option types |
| |
* |
| |
* Possible types of options |
| |
* @todo Thinking about case insensitivy of option |
| |
* ("--input" is the same as "--INPUT") |
| |
*/ |
| enum cfg_option_type { |
enum cfg_option_type { |
| |
|
| /* Boolean. */ |
/** Boolean */ |
| CFG_BOOL = 1, |
CFG_BOOL = 1, |
| CFG_BOOLEAN = 1, |
CFG_BOOLEAN = 1, |
| |
|
| /* Integer. */ |
/** Integer */ |
| CFG_INT = 2, |
CFG_INT = 2, |
| CFG_INTEGER = 2, |
CFG_INTEGER = 2, |
| |
|
| /* Unsigned int. */ |
/** Unsigned int */ |
| CFG_UINT = 3, |
CFG_UINT = 3, |
| CFG_UNSIGNED = 3, |
CFG_UNSIGNED = 3, |
| CFG_UNSIGNED_INT = 3, |
CFG_UNSIGNED_INT = 3, |
| |
|
| /* Long. */ |
/** Long */ |
| CFG_LONG = 4, |
CFG_LONG = 4, |
| |
|
| /* Unsigned long. */ |
/** Unsigned long */ |
| CFG_ULONG = 5, |
CFG_ULONG = 5, |
| CFG_UNSIGNED_LONG = 5, |
CFG_UNSIGNED_LONG = 5, |
| |
|
| /* Float. */ |
/** Float */ |
| CFG_FLOAT = 6, |
CFG_FLOAT = 6, |
| |
|
| /* Double. */ |
/** Double */ |
| CFG_DOUBLE = 7, |
CFG_DOUBLE = 7, |
| |
|
| /* String. */ |
/** String */ |
| CFG_STR = 8, |
CFG_STR = 8, |
| CFG_STRING = 8, |
CFG_STRING = 8, |
| |
|
| /* End (to mark last item in list). */ |
/** End (to mark last item in list) */ |
| CFG_END = 0, |
CFG_END = 0, |
| |
|
| /* Data type mask. */ |
/** Data type mask (used internally) */ |
| CFG_DATA_TYPE_MASK = 31, |
CFG_DATA_TYPE_MASK = 31, |
| |
|
| /* Single, multi or multi separated. Single by default. */ |
/** |
| /* Tells if option can be repeated. */ |
* Single, multi or multi separated. Single by default. |
| /* In multi case value is array of poiters to type ended with NULL. */ |
* Tells if option can be repeated. |
| |
* In multi case value is array of poiters to type ended with NULL. |
| |
*/ |
| CFG_SINGLE = 0, |
CFG_SINGLE = 0, |
| CFG_MULTI = 32, |
CFG_MULTI = 32, |
| CFG_MULTI_ARRAY = 32, |
CFG_MULTI_ARRAY = 32, |
| CFG_MULTI_SEPARATED = 32 + 64, |
CFG_MULTI_SEPARATED = 32 + 64, |
| |
|
| /* Leftover arguments specification. */ |
/** |
| /* Mark option which will contain leftover arguments. */ |
* Leftover arguments specification. |
| |
* Mark option which will contain leftover arguments. |
| |
*/ |
| CFG_LAST_ARGS = 128, |
CFG_LAST_ARGS = 128, |
| CFG_LAST_ARGUMENTS = 128, |
CFG_LAST_ARGUMENTS = 128, |
| CFG_LEFTOVER_ARGS = 128, |
CFG_LEFTOVER_ARGS = 128, |
| CFG_LEFTOVER_ARGUMENTS = 128 |
CFG_LEFTOVER_ARGUMENTS = 128 |
| |
|
| /* TODO: Thinking about case insensitivy of option. |
|
| (--input, --INPUT) */ |
|
| |
|
| }; |
}; |
| |
|
| |
/** |
| |
* Context type |
| |
* |
| |
* Possible types of context (used internally) |
| |
*/ |
| enum cfg_context_type { |
enum cfg_context_type { |
| |
|
| /* No context. */ |
/** No context */ |
| CFG_NO_CONTEXT = 0, |
CFG_NO_CONTEXT = 0, |
| |
|
| /* Command line context type. */ |
/** Command line context type */ |
| CFG_CMDLINE = 1, |
CFG_CMDLINE = 1, |
| CFG_LINE = 1, |
CFG_LINE = 1, |
| |
|
| /* Config file context type. */ |
/** Config file context type */ |
| CFG_CFGFILE = 2, |
CFG_CFGFILE = 2, |
| CFG_FILE = 2 |
CFG_FILE = 2 |
| }; |
}; |
| |
|
| |
/** |
| |
* Command line option type. |
| |
* |
| |
* Possible types of command line option (used internally) |
| |
*/ |
| enum cfg_line_option_type { |
enum cfg_line_option_type { |
| |
|
| /* Not long and not short option. */ |
/** Not long and not short option */ |
| CFG_NONE_OPTION = 0, |
CFG_NONE_OPTION = 0, |
| |
|
| /* Short command line option. */ |
/** Short command line option */ |
| CFG_SHORT_OPTION = 1, |
CFG_SHORT_OPTION = 1, |
| |
|
| /* Long command line option. */ |
/** Long command line option */ |
| CFG_LONG_OPTION = 2, |
CFG_LONG_OPTION = 2, |
| |
|
| /* Short command line options. */ |
/** Short command line options */ |
| CFG_SHORT_OPTIONS = 4, |
CFG_SHORT_OPTIONS = 4, |
| |
|
| /* Long command line option argument initialized with separator. */ |
/** Long command line option argument initialized with separator */ |
| CFG_LONG_SEPINIT = 8, |
CFG_LONG_SEPINIT = 8, |
| |
|
| |
/** Long command line option argument initialized without separator (default) */ |
| CFG_LONG_NOSEPINIT = 0 |
CFG_LONG_NOSEPINIT = 0 |
| }; |
}; |
| |
|
| |
/** |
| |
* @brief Structure for defining one config option |
| |
*/ |
| struct cfg_option { |
struct cfg_option { |
| |
/** Command line long name (may be NULL) */ |
| const char *cmdline_long_name; |
const char *cmdline_long_name; |
| |
/** Command line short name (may be '\0') */ |
| const char cmdline_short_name; |
const char cmdline_short_name; |
| |
/** Config file name (may be NULL) */ |
| const char *cfgfile_name; |
const char *cfgfile_name; |
| |
|
| |
/** Option type |
| |
@see cfg_option_type */ |
| const enum cfg_option_type type; |
const enum cfg_option_type type; |
| |
|
| |
/** Value */ |
| void *value; |
void *value; |
| |
|
| |
/** Return value (set to 0 for not return) */ |
| int val; |
int val; |
| }; |
}; |
| |
|
| |
/** |
| |
* @brief Main structure for defining context |
| |
*/ |
| struct cfg_context { |
struct cfg_context { |
| |
|
| /* |
/** |
| * Shared properties. |
* @name Shared properties |
| */ |
*/ |
| |
/*@{*/ |
| |
|
| /* Context type (command line or config file). */ |
/** Context type (command line or config file) */ |
| enum cfg_context_type type; |
enum cfg_context_type type; |
| |
|
| /* Flags. */ |
/** Flags */ |
| int flags; |
int flags; |
| |
|
| /* Options table. */ |
/** Options table */ |
| const struct cfg_option *options; |
const struct cfg_option *options; |
| |
|
| /* Quote prefix & postfix. */ |
/** Quote prefix & postfix */ |
| char **quote_prefix; |
char **quote_prefix; |
| char **quote_postfix; |
char **quote_postfix; |
| |
|
| /* |
/*@}*/ |
| * Command line specific properties. |
|
| |
/** |
| |
* @name Command line specific properties |
| */ |
*/ |
| |
/*@{*/ |
| |
|
| int argc; |
int argc; |
| char **argv; |
char **argv; |
| Line 297 struct cfg_context { |
|
| Line 330 struct cfg_context { |
|
| /* Array of strings which forces to stop command line parsing. */ |
/* Array of strings which forces to stop command line parsing. */ |
| char **line_stop_str; |
char **line_stop_str; |
| |
|
| /* Prefixes and option argument separator. */ |
/** default: "-" */ |
| char **short_option_prefix; /* default: "-" */ |
char **short_option_prefix; |
| char **long_option_prefix; /* default: "--" */ |
/** default: "--" */ |
| char **line_option_arg_separator; /* default: "=" */ |
char **long_option_prefix; |
| |
/** default: "=" */ |
| |
char **line_option_arg_separator; |
| |
|
| /* Multi values separator. */ |
/** Multi values separator. */ |
| char **line_multi_vals_separator; |
char **line_multi_vals_separator; |
| |
|
| /* |
/*@}*/ |
| * Config file specific properties. |
|
| |
/** |
| |
* @name Config file specific properties. |
| */ |
*/ |
| |
/*@{*/ |
| |
|
| long begin_pos; |
long begin_pos; |
| long end_pos; |
long end_pos; |
| Line 315 struct cfg_context { |
|
| Line 353 struct cfg_context { |
|
| |
|
| FILE *fhandle; |
FILE *fhandle; |
| |
|
| /* Array of strings prefixes which forces to stop config file parsing. */ |
/** Array of strings prefixes which forces to stop config file parsing. |
| char **file_stop_prefix; /* default: "[" */ |
default: "[" */ |
| |
char **file_stop_prefix; |
| |
|
| |
/** Array of string prefixes which mark comment line. |
| |
defaults: "#", ";" */ |
| |
char **comment_prefix; |
| |
|
| /* Array of string prefixes which mark comment line. */ |
/** Array of string postfixes to determine multi lines. */ |
| char **comment_prefix; /* defaults: "#", ";" */ |
|
| |
|
| /* Array of string postfixes to determine multi lines. */ |
|
| char **multi_line_postfix; |
char **multi_line_postfix; |
| |
|
| /* Option argument separator. */ |
/** Option argument separator. |
| char **file_option_arg_separator; /* default: "=" */ |
default: "=" */ |
| |
char **file_option_arg_separator; |
| |
|
| /* Multi values separator. */ |
/** Multi values separator. */ |
| char **file_multi_vals_separator; |
char **file_multi_vals_separator; |
| |
|
| |
/*@}*/ |
| }; |
}; |
| |
|
| |
/** |
| |
* @brief Context data type |
| |
*/ |
| typedef struct cfg_context * CFG_CONTEXT; |
typedef struct cfg_context * CFG_CONTEXT; |
| |
|
| /* |
/* |