Client Library - Config API


Detailed Description

detailed description

Example:
basic.cfg file;
 ; 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


Function Documentation

int s_config_category_init ( s_config_cat_t **  cat,
char *  name 
)

initialize the category struct

Parameters:
cat - pointer to the category struct pointer
name - category name
Returns:
0 on success, 1 on error.

int s_config_category_uninit ( s_config_cat_t cat  ) 

uninitialize the category struct

Parameters:
cat - the category struct pointer
Returns:
0 on success, 1 on error.

int s_config_init ( s_config_t **  cfg  ) 

initialize the config struct

Parameters:
cfg - pointer to the config struct pointer
Returns:
0 on success, 1 on error.

int s_config_parse ( s_config_t cfg,
char *  name 
)

parses the given configuration file

Parameters:
cfg - the config struct pointer
name - file name to parse
Returns:
0 on success, 1 on error.

char* s_config_strip ( char *  buf  ) 

strips leading and trailing white spaces by modifing buf

Parameters:
buf - buffer to strip white spaces from
Returns:
a valid pointer

int s_config_uninit ( s_config_t cfg  ) 

uninitialize the config struct

Parameters:
cfg - the config struct pointer
Returns:
0 on success, 1 on error.

int s_config_variable_init ( s_config_var_t **  var,
char *  name,
char *  value 
)

initialize the variable struct

Parameters:
var - pointer to the variable struct pointer
name - variable name
value - variable value
Returns:
0 on success, 1 on error.

int s_config_variable_uninit ( s_config_var_t var  ) 

uninitialize the variable struct

Parameters:
var - the variable struct pointer
Returns:
0 on success, 1 on error.


Generated on Wed Dec 27 17:53:06 2006 for xynth-0.8.40 by  doxygen 1.4.7