tags:

views:

125

answers:

4

I'm writing an INI-like configuration file and I want to know the best way to parse it in C/C++. I'm writing it on POSIX, so I'll be using # instead of ;. Which doesn't matter. I just want to know, is there some kind of tutorial, article on parsing things or something.

+3  A: 

There are lots of tutorials and articles on parsing, but what you're dealing with is so trivial that most of them will probably be overkill.

Given how often this has been done before, I'd start by looking at some of the existing code that already implements almost what you want.

Jerry Coffin
+2  A: 

There are plenty of open source libraries out there already which you can probably use with little or no modification, e.g. libini.

Paul R
Ah yes, but my main set back is how to include them in my GPL application. I don't know with BSD licenses how to give copyright in my application binaries.
Jookia
@Jookia: maybe you could ask a separate question here on SO about the licensing/copyright issue to get a solution to that problem ?
Paul R
+1  A: 

As often in C++ basic stuffs, boost have a library that can read ini files. In fact there is two libs, depending on what you want to achieve :

Klaim
A: 

Depending on how much complexity you actually need, you might get away with just using fgets() in a loop, and parsing each line manually (e.g. with strstr(), strchr(), strcmp(), etc). There's little point in dragging in a parsing library if you're just going to need to grab a few values.

Jeremy Friesner