cfgread man page on DragonFly

Man page or keyword search:  
man Server   44335 pages
apropos Keyword Search (all sections)
Output format
DragonFly logo
[printable version]

sf_cfg(3)		 BSD Library Functions Manual		     sf_cfg(3)

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

SYNOPSIS
     #include <strfunc.h>

     int
     cfgread(char *filename);

     char *
     cfgget(char *key);

     svect *
     cfgget2(char *key);

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

EXAMPLE
     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);

     };

CONFIGURATION FILE EXAMPLE
     key1 = "value";

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

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

     key2 = "Hello again!";

SEE ALSO
     strfunc(3), sf_svect(3).

AUTHORS
     Lev Walkin <vlm@lionet.info>

BSD				October 1, 2000				   BSD
[top]

List of man pages available for DragonFly

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net