From owner-freebsd-hackers Sun May 28 16:13:12 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from nts.mapisrael.com (nts.mapa.co.il [192.116.157.1]) by hub.freebsd.org (Postfix) with ESMTP id 7B0E837BB20 for ; Sun, 28 May 2000 16:13:08 -0700 (PDT) (envelope-from ak@freenet.co.uk) Received: from freenet.co.uk (ALEX [192.116.157.120]) by nts.mapisrael.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id LRLMW5VX; Mon, 29 May 2000 02:01:15 +0200 Message-ID: <3931B325.BB166270@freenet.co.uk> Date: Mon, 29 May 2000 02:00:37 +0200 From: A G F Keahan X-Mailer: Mozilla 4.72 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Generic config file parser? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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