libconfini
Yet another INI parser
|
Yet another INI parser
libconfini is the ultimate and most consistent INI file parser library written in C. Originally designed for parsing configuration files written by other programs, 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, stdbool.h and stdint.h (and for extreme platforms the code can be also compiled as “bare metal”, with few or no strings attached to the C Standard Library).
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 that you would normally find in other heavily structured formats (such as JSON, YAML, TOML), but with the advantage of using the most human-friendly configuration format ever invented (thanks to their informal status, INI files are indeed more fluid, expressive and human-friendly than formats explicitly designed with the same purpose, such as YAML and TOML). The library's main goal is to be uncommonly powerful in the most tedious and error-prone task when parsing a text file in C: string handling. Thanks to this, the programmer is left free to organize the content parsed as (s)he pleases, assisted by a rich set of fine-tuning tools.
[foo]
; absolute nesting, as in [foo.bar]
; relative nesting, as in [.bar]
)"Hello world"
and "He"l'lo' world
, or between foo bar
and foo bar
)CR
, Unix' LF
, Windows' CR
+LF
, RISC OS Open's LF
+CR
)log.ini:
example.c:
Output:
If you are using C++, under examples/cplusplus/map.cpp
you can find a snippet for storing an INI file into a class that relies on a std::unordered_map
object.
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).
Despite the small footprint, libconfini has been conceived as a shared library (but it can be used as a static library as well). An automatic list of the distributions that ship the library already compiled is available here.
If a pre-compiled package for your platform is not available, on most Unix-like systems it is possible to install libconfini using the following common steps:
If the strip
utility is not available on your machine, use make install
instead (it will produce larger binaries)
For a minimum installation without development files (i.e. static libraries, headers, documentation, examples, etc.) use ./configure --disable-devel
.
If the configure
script is missing you need to generate it by running the bootstrap
script. By default, bootstrap
will also run the configure
script immediately after having generated it, so you may type the make
command directly after bootstrap
. To list different options use ./bootstrap --help
.
If you are using Microsoft Windows, a batch script for compiling libconfini with MinGW without Bash is available (mgwmake.bat
). If you are interested in using GNU Make for compiling libconfini, you can integrate MinGW with MSYS, or you can directly use MSYS2 and its official port of the library. Alternatively, an unofficial port of libconfini for Cygwin is available.
For further information, see INSTALL.
Danilo Spinella maintains a D binding package of libconfini.
This library is free software. You can redistribute it and/or modify it under the terms of the GPL license version 3 or any later version. See COPYING for details.