| version 1.43, 2002/07/16 13:42:11 |
version 1.44, 2002/07/18 22:16:30 |
|
|
| * @file cfg+.h |
* @file cfg+.h |
| * @brief main implementation header file |
* @brief main implementation header file |
| * @author Ondrej Jombik <nepto@pobox.sk> |
* @author Ondrej Jombik <nepto@pobox.sk> |
| |
* @author Lubomir Host <rajo@host.sk> |
| * @version \$Id$ |
* @version \$Id$ |
| * @date 2001-2002 |
* @date 2001-2002 |
| */ |
*/ |
|
|
| /** |
/** |
| * Possible return values returned by parsing functions. |
* Possible return values returned by parsing functions. |
| */ |
*/ |
| enum cfg_error { |
enum cfg_error { /* {{{ */ |
| |
|
| /*@{*/ |
/*@{*/ |
| /** OK, all is right. */ |
/** OK, all is right. */ |
| Line 109 enum cfg_error { |
|
| Line 110 enum cfg_error { |
|
| CFG_ERR_INTERNAL = -20, |
CFG_ERR_INTERNAL = -20, |
| CFG_ERROR_INTERNAL = -20 |
CFG_ERROR_INTERNAL = -20 |
| |
|
| }; |
}; /* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| Line 121 enum cfg_error { |
|
| Line 122 enum cfg_error { |
|
| * @ref CFG_NORMAL_LEFTOVERS initialized. |
* @ref CFG_NORMAL_LEFTOVERS initialized. |
| * @todo CFG_APPEND, CFG_OVERWRITE, CFG_APPEND_MULTI_ONLY |
* @todo CFG_APPEND, CFG_OVERWRITE, CFG_APPEND_MULTI_ONLY |
| */ |
*/ |
| enum cfg_flag { |
enum cfg_flag { /* {{{ */ |
| |
|
| /** Ignore multiple arguments for single option. */ |
/** Ignore multiple arguments for single option. */ |
| CFG_IGNORE_MULTI = 1, |
CFG_IGNORE_MULTI = 1, |
|
|
| CFG_ADVANCED_QUOTE = 32 + 16 |
CFG_ADVANCED_QUOTE = 32 + 16 |
| */ |
*/ |
| |
|
| }; |
}; /* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
|
|
| * @todo Thinking about case insensitivy of option |
* @todo Thinking about case insensitivy of option |
| * ("--input" is the same as "--INPUT") |
* ("--input" is the same as "--INPUT") |
| */ |
*/ |
| enum cfg_option_type { |
enum cfg_option_type { /* {{{ */ |
| |
|
| /** Boolean */ |
/** Boolean */ |
| CFG_BOOL = 1, |
CFG_BOOL = 1, |
| Line 235 enum cfg_option_type { |
|
| Line 236 enum cfg_option_type { |
|
| CFG_LEFTOVER_ARGS = 128, |
CFG_LEFTOVER_ARGS = 128, |
| CFG_LEFTOVER_ARGUMENTS = 128 |
CFG_LEFTOVER_ARGUMENTS = 128 |
| |
|
| }; |
}; /* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| * @name Special properties types |
* @name Special properties types |
| */ |
*/ |
| /*@{*/ |
/*@{*/ |
| enum cfg_property_type { |
enum cfg_property_type { /* {{{ */ |
| |
|
| /** |
/** |
| * @name Special properties codes |
* @name Special properties codes |
| Line 332 enum cfg_property_type { |
|
| Line 333 enum cfg_property_type { |
|
| /* TODO: virtual properties */ |
/* TODO: virtual properties */ |
| CFG_VIRTUAL_SPECIAL_PROPERTY = 99 |
CFG_VIRTUAL_SPECIAL_PROPERTY = 99 |
| /*@}*/ |
/*@}*/ |
| }; |
}; /* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| Line 344 enum cfg_property_type { |
|
| Line 345 enum cfg_property_type { |
|
| * |
* |
| * Possible types of context (used internally) |
* 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, |
| Line 356 enum cfg_context_type { |
|
| Line 357 enum cfg_context_type { |
|
| /** Config file context type */ |
/** Config file context type */ |
| CFG_CFGFILE = 2, |
CFG_CFGFILE = 2, |
| CFG_FILE = 2 |
CFG_FILE = 2 |
| }; |
}; /* }}} */ |
| |
|
| /** |
/** |
| * Command line option type. |
* Command line option type. |
| * |
* |
| * Possible types of command line option (used internally) |
* 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, |
| Line 382 enum cfg_line_option_type { |
|
| Line 383 enum cfg_line_option_type { |
|
| |
|
| /** Long command line option argument initialized without separator (default) */ |
/** Long command line option argument initialized without separator (default) */ |
| CFG_LONG_NOSEPINIT = 0 |
CFG_LONG_NOSEPINIT = 0 |
| }; |
}; /* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| * @brief Structure for defining one config option |
* @brief Structure for defining one config option |
| */ |
*/ |
| struct cfg_option { |
struct cfg_option { /* {{{ */ |
| /** Command line long name (may be NULL) */ |
/** Command line long name (may be NULL) */ |
| const char *cmdline_long_name; |
const char *cmdline_long_name; |
| /** Command line short name (may be '\0') */ |
/** Command line short name (may be '\0') */ |
| Line 405 struct cfg_option { |
|
| Line 406 struct cfg_option { |
|
| |
|
| /** Return value (set to 0 for not return) */ |
/** Return value (set to 0 for not return) */ |
| int val; |
int val; |
| }; |
}; /* }}} */ |
| |
|
| /** |
/** |
| * @brief Main structure for defining context |
* @brief Main structure for defining context |
| */ |
*/ |
| struct cfg_context { |
struct cfg_context { /* {{{ */ |
| |
|
| /** |
/** |
| * @name Shared properties |
* @name Shared properties |
| Line 480 struct cfg_context { |
|
| Line 481 struct cfg_context { |
|
| FILE *fhandle; |
FILE *fhandle; |
| |
|
| /*@}*/ |
/*@}*/ |
| }; |
}; /* }}} */ |
| |
|
| /** |
/** |
| * @brief Context data type |
* @brief Context data type |
|
|
| #endif |
#endif |
| |
|
| /** |
/** |
| * @name Functions for creating and manipulating context |
* @name Functions and macros for creating and manipulating context |
| */ |
*/ |
| /*@{*/ |
/*@{*/ |
| |
/* {{{ */ |
| |
|
| /** |
/** |
| * Initialize core context |
* Initialize core context |
|
|
| char **argv, |
char **argv, |
| struct cfg_option *options); |
struct cfg_option *options); |
| |
|
| /* this must be function */ |
#define cfg_get_cmdline_context_pos(begin_pos, end_pos, argv, options) \ |
| #if 0 |
cfg_get_cmdline_context( \ |
| #define cfg_get_cmdline_context_by_argc(argc, argv, options) \ |
begin_pos, \ |
| do { \ |
end_pos - begin_pos + 1, \ |
| cfg_set_context_flag( |
argv, \ |
| cfg_get_cmdline_context(0, argc - 1, argv, options) \ |
options) |
| } while (0) |
|
| #endif |
|
| |
|
| /** |
/** |
| * Initialize configuration file context |
* Initialize command line context by argc and argv passed to main() |
| * |
* |
| * @param begin_pos starting position in file to parse |
* @param argc argumet count (argc) passed to function main() |
| * @param size maximal number of bytes/lines in file to parse |
* @param argv arguments array (argv) passed to function main() |
| * (set value of -1 for infinite) |
|
| * @param filename parsed filename |
|
| * @param options pointer to options table |
* @param options pointer to options table |
| * @return initialized command line context |
* @return initialized command line context |
| */ |
*/ |
| CFG_CONTEXT cfg_get_cfgfile_context( |
CFG_CONTEXT cfg_get_cmdline_context_argc( |
| long begin_pos, |
int argc, |
| long size, |
char **argv, |
| char *filename, |
|
| struct cfg_option *options); |
struct cfg_option *options); |
| |
|
| /** |
/** |
| * Set context to command line |
* Initialize configuration file context |
| * |
* |
| * @param con initialized context |
* @param begin_pos starting position in file to parse |
| * @param begin_pos index of beginning argument of arguments array |
* @param size maximal number of bytes/lines in file to parse |
| * @param size maximal number of array elements to parse |
|
| * (set value of -1 for infinite) |
* (set value of -1 for infinite) |
| * @param argv arguments array |
* @param filename parsed filename |
| * @return void |
* @param options pointer to options table |
| |
* @return initialized command line context |
| */ |
*/ |
| void cfg_set_cmdline_context( |
CFG_CONTEXT cfg_get_cfgfile_context( |
| const CFG_CONTEXT con, |
|
| long begin_pos, |
long begin_pos, |
| long size, |
long size, |
| char **argv); |
char *filename, |
| |
struct cfg_option *options); |
| |
|
| #define cfg_set_cmdline_context_by_argc(con, argc, argv) \ |
#define cfg_get_cfgfile_context_pos(begin_pos, end_pos, argv, options) \ |
| cfg_set_cmdline_context(con, 0, argc - 1, argv) |
cfg_get_cfgfile_context( \ |
| |
begin_pos, \ |
| |
end_pos - begin_pos + 1, \ |
| |
argv, \ |
| |
options) |
| |
|
| /** |
/** |
| * Set context to configuration file |
* Set context to command line |
| * |
* |
| * @param con initialized context |
* @param con initialized context |
| * @param begin_pos starting position in file to parse |
* @param begin_pos index of beginning argument of arguments array |
| * @param size maximal number of bytes/lines in file to parse |
* @param size maximal number of array elements to parse |
| * (set value of -1 for infinite) |
* (set value of -1 for infinite) |
| * @param filename parsed filename |
* @param argv arguments array |
| * @return void |
* @return void |
| */ |
*/ |
| void cfg_set_cfgfile_context( |
void cfg_set_cmdline_context( |
| const CFG_CONTEXT con, |
const CFG_CONTEXT con, |
| long begin_pos, |
long begin_pos, |
| long size, |
long size, |
| char *filename); |
char **argv); |
| |
|
| |
#define cfg_set_cmdline_context_pos(con, begin_pos, end_pos, argv) \ |
| |
cfg_get_cmdline_context( \ |
| |
con \ |
| |
begin_pos, \ |
| |
end_pos - begin_pos + 1, \ |
| |
argv) |
| |
|
| |
/** |
| |
* Set context to command line by argc and argv passed to main() |
| |
* |
| |
* @param con initialized context |
| |
* @param argc argumet count (argc) passed to function main() |
| |
* @param argv arguments array (argv) passed to function main() |
| |
* @return initialized command line context |
| |
*/ |
| |
void cfg_set_cmdline_context_argc( |
| |
const CFG_CONTEXT con, |
| |
int argc, |
| |
char **argv); |
| |
|
| /** |
/** |
| * Reinitialize popt context |
* Set context to configuration file |
| * |
* |
| * @param con initialized context |
* @param con initialized context |
| |
* @param begin_pos starting position in file to parse |
| |
* @param size maximal number of bytes/lines in file to parse |
| |
* (set value of -1 for infinite) |
| |
* @param filename parsed filename |
| * @return void |
* @return void |
| */ |
*/ |
| void cfg_reset_context(const CFG_CONTEXT con); |
void cfg_set_cfgfile_context( |
| |
const CFG_CONTEXT con, |
| |
long begin_pos, |
| |
long size, |
| |
char *filename); |
| |
|
| |
#define cfg_set_cfgfile_context_pos(con, begin_pos, end_pos, argv) \ |
| |
cfg_get_cfgfile_context( \ |
| |
con \ |
| |
begin_pos, \ |
| |
end_pos - begin_pos + 1, \ |
| |
argv) |
| |
|
| |
/** |
| |
* Reinitialize popt context |
| |
* |
| |
* @param con initialized context |
| |
* @return void |
| |
*/ |
| |
void cfg_reset_context(const CFG_CONTEXT con); |
| |
|
| /** |
/** |
| * Destroy context |
* Destroy context |
|
|
| */ |
*/ |
| void cfg_free_context(const CFG_CONTEXT con); |
void cfg_free_context(const CFG_CONTEXT con); |
| |
|
| |
/* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| * @name Functions for setting and clearing context flags |
* @name Functions for setting and clearing context flags |
| */ |
*/ |
| /*@{*/ |
/*@{*/ |
| |
/* {{{ */ |
| |
|
| /** |
/** |
| * Set context flag |
* Set context flag |
|
|
| */ |
*/ |
| int cfg_get_context_flags(const CFG_CONTEXT con); |
int cfg_get_context_flags(const CFG_CONTEXT con); |
| |
|
| |
/* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| * @name Functions and macros for properties manipulation |
* @name Functions and macros for properties manipulation |
| */ |
*/ |
| /*@{*/ |
/*@{*/ |
| |
/* {{{ */ |
| |
|
| /** |
/** |
| * Clear all strings of property |
* Clear all strings of property |
|
|
| int cfg_remove_property( |
int cfg_remove_property( |
| const CFG_CONTEXT con, enum cfg_property_type type, char *str); |
const CFG_CONTEXT con, enum cfg_property_type type, char *str); |
| |
|
| |
/* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| /** |
/** |
| * @name Functions for processing context options |
* @name Functions for processing context options |
| */ |
*/ |
| /*@{*/ |
/*@{*/ |
| |
/* {{{ */ |
| |
|
| /** |
/** |
| * Parse context |
* Parse context |
|
|
| */ |
*/ |
| int cfg_get_cur_idx(const CFG_CONTEXT con); |
int cfg_get_cur_idx(const CFG_CONTEXT con); |
| |
|
| |
/* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| |
|
| /** |
/** |
| * @name Error handling functions |
* @name Error handling functions |
| */ |
*/ |
| /*@{*/ |
/*@{*/ |
| |
/* {{{ */ |
| |
|
| /** |
/** |
| * Print error string to stderr |
* Print error string to stderr |
|
|
| * @return static error string |
* @return static error string |
| */ |
*/ |
| char *cfg_get_static_error_str(const int errorcode); |
char *cfg_get_static_error_str(const int errorcode); |
| |
|
| |
/* }}} */ |
| /*@}*/ |
/*@}*/ |
| |
|
| #ifdef __cplusplus |
#ifdef __cplusplus |
|
|
| |
|
| #endif /* _PLATON_CFG_H */ |
#endif /* _PLATON_CFG_H */ |
| |
|
| |
/* Modeline for ViM {{{ |
| |
* vim:set ts=4: |
| |
* vim600:fdm=marker fdl=0 fdc=0: |
| |
* }}} */ |
| |
|