A (long) while back I changed the config system in gmpc. The old system was very nasty.
I had one big struct with all the elements in there. Anywhere in the program I would set the values/read them and on exit I wrote them to a file.
This had a few problems, if gmpc didn’t exit normally, all changes where gone. Not easy to extend, you had to add a field to the struct, initialize it at program start, and make it read/write it to the config file.
So I changed it to something dynamic. You start the program you create a config object:
config_obj *config = config_open("configfile.xml");
Then you can read and set config file like:
cfg_get_single_value_as_int(config, "connection", "port");
Or with a default setting if you want:
cfg_get_single_value_as_int_with_default(config, "connection", "port", 6600)
This all works very nice, I don’t see any reason to change the interface. But I’ve been getting alot of comments that the config file isn’t human readable anymore (it’s an xml file).
So my mission for today is, changing the config file to something human readable.
There are 2 things that I can do.
- Keep the xml internally, write a custom save/open function.
- Re-design the whole thing.
I think I go for the last one.
Wish me luck.