libcfg+
0.7.0
|
main implementation header file More...
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | cfg_option |
Structure for defining one config option. More... | |
struct | cfg_context |
Main structure for defining context. More... | |
Macros | |
#define | CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 } |
End of options list marker. | |
#define | CFG_END_OF_LIST CFG_END_OPTION |
Alias for CFG_END_OPTION. | |
Typedefs | |
typedef struct cfg_context * | CFG_CONTEXT |
Context data type. | |
Enumerations | |
Error codes | |
enum | cfg_error { CFG_ERR_OK = 0, CFG_ERROR_OK = 0, CFG_OK = 0, CFG_ERR_NOARG = -1, CFG_ERROR_NOARG = -1, CFG_ERR_NOTALLOWEDARG = -2, CFG_ERROR_NOTALLOWEDARG = -2, CFG_ERR_BADOPT = -3, CFG_ERROR_BADOPT = -3, CFG_ERR_BADQUOTE = -4, CFG_ERROR_BADQUOTE = -4, CFG_ERR_BADNUMBER = -5, CFG_ERROR_BADNUMBER = -5, CFG_ERR_OVERFLOW = -6, CFG_ERROR_OVERFLOW = -6, CFG_ERR_MULTI = -7, CFG_ERROR_MULTI = -7, CFG_ERR_NOMEM = -8, CFG_ERROR_NOMEM = -8, CFG_ERR_STOP_STR = -9, CFG_ERR_STOP_STR_FOUND = -9, CFG_ERROR_STOP_STR = -9, CFG_ERROR_STOP_STR_FOUND = -9, CFG_ERR_NOEQUAL = -10, CFG_ERROR_NOEQUAL = -10, CFG_ERR_UNKNOWN = -11, CFG_ERROR_UNKNOWN = -11, CFG_ERR_FILE_NOT_FOUND = -12, CFG_ERROR_FILE_NOT_FOUND = -12, CFG_ERR_SEEK_ERROR = -13, CFG_ERROR_SEEK_ERROR = -13, CFG_ERR_INTERNAL = -20, CFG_ERROR_INTERNAL = -20 } |
Possible return values returned by parsing functions. More... | |
Context flags | |
enum | cfg_flag { CFG_IGNORE_MULTI = 1, CFG_IGNORE_UNKNOWN = 2, CFG_PROCESS_FIRST = 0, CFG_SKIP_FIRST = 4, CFG_POSIXLY_LEFTOVERS = 0, CFG_ADVANCED_LEFTOVERS = 8, CFG_NORMAL_LEFTOVERS = 0, CFG_STRICT_LEFTOVERS = 16, CFG_FILE_BYTE_POS_USAGE = 0, CFG_FILE_LINE_POS_USAGE = 32 } |
By default are CFG_PROCESS_FIRST, CFG_POSIXLY_LEFTOVERS and CFG_NORMAL_LEFTOVERS initialized. More... | |
Option types | |
enum | cfg_option_type { CFG_BOOL = 1, CFG_BOOLEAN = 1, CFG_INT = 2, CFG_INTEGER = 2, CFG_UINT = 3, CFG_UNSIGNED = 3, CFG_UNSIGNED_INT = 3, CFG_LONG = 4, CFG_ULONG = 5, CFG_UNSIGNED_LONG = 5, CFG_FLOAT = 6, CFG_DOUBLE = 7, CFG_STR = 8, CFG_STRING = 8, CFG_END = 0, CFG_DATA_TYPE_MASK = 31, CFG_SINGLE = 0, CFG_MULTI = 32, CFG_MULTI_ARRAY = 32, CFG_MULTI_SEPARATED = 32 + 64, CFG_LAST_ARGS = 128, CFG_LAST_ARGUMENTS = 128, CFG_LEFTOVER_ARGS = 128, CFG_LEFTOVER_ARGUMENTS = 128 } |
Possible types of options. More... | |
Internal enumerations | |
enum | cfg_context_type { CFG_NO_CONTEXT = 0, CFG_CMDLINE = 1, CFG_LINE = 1, CFG_CFGFILE = 2, CFG_FILE = 2 } |
Context type. More... | |
enum | cfg_line_option_type { CFG_NONE_OPTION = 0, CFG_SHORT_OPTION = 1, CFG_LONG_OPTION = 2, CFG_SHORT_OPTIONS = 4, CFG_LONG_SEPINIT = 8, CFG_LONG_NOSEPINIT = 0 } |
Command line option type. More... | |
Functions | |
Functions and macros for properties manipulation | |
int | cfg_clear_property (const CFG_CONTEXT con, enum cfg_property_type type) |
Clear all strings of property. More... | |
int | cfg_clear_properties (const CFG_CONTEXT con, enum cfg_property_type type,...) |
Clear all strings of property. More... | |
int | cfg_add_property (const CFG_CONTEXT con, enum cfg_property_type type, char *str) |
Add string to property. More... | |
int | cfg_add_properties (const CFG_CONTEXT con, enum cfg_property_type type, char *str,...) |
Add multiple strings to particular properties. More... | |
int | cfg_add_properties_str (const CFG_CONTEXT con, char *str, enum cfg_property_type type,...) |
Add string to multiple properties. More... | |
int | cfg_add_properties_type (const CFG_CONTEXT con, enum cfg_property_type type, char *str,...) |
Add multiple strings to one property. More... | |
int | cfg_remove_property (const CFG_CONTEXT con, enum cfg_property_type type, char *str) |
Remove string from property. More... | |
int | cfg_remove_properties (const CFG_CONTEXT con, enum cfg_property_type type, char *str,...) |
Remove multiple strings from particular properties. More... | |
int | cfg_remove_properties_str (const CFG_CONTEXT con, char *str, enum cfg_property_type type,...) |
Remove string from multiple properties. More... | |
int | cfg_remove_properties_type (const CFG_CONTEXT con, enum cfg_property_type type, char *str,...) |
Remove multiple strings from one property. More... | |
Functions for processing context options | |
int | cfg_parse (const CFG_CONTEXT con) |
Parse context. More... | |
int | cfg_get_next_opt (const CFG_CONTEXT con) |
Parse next option(s) and return its value (if non-zero) or error code. More... | |
char * | cfg_get_cur_opt (const CFG_CONTEXT con) |
Return currently processed option name. More... | |
char * | cfg_get_cur_arg (const CFG_CONTEXT con) |
Return currently processed option argument. More... | |
int | cfg_get_cur_idx (const CFG_CONTEXT con) |
Return currently processed option index (argv index in command line context, file byte position or line position in config file context) More... | |
Error handling functions | |
void | cfg_print_error (const CFG_CONTEXT con) |
Print error string to stderr. More... | |
void | cfg_fprint_error (const CFG_CONTEXT con, FILE *fh) |
Print error string to stream. More... | |
char * | cfg_get_error_str (const CFG_CONTEXT con) |
Get error string; error string is dynamically allocated, it needs to be freed after use. More... | |
char * | cfg_get_static_error_str (const int errorcode) |
Get static error string. More... | |
Functions and macros for creating and manipulating context | |
#define | cfg_get_cmdline_context_pos(begin_pos, end_pos, argv, options) |
Initialize core context. More... | |
#define | cfg_get_cfgfile_context_pos(begin_pos, end_pos, argv, options) |
Initialize core context. More... | |
#define | cfg_set_cmdline_context_pos(con, begin_pos, end_pos, argv) |
Initialize core context. More... | |
#define | cfg_set_cfgfile_context_pos(con, begin_pos, end_pos, argv) |
Initialize core context. More... | |
CFG_CONTEXT | cfg_get_context (struct cfg_option *options) |
Initialize core context. More... | |
CFG_CONTEXT | cfg_get_cmdline_context (long begin_pos, long size, char **argv, struct cfg_option *options) |
Initialize command line context. More... | |
CFG_CONTEXT | cfg_get_cmdline_context_argc (int argc, char **argv, struct cfg_option *options) |
Initialize command line context by argc and argv passed to main() More... | |
CFG_CONTEXT | cfg_get_cfgfile_context (long begin_pos, long size, char *filename, struct cfg_option *options) |
Initialize configuration file context. More... | |
void | cfg_set_cmdline_context (const CFG_CONTEXT con, long begin_pos, long size, char **argv) |
Set context to command line. More... | |
void | cfg_set_cmdline_context_argc (const CFG_CONTEXT con, int argc, char **argv) |
Set context to command line by argc and argv passed to main() More... | |
void | cfg_set_cfgfile_context (const CFG_CONTEXT con, long begin_pos, long size, char *filename) |
Set context to configuration file. More... | |
void | cfg_reset_context (const CFG_CONTEXT con) |
Reinitialize popt context. More... | |
void | cfg_free_context (const CFG_CONTEXT con) |
Destroy context. More... | |
Functions for setting and clearing context flags | |
#define | cfg_is_context_flag(con, flag) cfg_get_context_flag(con, flag) |
Set context flag. More... | |
void | cfg_set_context_flag (const CFG_CONTEXT con, int flag) |
Set context flag. More... | |
void | cfg_clear_context_flag (const CFG_CONTEXT con, int flag) |
Clear context flag. More... | |
int | cfg_get_context_flag (const CFG_CONTEXT con, int flag) |
Get context flag. More... | |
void | cfg_set_context_flags (const CFG_CONTEXT con, int flags) |
Overwrite context flags. More... | |
int | cfg_get_context_flags (const CFG_CONTEXT con) |
Get all context flags. More... | |
main implementation header file
#define cfg_get_cfgfile_context_pos | ( | begin_pos, | |
end_pos, | |||
argv, | |||
options | |||
) |
Initialize core context.
options | pointer to options table |
#define cfg_get_cmdline_context_pos | ( | begin_pos, | |
end_pos, | |||
argv, | |||
options | |||
) |
Initialize core context.
options | pointer to options table |
#define cfg_is_context_flag | ( | con, | |
flag | |||
) | cfg_get_context_flag(con, flag) |
Set context flag.
con | initialized context |
flag | context flag |
#define cfg_set_cfgfile_context_pos | ( | con, | |
begin_pos, | |||
end_pos, | |||
argv | |||
) |
Initialize core context.
options | pointer to options table |
#define cfg_set_cmdline_context_pos | ( | con, | |
begin_pos, | |||
end_pos, | |||
argv | |||
) |
Initialize core context.
options | pointer to options table |
enum cfg_context_type |
enum cfg_error |
Possible return values returned by parsing functions.
enum cfg_flag |
By default are CFG_PROCESS_FIRST, CFG_POSIXLY_LEFTOVERS and CFG_NORMAL_LEFTOVERS initialized.
enum cfg_line_option_type |
Command line option type.
Possible types of command line option (used internally)
enum cfg_option_type |
Possible types of options.
enum cfg_property_type |
Terminators of variable number arguments in functions cfg_add_properties(), cfg_set_properties(), cfg_get_properties() and similar.
int cfg_add_properties | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
char * | str, | ||
... | |||
) |
Add multiple strings to particular properties.
con | initialized context |
type | property type(s) |
str | string(s) for addition |
Argument list must be terminated with typeN = CFG_EOT or strN = NULL. Use constructions like this:
cfg_add_properties(con, type1, str1, type2, str2, type3=CFG_EOT)
int cfg_add_properties_str | ( | const CFG_CONTEXT | con, |
char * | str, | ||
enum cfg_property_type | type, | ||
... | |||
) |
Add string to multiple properties.
con | initialized context |
str | string for addition |
type | property type(s) |
Argument list must be terminated with typeN = CFG_EOT. Use constructions like this:
cfg_add_properties(con, str, type1, type2, type3=CFG_EOT)
int cfg_add_properties_type | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
char * | str, | ||
... | |||
) |
Add multiple strings to one property.
con | initialized context |
type | property type |
str | string(s) for addition |
Argument list must be terminated with strN = NULL. Use constructions like this:
cfg_add_properties(con, type, str1, str2, str3=NULL)
int cfg_add_property | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
char * | str | ||
) |
Add string to property.
con | initialized context |
type | property type |
str | string for addition |
void cfg_clear_context_flag | ( | const CFG_CONTEXT | con, |
int | flag | ||
) |
Clear context flag.
con | initialized context |
flag | context flag |
int cfg_clear_properties | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
... | |||
) |
Clear all strings of property.
con | initialized context |
type | property type |
int cfg_clear_property | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type | ||
) |
Clear all strings of property.
con | initialized context |
type | property type |
void cfg_fprint_error | ( | const CFG_CONTEXT | con, |
FILE * | fh | ||
) |
Print error string to stream.
con | initialized context |
fh | stream opened for writting |
void cfg_free_context | ( | const CFG_CONTEXT | con | ) |
Destroy context.
con | initialized context |
CFG_CONTEXT cfg_get_cfgfile_context | ( | long | begin_pos, |
long | size, | ||
char * | filename, | ||
struct cfg_option * | options | ||
) |
Initialize configuration file context.
begin_pos | starting position in file to parse |
size | maximal number of bytes/lines in file to parse (set value of -1 for infinite) |
filename | parsed filename |
options | pointer to options table |
CFG_CONTEXT cfg_get_cmdline_context | ( | long | begin_pos, |
long | size, | ||
char ** | argv, | ||
struct cfg_option * | options | ||
) |
Initialize command line context.
begin_pos | index of beginning argument of arguments array |
size | maximal number of array elements to parse (set value of -1 for infinite) |
argv | arguments array |
options | pointer to options table |
CFG_CONTEXT cfg_get_cmdline_context_argc | ( | int | argc, |
char ** | argv, | ||
struct cfg_option * | options | ||
) |
Initialize command line context by argc and argv passed to main()
argc | argumet count (argc) passed to function main() |
argv | arguments array (argv) passed to function main() |
options | pointer to options table |
CFG_CONTEXT cfg_get_context | ( | struct cfg_option * | options | ) |
Initialize core context.
options | pointer to options table |
int cfg_get_context_flag | ( | const CFG_CONTEXT | con, |
int | flag | ||
) |
Get context flag.
con | initialized context |
flag | context flag |
int cfg_get_context_flags | ( | const CFG_CONTEXT | con | ) |
Get all context flags.
con | initialized context |
char* cfg_get_cur_arg | ( | const CFG_CONTEXT | con | ) |
Return currently processed option argument.
con | initialized context |
int cfg_get_cur_idx | ( | const CFG_CONTEXT | con | ) |
Return currently processed option index (argv index in command line context, file byte position or line position in config file context)
con | initialized context |
char* cfg_get_cur_opt | ( | const CFG_CONTEXT | con | ) |
Return currently processed option name.
con | initialized context |
char* cfg_get_error_str | ( | const CFG_CONTEXT | con | ) |
Get error string; error string is dynamically allocated, it needs to be freed after use.
con | initialized context |
int cfg_get_next_opt | ( | const CFG_CONTEXT | con | ) |
Parse next option(s) and return its value (if non-zero) or error code.
con | initialized context |
char* cfg_get_static_error_str | ( | const int | errorcode | ) |
Get static error string.
errorcode | code of libcfg error |
int cfg_parse | ( | const CFG_CONTEXT | con | ) |
Parse context.
con | initialized context |
void cfg_print_error | ( | const CFG_CONTEXT | con | ) |
Print error string to stderr.
con | initialized context |
int cfg_remove_properties | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
char * | str, | ||
... | |||
) |
Remove multiple strings from particular properties.
con | initialized context |
type | property type(s) |
str | string(s) for removal |
Argument list must be terminated with typeN = CFG_EOT or strN = NULL. Use constructions like this:
cfg_remove_properties(con, type1, str1, type2, str2, type3=CFG_EOT)
int cfg_remove_properties_str | ( | const CFG_CONTEXT | con, |
char * | str, | ||
enum cfg_property_type | type, | ||
... | |||
) |
Remove string from multiple properties.
con | initialized context |
str | string for removal |
type | property type(s) |
Argument list must be terminated with typeN = CFG_EOT. Use constructions like this:
cfg_remove_properties(con, str, type1, type2, type3=CFG_EOT)
int cfg_remove_properties_type | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
char * | str, | ||
... | |||
) |
Remove multiple strings from one property.
con | initialized context |
type | property type |
str | string(s) for removal |
Argument list must be terminated with strN = NULL. Use constructions like this:
cfg_add_properties(con, type, str1, str2, str3=NULL)
int cfg_remove_property | ( | const CFG_CONTEXT | con, |
enum cfg_property_type | type, | ||
char * | str | ||
) |
Remove string from property.
con | initialized context |
type | property type |
str | string for removal |
void cfg_reset_context | ( | const CFG_CONTEXT | con | ) |
Reinitialize popt context.
con | initialized context |
void cfg_set_cfgfile_context | ( | const CFG_CONTEXT | con, |
long | begin_pos, | ||
long | size, | ||
char * | filename | ||
) |
Set context to configuration file.
con | initialized context |
begin_pos | starting position in file to parse |
size | maximal number of bytes/lines in file to parse (set value of -1 for infinite) |
filename | parsed filename |
void cfg_set_cmdline_context | ( | const CFG_CONTEXT | con, |
long | begin_pos, | ||
long | size, | ||
char ** | argv | ||
) |
Set context to command line.
con | initialized context |
begin_pos | index of beginning argument of arguments array |
size | maximal number of array elements to parse (set value of -1 for infinite) |
argv | arguments array |
void cfg_set_cmdline_context_argc | ( | const CFG_CONTEXT | con, |
int | argc, | ||
char ** | argv | ||
) |
Set context to command line by argc and argv passed to main()
con | initialized context |
argc | argumet count (argc) passed to function main() |
argv | arguments array (argv) passed to function main() |
void cfg_set_context_flag | ( | const CFG_CONTEXT | con, |
int | flag | ||
) |
Set context flag.
con | initialized context |
flag | context flag |
void cfg_set_context_flags | ( | const CFG_CONTEXT | con, |
int | flags | ||
) |
Overwrite context flags.
con | initialized context |
flags | context flags |