[Main page] [Overview]   /basic /configfile
SYNOPSIS
#include <defs>
inherit /basic/configfile;
FILE
/basic/configfile.c
DESCRIPTION
The config file parser provides functions - for reading
(into a mapping) and writing (into a specified file) - from
special configuration files. See the documentation of
read_ini_conf and write_ini_conf for details on the function calls.
An example config file:
key0=value0
key1=value1
array0=<<EOA
item0
item1
item2
item3
EOA
key2=value2
[new_section]
# comment
key0=value0
key1=value1
This config file would result in the following mapping:
mapping map = (["main":([key0:value0,key1:value1,
array0:({item0,item1,item2,item3)},
key2:value2]),
"new_section":([key0:value0,key1:value1]),
]);
Everything in the file before a section was explicitely opened
through [name] is put into [main]. You can open any section
again later in the file and write more keys into it. Sections
will not be overwritten in contrary to a key in a section,
wich, if specified more than one time, will equal to the last
assigned value.
Arrays are constructed by <<DELIMITER. The delimiter can take
any value as long as it is correctly repeated on a single line
where the array's items should end. It's suggested to use EOA
since that's the delimiter used by the write_conf function and
will conventionally not be used as an array value.
There may be spaces between the '=' and the keys/values. They
will be trimmed. Also the parser strips off \t and \r (for
compatibility to windows-generated files and their crlf ending
sequence). So you can use indents to make your configurations
more readable. But note that configuration files written by the
write_conf function are always in the simplest shape, and, due
to the internal structure of mappings, not neccessarily in the
same order as you may have put it in the initial way. By the
way, you can use a leading # to mark comment lines in your
configuration.
Regarding the used data types: If a config file is read in, all
integer values will be strings. You may have to convert them.
The other way, you don't have to bother if you send integers
out in the mapping which is written into a file, there they will
be converted into strings. So you can use the following data
types and structures: strings, integers and mixed arrays of
strings and integers.
SUBTOPICS