|
NAMEcfgread , cfgget ,
cfgget2 —
functions to read and parse configuration files
SYNOPSIS#include <strfunc.h>
int
char *
svect *
DESCRIPTIONThese routines give the user an easy way of creating nice configuration files. The basic idea of configuration files is the attribute=value scheme. Attribute may be writtten as the ordinary english literal word, or placed into the quotes, like a value. Value may also be quoted or be an ordinary english word or combination of alphanumeric characters. Attributes and values may be quoted using the double or single quotes. When quotes are used, escaping can be made much like as in Bourne shell or in the C code. Once read, file is closed, but attribute and values stored internally and may be used multiple times.There are two general forms of defining an attribute=value pairs. Two forms are defined using the following BNF: <simple_word> := 1*<A-Z0-9> <quoted_string> := <QUOTE> *<any character except 0> <QUOTE> <attr> := <simple_word> | <quoted_string> <value> := <quoted_string> | <simple_word> <generic_form> := <attribute> = <value> [ ; ] <multiple> := <attribute> { <value> *<[ , <value> ]> } [ ; ]
EXAMPLEvoid cfgparse() { char *value1; svect *values2; svect *values3; int r; if((r=cfgread("/path/to/config.file")) != 0) { if(r > 0) { printf("Wrong file format.0); } else { printf("File access failed.0); }; return; }; value1 = cfgget("key1"); values2 = cfgget2("key2"); values3 = cfgget2("key3"); /* Free allocated structures */ sfree(values2); sfree(values3); }; CONFIGURATION FILE EXAMPLEkey1 = "value"; key2 = "this multiline value will be \"passed\" to values2."; key3 = { "value1", "value2", "value3" }; key2 = "Hello again!"; SEE ALSOstrfunc(3), sf_svect(3).AUTHORSLev Walkin <vlm@lionet.info>
Visit the GSP FreeBSD Man Page Interface. |