Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Apr 2004 15:59:22 -0700 (PDT)
From:      Brian O'Shea <b_oshea@yahoo.com>
To:        Brandon Erhart <berhart@ErhartGroup.COM>, Craig Rodrigues <rodrigc@crodrigues.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: C code for parsing rc.conf?
Message-ID:  <20040414225922.41892.qmail@web10505.mail.yahoo.com>
In-Reply-To: <6.0.2.0.2.20040414162810.01c8cb48@mx1.erhartgroup.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--- 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?20040414225922.41892.qmail>