Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 May 2000 02:00:37 +0200
From:      A G F Keahan <ak@freenet.co.uk>
To:        freebsd-hackers@freebsd.org
Subject:   Generic config file parser?
Message-ID:  <3931B325.BB166270@freenet.co.uk>

next in thread | raw e-mail | index | archive | help
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.

A trivial thing to write, and a very useful one -- surely it's been done
before, no?

Alex


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?3931B325.BB166270>