You are not logged in.

#1 2010-04-30 01:10:38

Basu
Member
From: Cornell University
Registered: 2006-12-15
Posts: 296
Website

Writing user configurable C programs

I'm interested in writing a small server in pure C, but I'd like users to be able to configure some things (like the directory to be served) by plain text config files. Is there an easy/standard way to do this in C? I would like to avoid the following:

1. making yet another ad-hoc config language
2. writing a parser for said ad-hoc config language
3. embedding a full scripting language (like Lua)

Right now, I'm thinking of using something like YAML which has a C library for it, but I'm open to other suggestions.
Thanks,
Basu


The Bytebaker -- Computer science is not a science and it's not about computers
Check out my open source software at Github

Offline

#2 2010-04-30 05:06:48

Kiwi
Member
Registered: 2008-02-24
Posts: 153

Re: Writing user configurable C programs

If you like the style of pacman.conf it is a pretty easy parser to implement and use. Since it is already in C you do not even have to think that much. tongue

*wrote it in Lua*

Offline

#3 2010-04-30 06:45:37

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: Writing user configurable C programs

Both of these look promising if you don't want to embed python, lua, etc:

http://www.hyperrealm.com/libconfig/

http://liblcfg.carnivore.it/

Offline

#4 2010-05-02 13:05:56

AndreasBWagner
Member
From: Boston, MA, USA
Registered: 2010-03-05
Posts: 17
Website

Re: Writing user configurable C programs

Glib comes with a nice ini-like config parser.
Using Glib's GKeyFile Parser

Also, consider using the XDG Base Directory Specification. I'm trying to get more people to use it because it keeps the $HOME directory clean and it separates config, data and cache. You can use the libxdg-basedir for this.

Last edited by AndreasBWagner (2010-05-02 13:06:37)

Offline

Board footer

Powered by FluxBB