From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 14 15:34:51 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 8656F16A4D0 for ; Wed, 14 Apr 2004 15:34:51 -0700 (PDT) Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [204.127.202.56]) by mx1.FreeBSD.org (Postfix) with ESMTP id 28C6343D5F for ; Wed, 14 Apr 2004 15:34:51 -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 <20040414223449012001h9sje>; Wed, 14 Apr 2004 22:34:50 +0000 Message-Id: <6.0.2.0.2.20040414162810.01c8cb48@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 16:35:02 -0600 To: Craig Rodrigues From: Brandon Erhart In-Reply-To: <20040414215601.GA3923@crodrigues.org> References: <20040414215601.GA3923@crodrigues.org> 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: Wed, 14 Apr 2004 22:34:51 -0000 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 >rodrigc@crodrigues.org >_______________________________________________ >freebsd-hackers@freebsd.org mailing list >http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"