Date: Wed, 14 Apr 2004 18:05:15 -0600 From: Brandon Erhart <berhart@ErhartGroup.COM> To: Brian O'Shea <b_oshea@yahoo.com> Cc: freebsd-hackers@freebsd.org Subject: Re: C code for parsing rc.conf? Message-ID: <6.0.2.0.2.20040414180437.01c87ac0@mx1.erhartgroup.com> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <berhart@ErhartGroup.COM> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6.0.2.0.2.20040414180437.01c87ac0>