From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 14 15:59:26 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EF62616A4CE for ; Wed, 14 Apr 2004 15:59:26 -0700 (PDT) Received: from web10505.mail.yahoo.com (web10505.mail.yahoo.com [216.136.130.155]) by mx1.FreeBSD.org (Postfix) with SMTP id CA98D43D2F for ; Wed, 14 Apr 2004 15:59:26 -0700 (PDT) (envelope-from b_oshea@yahoo.com) Message-ID: <20040414225922.41892.qmail@web10505.mail.yahoo.com> Received: from [156.153.254.41] by web10505.mail.yahoo.com via HTTP; Wed, 14 Apr 2004 15:59:22 PDT Date: Wed, 14 Apr 2004 15:59:22 -0700 (PDT) From: Brian O'Shea To: Brandon Erhart , Craig Rodrigues In-Reply-To: <6.0.2.0.2.20040414162810.01c8cb48@mx1.erhartgroup.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii cc: freebsd-hackers@freebsd.org Subject: Re: C code for parsing rc.conf? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Apr 2004 22:59:27 -0000 --- Brandon Erhart wrote: > Not that I know of, but it should be a breeze to write a simple parsing > engine. > Just ignore all lines starting with a '#', and break at the '=' sign. The > first part would be your variable name, the last part your value for it. Don't forget to deal with quotes: some_variable="Double-quoted value" - or - some_other_variable='Single-quoted value' Not to mention lines with trailing comments: some_variable="Some Value" # Set some variable to some value. And, as somebody else pointed out, some other embedded shell syntax (which might contain an equal sign, so just blindly splitting lines on equal signs won't work): if [ "$some_variable" = "NO" ]; then # do something here... fi Remember that /etc/rc.conf is just a shell script, and so it is parsed by the shell interpreter (/bin/sh). You might end up writing a shell parser if you want to cover all possibilities! (in other words, re-inventing the wheel.) Be careful. -brian > Then just display variables and their names, and maybe parse the variable > names so you can assign meaningful help information to them. > > I didn't compile this, not sure if it'll work, but it'll give you a good > idea as to what your code may look like .. > [...] __________________________________ Do you Yahoo!? Yahoo! Tax Center - File online by April 15th http://taxes.yahoo.com/filing.html