J
John Doe
I've been doing some reading/research on parsing simple configuration
files through C, and have heard various opinions on the matter. I'd like
to solicit some opinions and design criteria (as well as "gotchas") for
doing this.
I'm implementing a program that needs to read a standard configuration
file, in key=value pairs for starters (though I'm open to other ideas).
Basically it would be no more than about 20 lines total, one key per line.
Something like the following:
foo = bar
port = /dev/ttyS0
user = John Q. Public
backup = $HOME/backup
I've also seen suggestions about breaking this up into the "Windows'y"
..ini file syntax, so that could be reconstructed to be something like:
[global]
foo = bar
[ports]
port = /dev/ttyS0
[user]
user = John Q. Public
[path]
backup = $HOME/backup
Either method of storage is fine, though it gets a bit harder parsing out
global blocks. The other thing that could get complicated, is the presence
of /etc/foo/foorc and $HOME/.foorc. Which overrides which? What about
merging settings?
I've looked at the following links, but they're all MUCH larger than I
need for this project:
Coman - LGPL - http://www.digitaltunnel.com/~lepware/coman/ChangeLog
GConf - LGPL - http://cvs.gnome.org/lxr/source/gconf/ChangeLog
Conf - GPL - http://www.cs.vu.nl/~bernsti/conf/index.html
dot.conf - GPL - http://www.azzit.de/dotconf/
Keeper - LGPL - http://www.inf.bme.hu/~mszeredi/keeper/
libconf - GPL - http://metalab.unc.edu/pub/Linux/libs/
libproplist - LGPL - http://www.windowmaker.org/src/lPL/ChangeLog
parsecfg - LGPL - http://www.enjoy.ne.jp/~gm/program/parsecfg/
Another option that was thrown my way, was to use lexx/yacc to create the
parser and logic for this. I'm completely unfamiliar with lexx/yacc for
this, so I don't know where to start. An hour of googling didn't produce
much of anything I could use for an jumping point to get me started.
Lastly, the old standby.. XML. In this case, XML would be a good storage
method for my config variables, but my project would then require an
additional dependancy on libxml or expat (which isn't a validating
parser).
Ideas? Code snippets? URLs I can check for insight?
Thanks in advance.
files through C, and have heard various opinions on the matter. I'd like
to solicit some opinions and design criteria (as well as "gotchas") for
doing this.
I'm implementing a program that needs to read a standard configuration
file, in key=value pairs for starters (though I'm open to other ideas).
Basically it would be no more than about 20 lines total, one key per line.
Something like the following:
foo = bar
port = /dev/ttyS0
user = John Q. Public
backup = $HOME/backup
I've also seen suggestions about breaking this up into the "Windows'y"
..ini file syntax, so that could be reconstructed to be something like:
[global]
foo = bar
[ports]
port = /dev/ttyS0
[user]
user = John Q. Public
[path]
backup = $HOME/backup
Either method of storage is fine, though it gets a bit harder parsing out
global blocks. The other thing that could get complicated, is the presence
of /etc/foo/foorc and $HOME/.foorc. Which overrides which? What about
merging settings?
I've looked at the following links, but they're all MUCH larger than I
need for this project:
Coman - LGPL - http://www.digitaltunnel.com/~lepware/coman/ChangeLog
GConf - LGPL - http://cvs.gnome.org/lxr/source/gconf/ChangeLog
Conf - GPL - http://www.cs.vu.nl/~bernsti/conf/index.html
dot.conf - GPL - http://www.azzit.de/dotconf/
Keeper - LGPL - http://www.inf.bme.hu/~mszeredi/keeper/
libconf - GPL - http://metalab.unc.edu/pub/Linux/libs/
libproplist - LGPL - http://www.windowmaker.org/src/lPL/ChangeLog
parsecfg - LGPL - http://www.enjoy.ne.jp/~gm/program/parsecfg/
Another option that was thrown my way, was to use lexx/yacc to create the
parser and logic for this. I'm completely unfamiliar with lexx/yacc for
this, so I don't know where to start. An hour of googling didn't produce
much of anything I could use for an jumping point to get me started.
Lastly, the old standby.. XML. In this case, XML would be a good storage
method for my config variables, but my project would then require an
additional dependancy on libxml or expat (which isn't a validating
parser).
Ideas? Code snippets? URLs I can check for insight?
Thanks in advance.