Off-topic: Configuration file parser

Forrest J. Cavalier III mibsoft at epix.net
Mon Jul 26 14:25:34 UTC 2004


I wrote a configuration file parser for a different project.
The syntax is similar to the INN configuration file.

I am not writing here to suggest that INN use this code or syntax.
(That change would be a lot of work, but not an insane amount for
the gains....)  I just thought maybe some ideas might make it into
the INN conf file parser eventually.

The file syntax is documented here:

    http://www.mibsoftware.com/librock/data/attributes_file.htm

(and that page has links to the API documentation.)

Some features above the INN-style parser:

    - Files can have conditional sections.

    - The file syntax permits expressions and variable substitution in
      assignments and tests for conditional sections.

    - Extensibility hooks are provided.  You can add different calls
      and function types for example.

    - The typical use example shows how to create an implementation which
      exposes the environment variables inside expressions and
      interpreted strings.

    - There is example code for filling in a linked list of structures
      using attributes and default attributes.

        http://www.mibsoftware.com/librock/data/xattrib.c

    This example makes it easy to retrofit existing designs.  You
    basically need to code a "set" function to map attribute names to
    structure elements, and cut-and-paste the rest of the example code.

One interesting implementation choice concerns lists and groups of
nestable sections.  I know this is a complicated part of the INN
lexer and parser.

I chose to do this by prefixing the variable names, so that the
output remains in a flat non-hierarchical list, which is easier to
implement and iterate.  Just as an example of this, an attributes file with:
    param=c
    {
    .prefix groupname.
    param=b
    }

results in a flat attributes list of:

    groupname.param=b
    param=c

Even with the extra features, the C line count ends up being a bit
lower than INN's conffile.c+confparse.c combination.

The source is available at no cost in tar.gz format under the MIT
software license for use however you like.  It has been tested on
BSD with gcc, and Win32 with MSVC.

Email or call if you want it.  (Spam being what it is today, if we try
to exchange email, it has a good chance of getting discarded unless
senders are in whitelists first.  So you might want to call.)

Forrest J. Cavalier III
Mib Software
Voice: 570-992-8824



More information about the inn-workers mailing list