; this is a basic configuration file [category0] variable0 = value0 ; this is a comment variable1 = value1 [category1] variable0 = value2 variable2 = value3
the code;
int i; int j; s_config_t *cfg; s_config_cat_t *cat; s_config_var_t *var; // initialize cfg struct s_config_init(&cfg); // parse the cfg file s_config_parse(cfg, "basic.cfg"); // walk through the categories i = 0; while (!s_list_eol(cfg->category, i)) { // get category and print cat = s_list_get(cfg->category, i++); printf("category: %s\n", cat->name); // walk though the variables in category j = 0; while (!s_list_eol(cat->variable, j)) { // get variable and print var = s_list_get(cat->variable, j++); printf("\t%s = %s\n", var->name, var->value); } } // uninitialize the cfg struct s_config_uninit(cfg);
print out will be;
category : category0
variable0 = value0
variable1 = value1
category : category1
variable0 = value2
variable2 = value3
Data Structures | |
| struct | s_config_var_s |
| config variable struct More... | |
| struct | s_config_cat_s |
| config category struct More... | |
| struct | s_config_s |
| config struct More... | |
Functions | |
| char * | s_config_strip (char *buf) |
| strips leading and trailing white spaces by modifing buf | |
| int | s_config_parse (s_config_t *cfg, char *name) |
| parses the given configuration file | |
| int | s_config_init (s_config_t **cfg) |
| initialize the config struct | |
| int | s_config_category_init (s_config_cat_t **cat, char *name) |
| initialize the category struct | |
| int | s_config_variable_init (s_config_var_t **var, char *name, char *value) |
| initialize the variable struct | |
| int | s_config_variable_uninit (s_config_var_t *var) |
| uninitialize the variable struct | |
| int | s_config_category_uninit (s_config_cat_t *cat) |
| uninitialize the category struct | |
| int | s_config_uninit (s_config_t *cfg) |
| uninitialize the config struct | |
| int s_config_category_init | ( | s_config_cat_t ** | cat, | |
| char * | name | |||
| ) |
initialize the category struct
| cat | - pointer to the category struct pointer | |
| name | - category name |
| int s_config_category_uninit | ( | s_config_cat_t * | cat | ) |
uninitialize the category struct
| cat | - the category struct pointer |
| int s_config_init | ( | s_config_t ** | cfg | ) |
initialize the config struct
| cfg | - pointer to the config struct pointer |
| int s_config_parse | ( | s_config_t * | cfg, | |
| char * | name | |||
| ) |
parses the given configuration file
| cfg | - the config struct pointer | |
| name | - file name to parse |
| char* s_config_strip | ( | char * | buf | ) |
strips leading and trailing white spaces by modifing buf
| buf | - buffer to strip white spaces from |
| int s_config_uninit | ( | s_config_t * | cfg | ) |
uninitialize the config struct
| cfg | - the config struct pointer |
| int s_config_variable_init | ( | s_config_var_t ** | var, | |
| char * | name, | |||
| char * | value | |||
| ) |
initialize the variable struct
| var | - pointer to the variable struct pointer | |
| name | - variable name | |
| value | - variable value |
| int s_config_variable_uninit | ( | s_config_var_t * | var | ) |
uninitialize the variable struct
| var | - the variable struct pointer |
1.4.7