- Notifications
You must be signed in to change notification settings - Fork27
madmurphy/libconfini
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
libconfini is the ultimate and most consistent INI file parser librarywritten in C. Originally designed for parsing configuration files written byother programs, it focuses on standardization and parsing exactness and is atease with almost every type of file containing key/value pairs.
The library is fast and suitable for embedded systems. Its algorithms arewritten from scratch and do not depend on any external library, except for theC standard headersstdio.h,stdlib.h,stdbool.h andstdint.h(and for extreme platforms the codecan 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 thefreedom to choose what to do with them through a custom callback invoked foreach INI node read. The API has been designed to be powerful, flexible andsimple to use.
Withlibconfini you will find in INI files the same serialization powerthat you would normally find in other heavily structured formats (such as JSON,YAML, TOML), but with the advantage of using the most human-friendlyconfiguration format ever invented (thanks to their informal status, INI filesare indeed more fluid, expressive and human-friendly than formats explicitlydesigned with the same purpose, such as YAML and TOML). The library's main goalis to be uncommonly powerful in the most tedious and error-prone task whenparsing a text file in C: string handling. Thanks to this, the programmer isleft free to organize the content parsed as (s)he pleases, assisted by a richset of fine-tuning tools.
- Typed data support (each value can be parsed as a boolean, a number, astring, an array)
- Single/double quotes support inBash style (i.e. quotes can be opened andclosed multiple times within the same value)
- Multi-line support
- Comment support
- Disabled entry support
- INI sectioning support (single-level sectioning, as in
[foo]; absolutenesting, as in[foo.bar]; relative nesting, as in[.bar]) - Automatic sanitization of values, key names and section paths
- Comparison functions designed just for INI source code (capable, for example,to recognize the equality between
"Hello world"and"He"l'lo' world, or betweenfoo barandfoo bar) - Callback pattern
- Thread-safety (each parsing process is fully reentrant)
- Highly optimized code (single memory allocation for each parsing, heuristicprogramming, optimization flags)
- Function modularity (each public function is independent from all otherpublic functions)
- K.I.S.S. (no public functions are automatically invoked during the parsing --for example, not even single/double quotes are automatically removed fromvalues unless the developer explicitly decides to use the formattingfunctions provided by the API)
- Robust and cross-platform file access (UTF-8 support; protection against nullbyte injection; support of all code representations of new lines -- i.e.ubiquitous support of Classic Mac OS'
CR, Unix'LF, Windows'CR+LF,RISC OS Open'sLF+CR)
log.ini:
[users]have_visited = ronnie, lilly82, robrob[last_update]date = 12.03.2017
example.c:
#include<confini.h>staticintcallback (IniDispatch*disp,void*v_other) {#defineIS_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); }elseif (IS_KEY("last_update","date")) {printf("Last update: %s\n",disp->value); } }#undef IS_KEYreturn0;}intmain () {if (load_ini_path("log.ini",INI_DEFAULT_FORMAT,NULL,callback,NULL)) {fprintf(stderr,"Sorry, something went wrong :-(\n");return1; }return0;}
Output:
People who have visited: ronnie, lilly82, robrobLast update: 12.03.2017If you are using C++, underexamples/cplusplus/map.cpp you can find a snippetfor storing an INI file into a class that relies on astd::unordered_mapobject.
For more details, please read theLibrary Functions Manual (man libconfini) -- a standalone HTML version is availablehere -- and themanual of the header file (man confini.h). The code is available onGitHub undermadmurphy/libconfini).
Despite the small footprint,libconfini has been conceived as a sharedlibrary (but it can be used as a static library as well). An automatic list ofthe distributions that ship the library already compiled is availablehere.
If a pre-compiled package for your platform is not available, on most Unix-likesystems it is possible to installlibconfini using the following commonsteps:
./configuremakemake install-strip
If thestrip utility is not available on your machine, usemake installinstead (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 theconfigure script is missing you need to generate it by running thebootstrap script. By default,bootstrap will also run theconfigurescript immediately after having generated it, so you may type themakecommand directly afterbootstrap. To list different options use./bootstrap --help.
If you are usingMicrosoft Windows, a batch script for compilinglibconfini withMinGW withoutBash is available(mgwmake.bat). If you are interested in usingGNU Make for compilinglibconfini, you can integrateMinGW withMSYS, or you candirectly useMSYS2 andits official port of the library.Alternatively,an unofficial port oflibconfini forCygwinis available.
For further information, seeINSTALL.
Danilo Spinella maintainsa D binding package oflibconfini.
This library is free software. You can redistribute it and/or modify it underthe terms of the GPL license version 3 or any later version. SeeCOPYINGfor details.
About
Yet another INI parser
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.