C code for parsing rc.conf?

Brandon Erhart berhart at ErhartGroup.COM
Wed Apr 14 17:05:04 PDT 2004


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 at 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



More information about the freebsd-hackers mailing list