## ## OSSP cfg - Configuration Parsing ## Copyright (c) 1999-2002 Ralf S. Engelschall ## Copyright (c) 1999-2002 The OSSP Project (http://www.ossp.org/) ## Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) ## ## 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 SYNOPSIS ... =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 configure structures which require arbitrarily nested sections. =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]/ # NL,CR,TAB,BS,FF,BEL,ESC | /\\\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 ::= "B or corresponding closing char ('}])>') if B is a char of '{[(<'" 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) spec: parent .. lbroth -> rbroth <- child[1] child[L] virtualhost[2].directory =head1 NODE SELECTION SPECIFICATION The B function takes a I string B ::= I | B B