1
ISG::ParseConfig(3) SmokePing ISG::ParseConfig(3)
5
SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
8
my $parser = ISG::ParseConfig->new(\%grammar);
9
my $cfg = $parser->parse('app.cfg') or die "ERROR: $parser->{err}\n";
10
my $pod = $parser->makepod;
13
DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
14
ISG::ParseConfig is a module to parse configuration files.
15
The configuration may consist of multiple-level sections
16
with assignments and tabular data. The parsed data will be
17
returned as a hash containing the whole configuration.
18
ISG::ParseConfig uses a grammar that is supplied upon cre-
19
ation of a ISG::ParseConfig object to parse the configura-
20
tion file and return helpful error messages in case of
21
syntax errors. Using the mmmmaaaakkkkeeeeppppoooodddd methode you can generate
22
documentation of the configuration file format.
24
GGGGrrrraaaammmmmmmmaaaarrrr DDDDeeeeffffiiiinnnniiiittttiiiioooonnnn
26
The grammar is a multiple-level hash of hashes, which fol-
27
lows the structure of the configuration. Each section or
28
variable is represented by a hash with the same structure.
29
Each hash contains special keys starting with an under-
30
score such as '_sections', '_vars', '_sub' or '_re' to
31
denote meta data with information about that section or
32
variable. Other keys are used to structure the hash
33
according to the same nesting structure of the configura-
34
tion itself. The starting hash given as parameter to 'new'
35
contains the "root section".
37
_S_p_e_c_i_a_l _S_e_c_t_i_o_n _K_e_y_s
39
_sections Array containing the list of sub-sections of
40
this section. Each sub-section must then be
41
represented by a sub-hash in this hash with
42
the same name of the sub-section.
44
The sub-section can also be a regular expres-
45
sion denoted by the syntax '/re/', where re is
46
the regular-expression. In case a regular
47
expression is used, a sub-hash named with the
48
same '/re/' must be included in this hash.
50
_vars Array containing the list of variables
51
(assignments) in this section. Analogous to
52
sections, regular expressions can be used.
54
_mandatory Array containing the list of mandatory sec-
57
_table Hash containing the table grammar (see Special
58
Table Keys). If not specified, no table is
59
allowed in this section. The grammar of the
60
columns if specified by sub-hashes named with
63
_text Section contains free-form text. Only sections
64
and @includes statements will be interpreted,
65
the rest will be added in the returned hash
66
under '_text' as string.
68
____tttteeeexxxxtttt is a hash reference which can contain a
69
____rrrreeee and a ____rrrreeee____eeeerrrrrrrroooorrrr key which will be used to
70
scrutanize the text ... if the hash is empty,
71
all text will be accepted.
73
_order If defined, a '_order' element will be put in
74
every hash containing the sections with a num-
75
ber that determines the order in which the
76
sections were defined.
78
_doc Describes what this section is about
80
_S_p_e_c_i_a_l _V_a_r_i_a_b_l_e _K_e_y_s
82
_re Regular expression upon which the value will
85
_re_error String containing the returned error in case
86
the regular expression doesn't match (if not
87
specified, a generic 'syntax error' message
90
_sub A function pointer. It called for every value,
91
with the value passed as its first argument.
92
If the function returns a defined value it is
93
assumed that the test was not successful and
94
an error is generated with the returned string
97
_doc Describtion of the variable.
99
_S_p_e_c_i_a_l _T_a_b_l_e _K_e_y_s
101
_columns Number of columns. If not specified, it will
104
_key If defined, the specified column number will
105
be used as key in a hash in the returned hash.
106
If not defined, the returned hash will contain
107
a '_table' element with the contents of the
108
table as array. The rows of the tables are
111
_sub they work analog to the description in the
114
_doc describes the content of the column.
116
_S_p_e_c_i_a_l _T_e_x_t _K_e_y_s
118
_re Regular expression upon which the text will be
119
checked (everything as a single line).
121
_re_error String containing the returned error in case
122
the regular expression doesn't match (if not
123
specified, a generic 'syntax error' message
126
_sub they work analog to the description in the
134
CCCCoooonnnnffffiiiigggguuuurrrraaaattttiiiioooonnnn SSSSyyyynnnnttttaaaaxxxx
136
_G_e_n_e_r_a_l _S_y_n_t_a_x
138
'#' denotes a comment up to the end-of-line, empty lines
139
are allowed and space at the beginning and end of lines is
142
'\' at the end of the line marks a continued line on the
143
next line. A single space will be inserted between the
146
'@include filename' is used to include another file.
148
'@define a some value' will replace all occurences of 'a'
149
in the following text with 'some value'.
151
Fields in tables that contain white space can be enclosed
152
in either "'" or """. Whitespace can also be escaped with
153
"\". Quotes inside quotes are allowed but must be escaped
154
with a backslash as well.
158
ISG::ParseConfig supports hierarchical configurations
159
through sections, whose syntax is as follows:
161
Level 1 *** section name ***
163
Level 2 + section name
165
Level 3 ++ section name
167
Level n, n>1 +..+ section name (number of '+' determines
170
_A_s_s_i_g_n_m_e_n_t_s
172
Assignements take the form: 'variable = value', where
173
value can be any string (can contain whitespaces and spe-
174
cial characters). The spaces before and after the equal
177
_T_a_b_u_l_a_r _D_a_t_a
179
The data is interpreted as one or more columns separated
182
EEEExxxxaaaammmmpppplllleeee
199
my $parser = ISG::ParseConfig->new({
200
_sections => [ 'network', 'hosts' ],
203
_sections => [ "/$RE_IP/" ],
205
_doc => "address of the dns server",
208
'dns must be an host name or ip address',
212
_vars => [ 'dns', 'netmask', 'gateway' ],
214
_doc => "address of the dns server",
217
'dns must be an host name or ip address'
223
'netmask must be a dotted ip address'
226
_doc => "Default Gateway address in IP notation",
229
'gateway must be a dotted ip address' },
233
_doc => "Details about the hosts",
235
_doc => "Description of all the Hosts",
239
_doc => "Ethernet Address",
242
'first column must be an ethernet mac address',
245
_doc => "IP Address",
248
'second column must be a dotted ip address',
254
my $cfg = $parser->parse('test.cfg') or
255
die "ERROR: $parser->{err}\n";
257
print $praser->makepod;
259
_C_o_n_f_i_g_u_r_a_t_i_o_n
267
netmask = 255.255.255.192
268
gateway = 129.132.7.65
272
00:50:fe:bc:65:11 129.132.7.97 plain.hades
273
00:50:fe:bc:65:12 129.132.7.98 isg.ee.hades
274
00:50:fe:bc:65:14 129.132.7.99 isg.ee.hades
280
'00:50:fe:bc:65:11' => [
285
'00:50:fe:bc:65:12' => [
290
'00:50:fe:bc:65:14' => [
298
'netmask' => '255.255.255.192',
299
'gateway' => '129.132.7.65'
301
'dns' => '129.132.7.87'
306
CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
307
Copyright (c) 2000, 2001 by ETH Zurich. All rights
310
LLLLIIIICCCCEEEENNNNSSSSEEEE
311
This program is free software; you can redistribute it
312
and/or modify it under the terms of the GNU General Public
313
License as published by the Free Software Foundation;
314
either version 2 of the License, or (at your option) any
317
This program is distributed in the hope that it will be
318
useful, but WITHOUT ANY WARRANTY; without even the implied
319
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
320
PURPOSE. See the GNU General Public License for more
323
You should have received a copy of the GNU General Public
324
License along with this program; if not, write to the Free
325
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
328
AAAAUUUUTTTTHHHHOOOORRRR
329
David Schweikert <dws@ee.ethz.ch>
330
Tobias Oetiker <oetiker@ee.ethz.ch>
332
HHHHIIIISSSSTTTTOOOORRRRYYYY
333
2001-05-11 ds 1.2 Initial Version for policy 0.3
334
2001-09-04 ds 1.3 Remove space before comments, more strict variable definition
335
2001-09-19 to 1.4 Added _sub error parsing and _doc self documentation
336
2001-10-20 to Improved Rendering of _doc information
337
2002-01-09 to Added Documentation to the _text section documentation
338
2002-01-28 to Fixed quote parsing in tables
339
2002-03-12 ds 1.5 Implemented @define, make makepod return a string and not an array
344
2002-03-27 1.6 ISG::ParseConfig(3)