Introduction Example

Conf4C is a library for reading configuration files. Written in C, Conf4C is designed to be a quick accessor library providing small applications simple access to non-XML configuration files.

Conf4C provides applications with a simple way to access name / value pairs specified in a configuration file. With only a few lines of code your application can open, parse, and read a configuration file regardless of comments or blank lines, allowing your application to quickly get to the 'meat' of the configuration. See the Conf4C example section below for more details.

Conf4C supports customized comment markers and name / value delimiters.

Conf4C is free software and part of the GNU Project. The software is licensed under the GNU GPL and is freely available for use.

Conf4C is designed to parse Apache-style configuration files which consist of comments, blank lines, name / value pairs and multiple sections (each with a type and a unique name) each of which contain additional name / value pairs. An example follows...

# A name / value pair consists of a name, a delimiter, and a value
hostname = metatron
ipaddress = 192.168.1.100

# A section is contained within <></> pairs
# and is identified by a section-type and a unique section name
<Directory /opt/users>
  # with more name value pairs
  name = User Directories
  quota = 1024 MB
  allowExceed = No
</Directory>
        

To easily read this the following lines should be included into your applications source...

#include <conf4c.h>

Conf4CFile *c4cf = conf4c_file_new (5, 10);
Conf4CFileAttrib *c4cfattrib = conf4c_fileattrib_new ("#", 
                                                      "=", 
                                                      CONF4C_DELIM_LAZY);
Conf4CParser *c4cp = conf4c_parser_new (c4cf, c4cfattrib);

conf4c_parser_parse (c4cp);

Conf4CReader *c4cr = conf4c_reader_new (c4cf);
        

Once the Conf4CParser has completed executing the conf4c_parser_parse () function the Conf4CFile will be populated with all the name / values of the configuration file. To easily read the parsed values create a Conf4CReader to iterate easily through the name / value pairs, section-types, and section names.

For more details see the Conf4C Tutorial.