libusual  0.1
Data Structures | Defines | Functions
usual/cfparser.h File Reference

Config file parser. More...

Data Structures

struct  CfValue
 Helper structure for passing key info to CfOps. More...
struct  CfOps
 Callbacks for setting and getting a variable value. More...
struct  CfKey
 Parameter description. More...
struct  CfSect
 Section description. More...
struct  CfContext
 Top-level config information. More...
struct  CfLookup
 Lookup entry for CF_LOOKUP table. More...

Defines

#define CF_ABS(name, ops, var, flags, def)
 Helper to describe CfKey with absolute addressing.
#define CF_REL(name, ops, var, flags, def)
 Helper to describe CfKey with relative addressing.
Per-key flags
#define CF_VAL_ABS
 The pointer is absolute.
#define CF_VAL_REL
 The pointer is relative to base.
#define CF_NO_RELOAD
 Value must not be changed on reload.
#define CF_READONLY
 Value can only be read.
Shortcut CfOps for well-known types
#define CF_STR
 Ops for string.
#define CF_FILE
 Ops for filename.
#define CF_INT
 Ops for integer.
#define CF_UINT
 Ops for unsigned integer.
#define CF_BOOL
 Ops for boolean.
#define CF_TIME_USEC
 Ops for time as usec.
#define CF_TIME_DOUBLE
 Ops for time as double.
#define CF_LOOKUP(t)
 Ops for lookup, takes table as argument.

Functions

bool cf_load_file (const struct CfContext *cf, const char *fn) _MUSTCHECK
 Load config from file.
const char * cf_get (const struct CfContext *cf, const char *sect, const char *var, char *buf, int buflen)
 Get single value.
bool cf_set (const struct CfContext *cf, const char *sect, const char *var, const char *val)
 Set single value.
Type-specific helpers
bool cf_set_str (struct CfValue *cv, const char *value)
 Setter for string.
bool cf_set_filename (struct CfValue *cv, const char *value)
 Setter for filename.
bool cf_set_int (struct CfValue *cv, const char *value)
 Setter for int.
bool cf_set_uint (struct CfValue *cv, const char *value)
 Setter for unsigned int.
bool cf_set_time_usec (struct CfValue *cv, const char *value)
 Setter for time-usec.
bool cf_set_time_double (struct CfValue *cv, const char *value)
 Setter for time-double.
bool cf_set_lookup (struct CfValue *cv, const char *value)
 Setter for lookup.
const char * cf_get_str (struct CfValue *cv)
 Getter for string.
const char * cf_get_int (struct CfValue *cv)
 Getter for int.
const char * cf_get_uint (struct CfValue *cv)
 Getter for unsigned int.
const char * cf_get_time_usec (struct CfValue *cv)
 Getter for time-usec.
const char * cf_get_time_double (struct CfValue *cv)
 Getter for time-double.
const char * cf_get_lookup (struct CfValue *cv)
 Getter for int lookup.

Simple line-by-line parser

typedef bool(* cf_handler_f )(void *arg, bool is_sect, const char *key, const char *val)
 Callback signarure for parse_ini_file()
bool parse_ini_file (const char *fn, cf_handler_f user_handler, void *arg) _MUSTCHECK
 Simple parser, launches callback for each line.

Detailed Description

Config file parser.


Define Documentation

#define CF_VAL_ABS

The pointer is absolute.

#define CF_VAL_REL

The pointer is relative to base.

#define CF_NO_RELOAD

Value must not be changed on reload.

#define CF_READONLY

Value can only be read.

#define CF_STR

Ops for string.

#define CF_FILE

Ops for filename.

#define CF_INT

Ops for integer.

#define CF_UINT

Ops for unsigned integer.

#define CF_BOOL

Ops for boolean.

#define CF_TIME_USEC

Ops for time as usec.

#define CF_TIME_DOUBLE

Ops for time as double.

#define CF_LOOKUP (   t)

Ops for lookup, takes table as argument.

#define CF_ABS (   name,
  ops,
  var,
  flags,
  def 
)

Helper to describe CfKey with absolute addressing.

#define CF_REL (   name,
  ops,
  var,
  flags,
  def 
)

Helper to describe CfKey with relative addressing.

Before using it defined CF_REL_BASE to base struct.

The var should be field in that struct.

 struct Foo {
        char *foo_name;
 };
 #define CF_REL_BASE struct Foo
 ...
 CF_REL("name", CF_STR, foo_name, 0, NULL)
 ...
 #undef CF_REL_BASE

Typedef Documentation

typedef bool(* cf_handler_f)(void *arg, bool is_sect, const char *key, const char *val)

Callback signarure for parse_ini_file()


Function Documentation

bool parse_ini_file ( const char *  fn,
cf_handler_f  user_handler,
void *  arg 
)

Simple parser, launches callback for each line.

bool cf_set_str ( struct CfValue cv,
const char *  value 
)

Setter for string.

bool cf_set_filename ( struct CfValue cv,
const char *  value 
)

Setter for filename.

bool cf_set_int ( struct CfValue cv,
const char *  value 
)

Setter for int.

bool cf_set_uint ( struct CfValue cv,
const char *  value 
)

Setter for unsigned int.

bool cf_set_time_usec ( struct CfValue cv,
const char *  value 
)

Setter for time-usec.

bool cf_set_time_double ( struct CfValue cv,
const char *  value 
)

Setter for time-double.

bool cf_set_lookup ( struct CfValue cv,
const char *  value 
)

Setter for lookup.

const char* cf_get_str ( struct CfValue cv)

Getter for string.

const char* cf_get_int ( struct CfValue cv)

Getter for int.

const char* cf_get_uint ( struct CfValue cv)

Getter for unsigned int.

const char* cf_get_time_usec ( struct CfValue cv)

Getter for time-usec.

const char* cf_get_time_double ( struct CfValue cv)

Getter for time-double.

const char* cf_get_lookup ( struct CfValue cv)

Getter for int lookup.

bool cf_load_file ( const struct CfContext cf,
const char *  fn 
)

Load config from file.

const char* cf_get ( const struct CfContext cf,
const char *  sect,
const char *  var,
char *  buf,
int  buflen 
)

Get single value.

bool cf_set ( const struct CfContext cf,
const char *  sect,
const char *  var,
const char *  val 
)

Set single value.