tags:

views:

167

answers:

5

Hi

Let's say I have a simple config file that my c program needs to read/parse.

Let's say it looks a little bit like this:

#Some comment
key1=data1
key2=data2

Is there a standard c lib that I can use instead of writing my own parser?

Thanks Johan


Note: Today I have my own little parser, but there must be some standard libs that solves this simple problem.

+1  A: 

libconfig but it does quite more than what you're asking

f4
a little bit overkill, but I like it.
Johan
A: 

If today you have your own little parser, is there a compelling case for migrating?

The web is full of code snippets where people have done their own little parsers for various things rather than using library code and this is a bad thing.

Like all those crazy the people parsing URLs and decoding before splitting.

But in the case of reading your config file, I can't see the big harm.

Will
Sometimes it is good thing to stop and look around and see if you are missing out on something, and as you say man maybe I will continue to use my own parser in this project. This question was more out of curiosity.
Johan
+1  A: 

http://code.jellycan.com/simpleini/

You can use simple INI files.

FractalizeR
+1  A: 

Why not just use GLIB?

Among countless other things it has library functions for parsing INI like configuration files:

http://library.gnome.org/devel/glib/2.22/glib-Key-value-file-parser.html

Apart from that it also supports Datatypes (Lists, Hashtables, Strings, Caches), Threading, platform neutral abstractions, unit testing, error handling and lots of other great stuff.

For me it's the most useful C library and I would need to have a very good reason to write a C program without using this library.

ahe
+1  A: 

Here's one I've used with success:

http://ndevilla.free.fr/iniparser/

It's small and independent.

Tim Schaeffer