\input texinfo.tex @c -*-texinfo-*-
@c
@c %**start of header
@c All text is ignored before the setfilename.
@setfilename libconfig.info
@settitle libconfig
@set edition 1.4.8
@set update-date 4 August 2011
@set subtitle-text A Library For Processing Structured Configuration Files
@set author-text Mark A.@: Lindner
@comment %**end of header
@dircategory Software libraries
@direntry
* libconfig: (libconfig). A Library For Processing Structured Configuration Files
@end direntry
@tex
\global\emergencystretch = .3\hsize
@end tex
@setchapternewpage odd
@titlepage
@title libconfig
@subtitle @value{subtitle-text}
@subtitle Version @value{edition}
@subtitle @value{update-date}
@author @value{author-text}
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 2005-2011 Mark A Lindner
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
@end titlepage
@c Give the HTML output a title page that somewhat resembles the printed one
@ifhtml
@html
@value{subtitle-text}
Version @value{edition}
@value{update-date}
@value{author-text}
@end html
@end ifhtml
@contents
@ifnottex
@node Top
@comment node-name, next, previous, up
@top libconfig
@end ifnottex
@menu
* Introduction::
* Configuration Files::
* The C API::
* The C++ API::
* Example Programs::
* Configuration File Grammar::
* License::
* Function Index::
* Type Index::
* Concept Index::
@end menu
@node Introduction, Configuration Files, Top, Top
@comment node-name, next, previous, up
@menu
* Why Another Configuration File Library?::
* Using the Library from a C Program::
* Using the Library from a C++ Program::
* Multithreading Issues::
* Internationalization Issues::
* Compiling Using pkg-config::
* Version Test Macros::
@end menu
@chapter Introduction
@i{Libconfig} is a library for reading, manipulating, and writing
structured configuration files. The library features a fully
reentrant parser and includes bindings for both the C and C++
programming languages.
The library runs on modern POSIX-compilant systems, such as Linux,
Solaris, and Mac OS X (Darwin), as well as on Microsoft Windows
2000/XP and later (with either Microsoft Visual Studio 2005 or later,
or the GNU toolchain via the MinGW environment).
@node Why Another Configuration File Library?, Using the Library from a C Program, , Introduction
@comment node-name, next, previous, up
@section Why Another Configuration File Library?
There are several open-source configuration file libraries available
as of this writing. This library was written because each of those
libraries falls short in one or more ways. The main features of
@i{libconfig} that set it apart from the other libraries are:
@itemize @bullet
@item A fully reentrant parser. Independent configurations can be parsed in concurrent threads at the same time.
@item Both C @i{and} C++ bindings, as well as hooks to allow for the creation of wrappers in other languages.
@item A simple, structured configuration file format that is more
readable and compact than XML and more flexible than the obsolete but
prevalent Windows ``INI'' file format.
@item A low-footprint implementation (just 37K for the C library and 76K for
the C++ library) that is suitable for memory-constrained systems.
@item Proper documentation.
@end itemize
@node Using the Library from a C Program, Using the Library from a C++ Program, Why Another Configuration File Library?, Introduction
@comment node-name, next, previous, up
@section Using the Library from a C Program
To use the library from C code, include the following preprocessor
directive in your source files:
@sp 1
@smallexample
#include
@end smallexample
@sp 1
To link with the library, specify @samp{-lconfig} as an argument to the
linker.
@node Using the Library from a C++ Program, Multithreading Issues, Using the Library from a C Program, Introduction
@comment node-name, next, previous, up
@section Using the Library from a C++ Program
To use the library from C++, include the following preprocessor
directive in your source files:
@sp 1
@smallexample
#include
@end smallexample
@sp 1
Or, alternatively:
@sp 1
@smallexample
#include
@end smallexample
@sp 1
@page
The C++ API classes are defined in the namespace @samp{libconfig}, hence the
following statement may optionally be used:
@sp 1
@smallexample
using namespace libconfig;
@end smallexample
@sp 1
To link with the library, specify @samp{-lconfig++} as an argument to
the linker.
@node Multithreading Issues, Internationalization Issues, Using the Library from a C++ Program, Introduction
@comment node-name, next, previous, up
@section Multithreading Issues
@i{Libconfig} is fully @dfn{reentrant}; the functions in the library
do not make use of global variables and do not maintain state between
successive calls. Therefore two independent configurations may be safely
manipulated concurrently by two distinct threads.
@i{Libconfig} is not @dfn{thread-safe}. The library is not aware of
the presence of threads and knows nothing about the host system's
threading model. Therefore, if an instance of a configuration is to be
accessed from multiple threads, it must be suitably protected by
synchronization mechanisms like read-write locks or mutexes; the
standard rules for safe multithreaded access to shared data must be
observed.
@i{Libconfig} is not @dfn{async-safe}. Calls should not be made into
the library from signal handlers, because some of the C library
routines that it uses may not be async-safe.
@i{Libconfig} is not guaranteed to be @dfn{cancel-safe}. Since it is
not aware of the host system's threading model, the library does not
contain any thread cancellation points. In most cases this will not be
an issue for multithreaded programs. However, be aware that some of
the routines in the library (namely those that read/write
configurations from/to files or streams) perform I/O using C library
routines which may potentially block; whether or not these C library
routines are cancel-safe depends on the host system.
@node Internationalization Issues, Compiling Using pkg-config, Multithreading Issues, Introduction
@comment node-name, next, previous, up
@section Internationalization Issues
@cindex Unicode
@cindex UTF-8
@i{Libconfig} does not natively support Unicode configuration files,
but string values may contain Unicode text encoded in UTF-8; such
strings will be treated as ordinary 8-bit ASCII text by the
library. It is the responsibility of the calling program to perform
the necessary conversions to/from wide (@t{wchar_t}) strings using the
wide string conversion functions such as @t{mbsrtowcs()} and
@t{wcsrtombs()} or the @t{iconv()} function of the @i{libiconv}
library.
@cindex locale
The textual representation of a floating point value varies by
locale. However, the @i{libconfig} grammar specifies that
floating point values are represented using a period (`.') as the
radix symbol; this is consistent with the grammar of most programming
languages. When a configuration is read in or written out,
@i{libconfig} temporarily changes the @t{LC_NUMERIC} category of the
locale of the calling thread to the ``C'' locale to ensure consistent
handling of floating point values regardless of the locale(s) in use
by the calling program.
Note that the MinGW environment does not (as of this writing) provide
functions for changing the locale of the calling thread. Therefore,
when using @i{libconfig} in that environment, the calling program is
responsible for changing the @t{LC_NUMERIC} category of the locale to
the "C" locale before reading or writing a configuration.
@node Compiling Using pkg-config, Version Test Macros, Internationalization Issues, Introduction
@comment node-name, next, previous, up
@section Compiling Using pkg-config
On UNIX systems you can use the @i{pkg-config} utility (version 0.20
or later) to automatically select the appropriate compiler and linker
switches for @i{libconfig}. Ensure that the environment variable
@code{PKG_CONFIG_PATH} contains the absolute path to the
@file{lib/pkgconfig} subdirectory of the @i{libconfig} installation. Then,
you can compile and link C programs with @i{libconfig} as follows:
@smallexample
gcc `pkg-config --cflags libconfig` myprogram.c -o myprogram \
`pkg-config --libs libconfig`
@end smallexample
@sp 1
And similarly, for C++ programs:
@smallexample
g++ `pkg-config --cflags libconfig++` myprogram.cpp -o myprogram \
`pkg-config --libs libconfig++`
@end smallexample
@sp 1
Note the backticks in the above examples.