views:

43

answers:

2

My code uses a text based conf file with key=value type entries. I want to add sections feature for file, i.e. search for number of sections, search for particular key in a section.

I was wondering if there are any libraries/functions which already does this, that I can reuse. My suspicion is yes, since lot of gnu software uses such files. If getopt for cmd line flags exists, something like a conf file reader should also exist. But I just can't find it. Any information is appreciated.

+2  A: 

Glib provides functions for reading 'key=value' type configuration files. See: http://library.gnome.org/devel/glib/stable/glib-Key-value-file-parser.html.

Kyle Lutz
Thank you, exactly what I was looking for
+1  A: 

Unfortunately, there is a lot of variation with the syntax for those files. There are a couple libraries which do this, it looks like GConf and libconfig might be what you're looking for.

In situations like these, I sometimes peek at the source code to Git to see how it's handled there.

Dietrich Epp
URLs? They improve the quality of an answer like this immensely. I know I can probably Google them up - but it is even more convenient not to have to do so.
Jonathan Leffler
Yes, libconfig http://www.hyperrealm.com/libconfig/ looks quite nice!
Matt Joiner
There are at least two separate libconfig libraries that could be intended: http://www.hyperrealm.com/libconfig/ (version 1.4.1) and http://sourceforge.net/projects/libconfig/ (version 0.2). The GConf library is a section of Gnome: http://projects.gnome.org/gconf/.
Jonathan Leffler