## ## OSSP cfg - Configuration Parsing ## Copyright (c) 2002-2006 Ralf S. Engelschall ## Copyright (c) 2002-2006 The OSSP Project (http://www.ossp.org/) ## ## This file is part of OSSP cfg, a configuration parsing ## library which can be found at http://www.ossp.org/pkg/lib/cfg/. ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## ## cfg.pod: manual page ## =pod =head1 NAME B - Configuration Parsing =head1 VERSION OSSP cfg CFG_VERSION_STR =head1 SYNOPSIS =over 4 =item B cfg.h =item B cfg_t, cfg_rc_t, cfg_node_type_t, cfg_node_t, cfg_node_attr_t, cfg_fmt_t, cfg_data_t, cfg_data_ctrl_t, cfg_data_cb_t, cfg_data_attr_t =item B cfg_create, cfg_destroy, cfg_error, cfg_version, cfg_import, cfg_export, cfg_node_create, cfg_node_destroy, cfg_node_clone, cfg_node_set, cfg_node_get, cfg_node_root, cfg_node_select, cfg_node_find, cfg_node_apply, cfg_node_cmp, cfg_node_link, cfg_node_unlink, cfg_data_set, cfg_data_get, cfg_data_ctrl =back =head1 DESCRIPTION B is a ISO-C library for parsing arbitrary C/C++-style configuration files. A configuration is sequence of directives. Each directive consists of zero or more tokens. Each token can be either a string or again a complete sequence. This means the configuration syntax has a recursive structure and this way allows to create configurations with arbitrarily nested sections. Additionally the configuration syntax provides complex single/double/balanced quoting of tokens, hexadecimal/octal/decimal character encodings, character escaping, C/C++ and Shell-style comments, etc. The library API allows importing a configuration text into an Abstract Syntax Tree (AST), traversing the AST and optionally exporting the AST again as a configuration text. =head2 CONFIGURATION SYNTAX The configuration syntax is described by the following context-free (Chomsky-2) grammar: B ::= I | B | B B B B ::= B | B B B ::= B B B | B B ::= B # double quoted string | B # single quoted string | B # flexible quoted string | B # plain text string The other contained terminal symbols are defined itself by the following set of grammars production (regular sub-grammars for character sequences given as Perl-style regular expressions "/I/"): B ::= /;/ B ::= /{/ B ::= /}/ B ::= /"/ B /"/ B ::= I | B B B ::= /\\"/ # escaped quote | /\\x\{[0-9a-fA-F]+\}/ # hex-char group | /\\x[0-9a-fA-F]{2}/ # hex-char | /\\[0-7]{1,3}/ # octal character | /\\[nrtbfae]/ # special character | /\\\n[ \t]*/ # line continuation | /\\\\/ # escaped escape | /./ # any other char B ::= /'/ B /'/ B ::= I | B B B ::= /\\'/ # escaped quote | /\\\n[ \t]*/ # line contination | /\\\\/ # escaped escape | /./ # any other char B ::= /q/ B B B B ::= I | B B B ::= /\\/ B # escaped open | /\\/ B # escaped close | /\\\n[ \t]*/ # line contination | /./ # any other char B ::= /[!"#$%&'()*+,-./:;<=>?@\[\\\]^_`{|}~]/ B ::= EE B or corresponding closing char ('}])>') if B is a char of '{[(<' EE B ::= B B B ::= I | B B B ::= /[^ \t\n;{}"']/ # none of specials Additionally, white-space B and comment B tokens are allowed at any position in the above productions of the previous grammar part. B ::= /[ \t\n]+/ B ::= B # style of C | B # style of C++ | B # style of /bin/sh B ::= /\/\*([^*]|\*(?!\/))*\*\// B ::= /\/\/[^\n]*/ B ::= /#[^\n]*/ Finally, any configuration line can have a trailing backslash character (C<\>) just before the newline character for simple line continuation. The backslash, the newline and (optionally) the leading whitespaces on the following line are silently obsorbed and as a side-effect continue the first line with the contents of the second lines. =head2 CONFIGURATION EXAMPLE A more intuitive description of the configuration syntax is perhaps given by the following example which shows all features at once: /* single word */ foo; /* multi word */ foo bar quux; /* nested structure */ foo { bar; baz } quux; /* quoted strings */ 'foo bar' "foo\x0a\t\n\ bar" =head1 APPLICATION PROGRAMMING INTERFACE (API) ... =head1 NODE SELECTION SPECIFICATION The B function takes a I string B ::= I | B B