GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
sf_cfg(3) FreeBSD Library Functions Manual sf_cfg(3)

cfgread, cfgget, cfgget2
functions to read and parse configuration files

#include <strfunc.h>

int
cfgread(char *filename);

char *
cfgget(char *key);

svect *
cfgget2(char *key);

These routines give the user an easy way of creating nice configuration files. The basic idea of configuration files is the attribute=value scheme. Attribute may be writtten as the ordinary english literal word, or placed into the quotes, like a value. Value may also be quoted or be an ordinary english word or combination of alphanumeric characters. Attributes and values may be quoted using the double or single quotes. When quotes are used, escaping can be made much like as in Bourne shell or in the C code. Once read, file is closed, but attribute and values stored internally and may be used multiple times.

There are two general forms of defining an attribute=value pairs. Two forms are defined using the following BNF:

	<simple_word>	:=	1*<A-Z0-9>

	<quoted_string>	:=	<QUOTE> *<any character except 0> <QUOTE>

	<attr>		:= <simple_word> | <quoted_string>

	<value>		:= <quoted_string> | <simple_word>

	<generic_form>	:= <attribute> = <value> [ ; ]

	<multiple>	:= <attribute> { <value> *<[ , <value> ]> }  [ ; ]

cfgread() function used to read and parse the configuration file.

cfgget() returns an appropriate value for the specified key, or NULL if key is not found.

cfgget2() may be required if multiple values are expected. It allocates the svect * structure that must be freed by caller with sfree(). It will return NULL if svect allocation failed. If no key values found, it will return valid, but empty string vector.

void cfgparse() {
	char *value1;
	svect *values2;
	svect *values3;
	int r;

	if((r=cfgread("/path/to/config.file")) != 0) {
		if(r > 0) {
			printf("Wrong file format.0);
		} else {
			printf("File access failed.0);
		};
		return;
	};

	value1	= cfgget("key1");
	values2	= cfgget2("key2");
	values3	= cfgget2("key3");

	/* Free allocated structures */
	sfree(values2);
	sfree(values3);

};


key1 = "value";

key2 = "this multiline
		value will be
		\"passed\" to values2.";

key3 = {
	"value1",
	"value2",
	"value3"
};


key2 = "Hello again!";

strfunc(3), sf_svect(3).

Lev Walkin <vlm@lionet.info>
October 1, 2000 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.