Readconfig Notes

Readconfig was created due to a desperate need to have a config parser for a program I'm working on. I'd been writing config parsers per program and it was beginning to be a big pain. The method I've been using has been something like this:
  1. Think of functionality
  2. Think of configuration
  3. Add elements to config file to manage new features
  4. Add elements into configuration parser to manage new feature configuration
  5. Do implementation
  6. Do new features (goto 2)
What I wanted, was a way to do it without the config parser knowing what it's doing, to the point where the config parser didn't know anything but what file it needed to parse. Then the program just asks it for the value of variables. That way, you end up with something more like this:
  1. Think of functionality
  2. Think of configuration
  3. Do configuration
  4. Do implementation
  5. As new features are added (goto 2)
Wow, that was the first time I've used goto since Saturn assembly...

Anyway, this isn't a new concept, but I've not found any library that does this in a completely isolated manner, so the program and the config reader can be seperate. Now, the program just requests config info by name when it needs it.

This is an example config file:

/*
   C style comments work
*/

// C++, too (oh, and whitespace is ignored)

# And bourne if you dig that kind of thing

avariable=itsvalue;
anothervariable="A string value";

# This is an example of a subsection
tree {
    type="broadleaf";
    branch1
    {
	color=blue;
	broken=1;
    }

    size="big";

    branch2 { color=orange; }
}

The parser doesn't care what's in the file, just what the file looks like. Sections and subsections can be created (recursively), and variables can be defined and referenced from whatever section they exist in.

In this example, the table to the right (for lynx users, the garbage looking blob below) shows which variables were parsed from the config file, and how they can be referenced from the program.

Variable Value
avariable itsvalue
anothervariable A string value
tree.type broadleaf
tree.size big
tree.branch1.color blue
tree.branch1.broken 1
tree.branch2.color orange

There is a working model of this in use right now, but it won't be available for another week or so. If you'd like more information before then, please send E-mail to dustin@spy.net.