From owner-freebsd-hackers Mon May 29 1: 1:44 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from gilgamesch.bik-gmbh.de (T1-Hansenet.BIK-GmbH.de [192.76.134.246]) by hub.freebsd.org (Postfix) with ESMTP id 1FC2437BBF5 for ; Mon, 29 May 2000 01:01:41 -0700 (PDT) (envelope-from cracauer@gilgamesch.bik-gmbh.de) Received: (from cracauer@localhost) by gilgamesch.bik-gmbh.de (8.9.3/8.7.3) id KAA97756; Mon, 29 May 2000 10:01:36 +0200 (MET DST) Date: Mon, 29 May 2000 10:01:36 +0200 From: Martin Cracauer To: A G F Keahan Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Generic config file parser? Message-ID: <20000529100136.A97382@cons.org> References: <3931B325.BB166270@freenet.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <3931B325.BB166270@freenet.co.uk>; from ak@freenet.co.uk on Mon, May 29, 2000 at 02:00:37AM +0200 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 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