libconfini
Yet another INI parser
README

Yet another INI parser

libconfini is the ultimate and most consistent INI file parser library written in C. It focuses on standardization and parsing exactness and is at ease with almost every type of file containing key/value pairs.

The library is fast and suitable for embedded systems. Its algorithms are written from scratch and do not depend on any external library, except for the C standard headers stdio.h, stdlib.h and stdint.h.

Rather than storing the parsed data, libconfini gives the developer the freedom to choose what to do with them through a custom callback invoked for each INI node read. The API has been designed to be powerful, flexible and simple to use.

With libconfini you will find in INI files the same serialization power you would normally find in other heavily structured formats (such as JXON, YAML, TOML), but with the advantage of using the most human-readable configuration format ever invented (thanks to their informal status, INI files are indeed more fluid and human-readable than formats explicitly designed with this purpose, such as YAML and TOML).

Features

Sample usage

log.ini:

[users]
have_visited = ronnie, lilly82, robrob
[last_update]
date = 12.03.2017

example.c:

#include <confini.h>
static int callback (IniDispatch * disp, void * v_other) {
#define IS_KEY(SECTION,KEY) \
(ini_array_match(SECTION, disp->append_to, '.', disp->format) && \
ini_string_match_ii(KEY, disp->data, disp->format))
if (disp->type == INI_KEY) {
if (IS_KEY("users", "have_visited")) {
/* No need to parse this field as an array right now */
printf("People who have visited: %s\n", disp->value);
} else if (IS_KEY("last_update", "date")) {
printf("Last update: %s\n", disp->value);
}
}
#undef IS_KEY
return 0;
}
int main () {
if (load_ini_path("log.ini", INI_DEFAULT_FORMAT, NULL, callback, NULL)) {
fprintf(stderr, "Sorry, something went wrong :-(\n");
return 1;
}
return 0;
}

Output:

People who have visited: ronnie, lilly82, robrob
Last update: 12.03.2017

For more details, please read the Library Functions Manual (man libconfini – a standalone HTML version is available here) and the manual of the header file (man confini.h). The code is available on GitHub under madmurphy/libconfini).

Installation

Despite the small footprint (34 kB of compiled binary using GCC), libconfini has been conceived as a shared library (but it may be used as a static library as well).

On most Unix-like systems, it is possible to install libconfini using the following common steps:

./configure
make
make install

If the configure script is missing from your package you need to generate it by running the autogen.sh script. By default autogen.sh will also run the configure script immediately after having generated it, so you may directly type the make command directly after autogen.sh. To list different options use autogen.sh --help.

An unofficial port of libconfini for Cygwin is also available.

Free software

This library is free software. You can redistribute it and/or modify it under the terms of the GPL3 license. See COPYING for details.