From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 14 17:05:04 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 85A4E16A4CE for ; Wed, 14 Apr 2004 17:05:04 -0700 (PDT) Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [204.127.202.56]) by mx1.FreeBSD.org (Postfix) with ESMTP id 17BA043D1F for ; Wed, 14 Apr 2004 17:05:04 -0700 (PDT) (envelope-from berhart@erhartgroup.com) Received: from cocaine.erhartgroup.com (c-67-166-0-138.client.comcast.net[67.166.0.138]) by comcast.net (sccrmhc12) with SMTP id <20040415000502012001fgene>; Thu, 15 Apr 2004 00:05:03 +0000 Message-Id: <6.0.2.0.2.20040414180437.01c87ac0@mx1.erhartgroup.com> X-Sender: berhart%erhartgroup.com@mx1.erhartgroup.com (Unverified) X-Mailer: QUALCOMM Windows Eudora Version 6.0.2.0 Date: Wed, 14 Apr 2004 18:05:15 -0600 To: Brian O'Shea From: Brandon Erhart In-Reply-To: <20040414225922.41892.qmail@web10505.mail.yahoo.com> References: <6.0.2.0.2.20040414162810.01c8cb48@mx1.erhartgroup.com> <20040414225922.41892.qmail@web10505.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed 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: Thu, 15 Apr 2004 00:05:04 -0000 Ah yes, I was just being crude .. giving some lame example :-P Parsing the rc.conf would take considerably more work than that "Tha whistles go WOOOOOO!" - Bubb Rubb Brandon At 04:59 PM 4/14/2004, you wrote: >--- 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