Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 May 2000 10:01:36 +0200
From:      Martin Cracauer <cracauer@cons.org>
To:        A G F Keahan <ak@freenet.co.uk>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Generic config file parser?
Message-ID:  <20000529100136.A97382@cons.org>
In-Reply-To: <3931B325.BB166270@freenet.co.uk>; from ak@freenet.co.uk on Mon, May 29, 2000 at 02:00:37AM %2B0200
References:  <3931B325.BB166270@freenet.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
In <3931B325.BB166270@freenet.co.uk>, A G F Keahan wrote: 
> This may be a silly question, but is there such a thing?    Almost every
> program that I know uses configuration files, often in different,
> incompatible formats.   I personally prefer Samba/Wine-style config
> files which are split into "sections" like this:
> 
> [SECTIONNAME1]
> wibble1 = blah
> wibble2 = 35
> wibble3 = "a string that has more than one word"
> ; this is a comment -- ignored
> wibble4 = 4.567e9
> 
> What I'm after is some kind of a generic parser function, which you can
> give a section name "SECTIONNAME1"), a token name (e.g. "wibble1"), a
> separator (e.g. "=", ":", or white space ""), and a variable of some
> type (char *, int, float, etc), and have it return "true" and the
> requested value if it exists, or "false" if the value was not found or
> datatype was incorrectly specified.   Similarly, I want to be able to
> save a value into a given section of the file, possibly replacing an
> existing value, or adding a new one.

It's exactly this what XML is for.  It gives you a generic way to
define file syntaxes, so that not only your program can read it, but
also generic file checkers, GUI tools that support other people in
writing such files in environments they like.  Also, its would be easy
to use in one of the many languages that have a XML library (no need
to use a foreign interface to your C library).

The syntax can easily include collections of all kinds, including
trees, which is more difficult to make in home-grown parsers.  At
least the history of my applications using config files shows that
sooner or later things become more complex and need such features.
The usual way to hack around the problem is to put collections in
strings, which breaks the normal syntax error reporting.

I have to admit that my main ASCII-parsing application still uses a
hack-up C++ (urgs) parser, basically since I didn't find a sufficient
XML parsing library for C so far, but the mess is incredible (the
applications will be 10 years out this summer).  I can only advice you
to use synaxtes that could (not necessarily from start) be parsed by
existing technology that leave roon for syntax expansion.

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
BSD User Group Hamburg, Germany     http://www.bsdhh.org/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000529100136.A97382>