[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Example Source

#include <stdio.h>

#include "conf4c.h"

int
main (int argc, char **argv)
{
	Conf4CFile *c4cf;
	Conf4CFileAttrib *c4cfattrib;
	Conf4CParser *parser;
	Conf4CReader *c4cr;

	/* create an instance of Conf4CFile 		*/
	/* use values:					*/
	/* '#' denotes a comments			*/
	/* ' ' delimits a name / value pair		*/
	/* create room for 3 section types		*/
	/* create room for 3 instances of each type 	*/
	/* create froom for 5 entries in each instance	*/
	/* create room for 25 top level n/v entries 	*/
	c4cfattrib = conf4c_fileattrib_new ("apache.conf", "#", " ", CONF4C_DELIM_LAZY);
	c4cf = conf4c_file_new (3, 25);
	parser = conf4c_parser_new (c4cf, c4cfattrib);

	/* parse the file */
	conf4c_parser_parse (parser, 3, 5);
	
	/* create a reader to read the newly parsed file */
	c4cr = conf4c_reader_new (c4cf);

	/* now move the Conf4CReader through each and every name / value pair the */
	/* Conf4CFile contains, retreiving section types, section-instance names, */
	/* and both name and value strings along the way */
	do {
		printf ("Entering Section Type: %s\n", conf4c_reader_get_section_type (c4cr));

		do {
			printf ("\tListing Section Instance: %s\n", conf4c_reader_get_stor_name (c4cr));

			do {
				printf ("\t\t<Name : Value>: %s : %s\n", 
						conf4c_reader_get_value_name (c4cr), 
						conf4c_reader_get_value (c4cr));
			}while (conf4c_reader_next_name_value (c4cr));
		}while (conf4c_reader_next_stor (c4cr));
	}while (conf4c_reader_next_section (c4cr));

	/* or if you know the section-type and name of the */
	/* value you desire */
	printf ("IfModule type, prefork.c instance, MaxClients value: %s\n", 
			conf4c_reader_get_named_value (c4cr, "IfModule", "prefork.c", "MaxClients"));
	return 0;
}


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated on October, 29 2004 using texi2html 1.70.