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

int main(int argc, char **argv)
{
FILE *rc;
char buf[512];


if ( (rc=fopen("/etc/rc.conf", "r")) == NULL) { perror("fopen()");

        exit(EXIT_FAILURE);
}

while (fgets(buf, sizeof(buf), rc) != NULL)
{
        char *eq_ptr, var_name[256], var_value[256];

some_function_to_strip_trailing_and_pre_whitespace(buf); /* this function will just strip pre- and trailing whitespace from the line */

if (!strlen(buf)) continue; /* blank line */

if (buf[0] == '#') continue; /* comment line */

if ( (eq_ptr = index(buf, '=')) == NULL) continue; /* no equal sign */

*eq_ptr = '\0';

        memset(var_name, 0, 256);
        memset(var_value, 0, 256);

if (!strlen(buf) || !strlen(eq_ptr+1)) continue; /* either the variable name or the value was empty */

        strncpy(var_name, buf, 255);
        strncpy(var_value, eq_ptr+1, 255);

        printf("%s=%s\n", var_name, var_value);
}

        exit(EXIT_SUCCESS);
}

At 03:56 PM 4/14/2004, you wrote:
Hi,

Is there a C library that comes with FreeBSD which
can be used to parse, append to, and validate
rc.conf?

I'd like to customize some of the settings in /etc/rc.conf
with my own GUI-based program.  It's not too hard
to write something on my own, but I was wondering
if a reusable library existed in FreeBSD 4.x or 5.x for doing this.

Thanks.

--
Craig Rodrigues
http://crodrigues.org
[EMAIL PROTECTED]
_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

_______________________________________________ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to