cfg+.h | cfg+.h | |||
---|---|---|---|---|
/* | /* | |||
* libcfg+ - precise command line & config file parsing library | * libcfg+ - precise command line & config file parsing library | |||
* | * | |||
* cfg+.h - main implementation header file | * cfg+.h - main implementation header file | |||
* ____________________________________________________________ | * ____________________________________________________________ | |||
* | * | |||
* Developed by Ondrej Jombik <nepto@pobox.sk> | * Developed by Ondrej Jombik <nepto@pobox.sk> | |||
* and Lubomir Host <rajo@host.sk> | ||||
* Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/ | * Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/ | |||
* All rights reserved. | * All rights reserved. | |||
* | * | |||
* See README file for more information about this software. | * See README file for more information about this software. | |||
* See COPYING file for license information. | * See COPYING file for license information. | |||
* | * | |||
* Download the latest version from | * Download the latest version from | |||
* http://www.platon.sk/projects/libcfg+/ | * http://www.platon.sk/projects/libcfg+/ | |||
*/ | */ | |||
/* $Id: cfg+.h,v 1.37 2002/05/30 22:29:45 jombik9 Exp $ */ | /* $Id: cfg+.h,v 1.44 2002/07/18 22:16:30 nepto Exp $ */ | |||
/** | /** | |||
* @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> | |||
* @version \$Id: cfg+.h,v 1.37 2002/05/30 22:29:45 jombik9 Exp $ | * @author Lubomir Host <rajo@host.sk> | |||
* @version \$Id: cfg+.h,v 1.44 2002/07/18 22:16:30 nepto Exp $ | ||||
* @date 2001-2002 | * @date 2001-2002 | |||
*/ | */ | |||
#ifndef _PLATON_CFG_H | #ifndef _PLATON_CFG_H | |||
#define _PLATON_CFG_H | #define _PLATON_CFG_H | |||
#include <stdio.h> | #include <stdio.h> | |||
/** End of options list marker */ | /** End of options list marker */ | |||
#define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 } | #define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 } | |||
#define CFG_END_OF_LIST CFG_END_OPTION /**< @ref CFG_END_OPTION */ | #define CFG_END_OF_LIST CFG_END_OPTION /**< @ref CFG_END_OPTION */ | |||
/** | /** | |||
* @name Error codes | * @name Error codes | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** | /** | |||
* 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. */ | |||
CFG_ERR_OK = 0, | CFG_ERR_OK = 0, | |||
CFG_ERROR_OK = 0, | CFG_ERROR_OK = 0, | |||
CFG_OK = 0, | CFG_OK = 0, | |||
/*@}*/ | /*@}*/ | |||
/** An argument is missing for an option. */ | /** An argument is missing for an option. */ | |||
CFG_ERR_NOARG = -1, | CFG_ERR_NOARG = -1, | |||
skipping to change at line 111 | skipping to change at line 113 | |||
CFG_ERROR_FILE_NOT_FOUND = -12, | CFG_ERROR_FILE_NOT_FOUND = -12, | |||
/** Seek error (fseek() failure). */ | /** Seek error (fseek() failure). */ | |||
CFG_ERR_SEEK_ERROR = -13, | CFG_ERR_SEEK_ERROR = -13, | |||
CFG_ERROR_SEEK_ERROR = -13, | CFG_ERROR_SEEK_ERROR = -13, | |||
/** Internal error. */ | /** Internal error. */ | |||
CFG_ERR_INTERNAL = -20, | CFG_ERR_INTERNAL = -20, | |||
CFG_ERROR_INTERNAL = -20 | CFG_ERROR_INTERNAL = -20 | |||
}; | }; /* }}} */ | |||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Context flags | * @name Context flags | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** | /** | |||
* By default are @ref CFG_SKIP_FIRST, @ref CFG_POSIXLY_LEFTOVERS and | * By default are @ref CFG_PROCESS_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 | * @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, | |||
/** Ignore unknown options. */ | /** Ignore unknown options. */ | |||
CFG_IGNORE_UNKNOWN = 2, | CFG_IGNORE_UNKNOWN = 2, | |||
/** Skip processing of the first argument on command line. */ | ||||
CFG_SKIP_FIRST = 0, | ||||
/** Process also the first argument on command line. */ | /** Process also the first argument on command line. */ | |||
CFG_PROCESS_FIRST = 4, | CFG_PROCESS_FIRST = 0, | |||
/** Skip processing of the first argument on command line. */ | ||||
CFG_SKIP_FIRST = 4, | ||||
/** Posixly correct leftover arguments. */ | /** Posixly correct leftover arguments. */ | |||
CFG_POSIXLY_LEFTOVERS = 0, | CFG_POSIXLY_LEFTOVERS = 0, | |||
/** Advanced leftover arguments. */ | /** Advanced leftover arguments. */ | |||
CFG_ADVANCED_LEFTOVERS = 8, | CFG_ADVANCED_LEFTOVERS = 8, | |||
/** Normal leftover arguments initialization in file. */ | /** Normal leftover arguments initialization in file. */ | |||
CFG_NORMAL_LEFTOVERS = 0, | CFG_NORMAL_LEFTOVERS = 0, | |||
skipping to change at line 168 | skipping to change at line 170 | |||
CFG_IGNORE_QUOTE = 16 | CFG_IGNORE_QUOTE = 16 | |||
*/ | */ | |||
/* Advanced quotations are things like option = va"'l'"ue | /* Advanced quotations are things like option = va"'l'"ue | |||
which resolves to va'l 'ue. | which resolves to va'l 'ue. | |||
We really want this strange stuff? Any volunter? | We really want this strange stuff? Any volunter? | |||
CFG_ADVANCED_QUOTE = 32 + 16 | CFG_ADVANCED_QUOTE = 32 + 16 | |||
*/ | */ | |||
}; | }; /* }}} */ | |||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Option types | * @name Option types | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** | /** | |||
* Possible types of options | * Possible types of options | |||
* @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, | |||
CFG_BOOLEAN = 1, | CFG_BOOLEAN = 1, | |||
/** Integer */ | /** Integer */ | |||
CFG_INT = 2, | CFG_INT = 2, | |||
CFG_INTEGER = 2, | CFG_INTEGER = 2, | |||
/** Unsigned int */ | /** Unsigned int */ | |||
skipping to change at line 237 | skipping to change at line 239 | |||
/** | /** | |||
* Leftover arguments specification. | * Leftover arguments specification. | |||
* Mark option which will contain leftover arguments. | * 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 | |||
}; | }; /* }}} */ | |||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Special properties types | * @name Special properties types | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
enum cfg_property_type { | enum cfg_property_type { /* {{{ */ | |||
/** | /** | |||
* @name Special properties codes | * @name Special properties codes | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** Array of strings which forces to stop command line parsing. */ | /** Array of strings which forces to stop command line parsing. */ | |||
CFG_LINE_STOP_STRING = 0, | CFG_LINE_STOP_STRING = 0, | |||
/** default: "-" */ | /** Command line short option prefix (default: "-") */ | |||
CFG_LINE_SHORT_OPTION_PREFIX = 1, | CFG_LINE_SHORT_OPTION_PREFIX = 1, | |||
/** default: "--" */ | /** Command line long option prefix (default: "--") */ | |||
CFG_LINE_LONG_OPTION_PREFIX = 2, | CFG_LINE_LONG_OPTION_PREFIX = 2, | |||
/** default: "=" */ | /** Command line option argument separator (default: "=") */ | |||
CFG_LINE_OPTION_ARG_SEPARATOR = 3, | CFG_LINE_OPTION_ARG_SEPARATOR = 3, | |||
/** Multi values separator. */ | /** Command line multi values separator. */ | |||
CFG_LINE_MULTI_VALS_SEPARATOR = 4, | CFG_LINE_NORMAL_MULTI_VALS_SEPARATOR = 4, | |||
/** Quote prefix & postfix */ | /** Command line multi values leftover arguments separator */ | |||
CFG_QUOTE_PREFIX = 5, | CFG_LINE_LEFTOVER_MULTI_VALS_SEPARATOR = 5, | |||
CFG_QUOTE_POSTFIX = 6, | ||||
/** Command line quote prefix & postfix */ | ||||
CFG_LINE_QUOTE_PREFIX = 6, | ||||
CFG_LINE_QUOTE_POSTFIX = 7, | ||||
/** Array of strings prefixes which forces to stop config file parsi ng. | /** Array of strings prefixes which forces to stop config file parsi ng. | |||
* default: "[" | * default: "[" | |||
*/ | */ | |||
CFG_FILE_STOP_PREFIX = 7, | CFG_FILE_STOP_PREFIX = 8, | |||
/** Array of string prefixes which mark comment line. | /** Array of string prefixes which mark comment line. | |||
* defaults: "#", ";" | * defaults: "#", ";" | |||
*/ | */ | |||
CFG_FILE_COMMENT_PREFIX = 8, | CFG_FILE_COMMENT_PREFIX = 9, | |||
/** Array of string postfixes to determine multi lines. */ | /** Array of string postfixes to determine multi lines. */ | |||
CFG_FILE_MULTI_LINE_POSTFIX = 9, | CFG_FILE_MULTI_LINE_POSTFIX = 10, | |||
/** Option argument separator. | /** Config file option argument separator (default: "=") */ | |||
default: "=" */ | CFG_FILE_OPTION_ARG_SEPARATOR = 11, | |||
CFG_FILE_OPTION_ARG_SEPARATOR = 10, | ||||
/** Multi values separator. */ | /** Config file multi values separator. */ | |||
CFG_FILE_MULTI_VALS_SEPARATOR = 11, | CFG_FILE_NORMAL_MULTI_VALS_SEPARATOR = 12, | |||
/** Command line multi values leftover arguments separator */ | ||||
CFG_FILE_LEFTOVER_MULTI_VALS_SEPARATOR = 13, | ||||
/** Config file quote prefix & postfix */ | ||||
CFG_FILE_QUOTE_PREFIX = 14, | ||||
CFG_FILE_QUOTE_POSTFIX = 15, | ||||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Numbers of normal properties | * @name Numbers of normal properties | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** Special properties count */ | /** Special properties count */ | |||
CFG_N_PROPS = 12, | CFG_N_PROPS = 16, | |||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Virtual properties codes | * @name Virtual properties codes | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** File quote prefix & postfix */ | ||||
CFG_QUOTE = 50, | ||||
CFG_LINE_QUOTE = 51, | ||||
CFG_FILE_QUOTE = 52, | ||||
CFG_QUOTE_PREFIX = 53, | ||||
CFG_QUOTE_POSTFIX = 54, | ||||
/** Multi values separator */ | ||||
CFG_MULTI_VALS_SEPARATOR = 55, | ||||
CFG_FILE_MULTI_VALS_SEPARATOR = 56, | ||||
CFG_LINE_MULTI_VALS_SEPARATOR = 57, | ||||
CFG_NORMAL_MULTI_VALS_SEPARATOR = 58, | ||||
CFG_LEFTOVER_MULTI_VALS_SEPARATOR = 59, | ||||
/** Option argument separator */ | ||||
CFG_OPTION_ARG_SEPARATOR = 60, | ||||
/* TODO: virtual properties */ | /* TODO: virtual properties */ | |||
CFG_VIRTUAL_SPECIAL_PROPERTY = 13 | CFG_VIRTUAL_SPECIAL_PROPERTY = 99 | |||
/*@}*/ | /*@}*/ | |||
}; | }; /* }}} */ | |||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Internal enumerations | * @name Internal enumerations | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** | /** | |||
* Context type | * Context 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, | |||
/** 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. | * 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, | |||
/** 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) */ | /** 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') */ | |||
const char cmdline_short_name; | const char cmdline_short_name; | |||
/** Config file name (may be NULL) */ | /** Config file name (may be NULL) */ | |||
const char *cfgfile_name; | const char *cfgfile_name; | |||
/** Option type | /** Option type | |||
@see cfg_option_type */ | @see cfg_option_type */ | |||
const enum cfg_option_type type; | const enum cfg_option_type type; | |||
/** Pointer where to store value of option */ | /** Pointer where to store value of option */ | |||
void *value; | void *value; | |||
/** 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 | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/** 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; | |||
/** Starting parsing position */ | ||||
long begin_pos; | ||||
/** Number of elements (array arguments, bytes or lines) to parse | ||||
(value of -1 means infinite) */ | ||||
long size; | ||||
/** Array of used options indexes */ | /** Array of used options indexes */ | |||
int *used_opt_idx; | int *used_opt_idx; | |||
/** Error code of last occured error. */ | /** Error code of last occured error. */ | |||
enum cfg_error error_code; | enum cfg_error error_code; | |||
/** Special properties */ | /** Special properties */ | |||
char **prop[CFG_N_PROPS]; | char **prop[CFG_N_PROPS]; | |||
/** Currents */ | ||||
long cur_idx; | ||||
long cur_idx_tmp; | ||||
int cur_opt_type; | ||||
/** Current option string */ | ||||
char *cur_opt; | ||||
/** Current option argument*/ | ||||
char *cur_arg; | ||||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Command line specific properties | * @name Command line specific properties | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
int argc; | /** Flag to detect if parsing already started */ | |||
char **argv; | int parsing_started:1; | |||
int cur_idx; | ||||
int cur_idx_tmp; | ||||
int cur_opt_type; | ||||
char *cur_opt; | /** NULL terminated array of argument */ | |||
char *cur_arg; | char **argv; | |||
/*@}*/ | /*@}*/ | |||
/** | /** | |||
* @name Config file specific properties. | * @name Config file specific properties. | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
long begin_pos; | /** Filename (name of file) */ | |||
long end_pos; | ||||
char *filename; | char *filename; | |||
/** Pointer to FILE* structure of parsed file */ | ||||
FILE *fhandle; | FILE *fhandle; | |||
/*@}*/ | /*@}*/ | |||
}; | }; /* }}} */ | |||
/** | /** | |||
* @brief Context data type | * @brief Context data type | |||
*/ | */ | |||
typedef struct cfg_context * CFG_CONTEXT; | typedef struct cfg_context * CFG_CONTEXT; | |||
/* | /* | |||
* Functions | * Functions | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
/** | /** | |||
* @name Functions for creating and manipulating context | * @name Functions and macros for creating and manipulating context | |||
*/ | */ | |||
/*@{*/ | /*@{*/ | |||
/* {{{ */ | ||||
/** | /** | |||
* Initialize core context | * Initialize core context | |||
* | * | |||
* @param options pointer to options table | * @param options pointer to options table | |||
* @return initialized core context; further sp ecification | * @return initialized core context; further sp ecification | |||
* to command line or config fi le is required | * to command line or config fi le is required | |||
*/ | */ | |||
CFG_CONTEXT cfg_get_context(struct cfg_option *options); | CFG_CONTEXT cfg_get_context(struct cfg_option *options); | |||
/** | /** | |||
* Initialize command line context | * Initialize command line context | |||
* | * | |||
* @param argc number of arguments | * @param begin_pos index of beginning argument of arguments arr | |||
ay | ||||
* @param size maximal number of array elements to parse | ||||
* (set value of -1 for infinit | ||||
e) | ||||
* @param argv arguments array | * @param argv arguments array | |||
* @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_cmdline_context( | CFG_CONTEXT cfg_get_cmdline_context( | |||
int argc, | long begin_pos, | |||
long size, | ||||
char **argv, | char **argv, | |||
struct cfg_option *options); | struct cfg_option *options); | |||
#define cfg_get_cmdline_context_pos(begin_pos, end_pos, argv, options) \ | ||||
cfg_get_cmdline_context( \ | ||||
begin_pos, \ | ||||
end_pos - begin_pos + 1, \ | ||||
argv, \ | ||||
options) | ||||
/** | ||||
* Initialize command line context by argc and argv passed t | ||||
o main() | ||||
* | ||||
* @param argc argumet count (argc) passed to funct | ||||
ion main() | ||||
* @param argv arguments array (argv) passed to fun | ||||
ction main() | ||||
* @param options pointer to options table | ||||
* @return initialized command line con | ||||
text | ||||
*/ | ||||
CFG_CONTEXT cfg_get_cmdline_context_argc( | ||||
int argc, | ||||
char **argv, | ||||
struct cfg_option *options); | ||||
/** | /** | |||
* Initialize config line context | * Initialize configuration file context | |||
* | * | |||
* @param begin_pos starting position in file to parse | * @param begin_pos starting position in file to parse | |||
* @param end_pos ending position of file to parse | * @param size maximal number of bytes/lines in file to par | |||
se | ||||
* (set value of -1 for infinit | ||||
e) | ||||
* @param filename parsed filename | * @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_cfgfile_context( | |||
long begin_pos, | long begin_pos, | |||
long end_pos, | long size, | |||
char *filename, | char *filename, | |||
struct cfg_option *options); | struct cfg_option *options); | |||
/** | #define cfg_get_cfgfile_context_pos(begin_pos, end_pos, argv, options) \ | |||
* Set context to command line | cfg_get_cfgfile_context( \ | |||
* | begin_pos, \ | |||
* @param con initialized context | end_pos - begin_pos + 1, \ | |||
* @param argc number of arguments | argv, \ | |||
* @param argv arguments array | options) | |||
* @return void | ||||
*/ | /** | |||
void cfg_set_cmdline_context( | * Set context to command line | |||
const CFG_CONTEXT con, | * | |||
int argc, | * @param con initialized context | |||
char **argv); | * @param begin_pos index of beginning argument of argum | |||
ents array | ||||
* @param size maximal number of array elements to | ||||
parse | ||||
* (set value of -1 for | ||||
infinite) | ||||
* @param argv arguments array | ||||
* @return void | ||||
*/ | ||||
void cfg_set_cmdline_context( | ||||
const CFG_CONTEXT con, | ||||
long begin_pos, | ||||
long size, | ||||
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 ma | ||||
in() | ||||
* | ||||
* @param con initialized context | ||||
* @param argc argumet count (argc) passed to funct | ||||
ion main() | ||||
* @param argv arguments array (argv) passed to fun | ||||
ction main() | ||||
* @return initialized command line con | ||||
text | ||||
*/ | ||||
void cfg_set_cmdline_context_argc( | ||||
const CFG_CONTEXT con, | ||||
int argc, | ||||
char **argv); | ||||
/** | /** | |||
* Set context to command line | * Set context to configuration file | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @param begin_pos starting position in file to parse | * @param begin_pos starting position in file to parse | |||
* @param end_pos ending position of file to parse | * @param size maximal number of bytes/lines in file to par | |||
se | ||||
* (set value of -1 for infinit | ||||
e) | ||||
* @param filename parsed filename | * @param filename parsed filename | |||
* @return void | * @return void | |||
*/ | */ | |||
void cfg_set_cfgfile_context( | void cfg_set_cfgfile_context( | |||
const CFG_CONTEXT con, | const CFG_CONTEXT con, | |||
long begin_pos, | long begin_pos, | |||
long end_pos, | long size, | |||
char *filename); | char *filename); | |||
/** | #define cfg_set_cfgfile_context_pos(con, begin_pos, end_pos, argv) \ | |||
* Reinitialize popt context | cfg_get_cfgfile_context( \ | |||
* | con \ | |||
* @param con initialized context | begin_pos, \ | |||
* @return void | end_pos - begin_pos + 1, \ | |||
*/ | argv) | |||
void cfg_reset_context(const CFG_CONTEXT con); | ||||
/** | ||||
* Reinitialize popt context | ||||
* | ||||
* @param con initialized context | ||||
* @return void | ||||
*/ | ||||
void cfg_reset_context(const CFG_CONTEXT con); | ||||
/** | /** | |||
* Destroy context | * Destroy context | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @return void | * @return void | |||
*/ | */ | |||
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 | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @param flag context flag | * @param flag context flag | |||
* @return void | * @return void | |||
*/ | */ | |||
void cfg_set_context_flag(const CFG_CONTEXT con, int flag); | void cfg_set_context_flag(const CFG_CONTEXT con, int flag); | |||
skipping to change at line 594 | skipping to change at line 703 | |||
void cfg_set_context_flags(const CFG_CONTEXT con, int flags); | void cfg_set_context_flags(const CFG_CONTEXT con, int flags); | |||
/** | /** | |||
* Get all context flags | * Get all context flags | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @return all context flags | * @return all context flags | |||
*/ | */ | |||
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 | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @param type property type | * @param type property type | |||
* @return void | * @return 1 on success, 0 on not enough memory error | |||
* @see cfg_property_type | * @see cfg_property_type | |||
*/ | */ | |||
void cfg_clear_property( | int cfg_clear_property( | |||
const CFG_CONTEXT con, enum cfg_property_type type); | const CFG_CONTEXT con, enum cfg_property_type type); | |||
/** | /** | |||
* Add string to property | * Add string to property | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @param type property type | * @param type property type | |||
* @param str string for addition | * @param str string for addition | |||
* @return 1 on success, 0 on not enough memory error | * @return 1 on success, 0 on not enough memory error | |||
* @see cfg_property_type | * @see cfg_property_type | |||
skipping to change at line 636 | skipping to change at line 747 | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @param type property type | * @param type property type | |||
* @param str string for removing | * @param str string for removing | |||
* @return 1 on success, 0 on not enough memory error | * @return 1 on success, 0 on not enough memory error | |||
* @see cfg_property_type | * @see cfg_property_type | |||
*/ | */ | |||
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 | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @return code of error (CFG_ERR_*) or CFG_OK | * @return code of error (CFG_ERROR_*) or CFG_OK | |||
* @see cfg_error | * @see cfg_error | |||
*/ | */ | |||
int cfg_parse(const CFG_CONTEXT con); | int cfg_parse(const CFG_CONTEXT con); | |||
/** | /** | |||
* Parse next option(s) and return its value (if non-zero) or error code. | * Parse next option(s) and return its value (if non-zero) or error code. | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @return next option val, code of error (CFG_ERR_*) | * @return next option val, code of error (CFG_ERROR_*) | |||
* or CFG_OK on end | * or CFG_OK on end | |||
* @see cfg_error | * @see cfg_error | |||
* @see cfg_context | * @see cfg_context | |||
*/ | */ | |||
int cfg_get_next_opt(const CFG_CONTEXT con); | int cfg_get_next_opt(const CFG_CONTEXT con); | |||
/** | /** | |||
* Return currently processed option name | * Return currently processed option name | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
skipping to change at line 687 | skipping to change at line 800 | |||
char *cfg_get_cur_arg(const CFG_CONTEXT con); | char *cfg_get_cur_arg(const CFG_CONTEXT con); | |||
/** | /** | |||
* Return currently processed option index (argv index in command li ne | * Return currently processed option index (argv index in command li ne | |||
* context, file byte position or line position in config file conte xt) | * context, file byte position or line position in config file conte xt) | |||
* | * | |||
* @param con initialized context @return index of cur rent option | * @param con initialized context @return index of cur rent option | |||
*/ | */ | |||
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 | |||
* | * | |||
* @param con initialized context | * @param con initialized context | |||
* @return void | * @return void | |||
*/ | */ | |||
void cfg_print_error(const CFG_CONTEXT con); | void cfg_print_error(const CFG_CONTEXT con); | |||
/** | /** | |||
skipping to change at line 727 | skipping to change at line 842 | |||
*/ | */ | |||
char *cfg_get_error_str(const CFG_CONTEXT con); | char *cfg_get_error_str(const CFG_CONTEXT con); | |||
/** | /** | |||
* Get static error string | * Get static error string | |||
* | * | |||
* @param errorcode code of libcfg error | * @param errorcode code of libcfg error | |||
* @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 | #endif | |||
#endif /* _PLATON_CFG_H */ | #endif /* _PLATON_CFG_H */ | |||
/* Modeline for ViM {{{ | ||||
* vim:set ts=4: | ||||
* vim600:fdm=marker fdl=0 fdc=0: | ||||
* }}} */ | ||||
End of changes. 68 change blocks. | ||||
83 lines changed or deleted | 217 lines changed or added | |||