~ubuntu-branches/ubuntu/edgy/smokeping/edgy-proposed

« back to all changes in this revision

Viewing changes to doc/ParseConfig.pm.txt

  • Committer: Bazaar Package Importer
  • Author(s): Jose Carlos Garcia Sogo
  • Date: 2002-04-02 15:02:08 UTC
  • Revision ID: james.westby@ubuntu.com-20020402150208-8eycqntc07q6gig5
Tags: upstream-1.6
ImportĀ upstreamĀ versionĀ 1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ISG::ParseConfig(3)         SmokePing         ISG::ParseConfig(3)
 
2
 
 
3
 
 
4
 
 
5
SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
 
6
        use ISG::ParseConfig;
 
7
 
 
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;
 
11
 
 
12
 
 
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.
 
23
 
 
24
       GGGGrrrraaaammmmmmmmaaaarrrr DDDDeeeeffffiiiinnnniiiittttiiiioooonnnn
 
25
 
 
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".
 
36
 
 
37
       _S_p_e_c_i_a_l _S_e_c_t_i_o_n _K_e_y_s
 
38
 
 
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.
 
43
 
 
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.
 
49
 
 
50
       _vars       Array containing the list of variables
 
51
                   (assignments) in this section.  Analogous to
 
52
                   sections, regular expressions can be used.
 
53
 
 
54
       _mandatory  Array containing the list of mandatory sec-
 
55
                   tions and variables.
 
56
 
 
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
 
61
                   the column number.
 
62
 
 
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.
 
67
 
 
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.
 
72
 
 
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.
 
77
 
 
78
       _doc        Describes what this section is about
 
79
 
 
80
       _S_p_e_c_i_a_l _V_a_r_i_a_b_l_e _K_e_y_s
 
81
 
 
82
       _re         Regular expression upon which the value will
 
83
                   be checked.
 
84
 
 
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
 
88
                   will be returned).
 
89
 
 
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
 
95
                   as content.
 
96
 
 
97
       _doc        Describtion of the variable.
 
98
 
 
99
       _S_p_e_c_i_a_l _T_a_b_l_e _K_e_y_s
 
100
 
 
101
       _columns    Number of columns. If not specified, it will
 
102
                   not be enforced.
 
103
 
 
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
 
109
                   stored as arrays.
 
110
 
 
111
       _sub        they work analog to the description in the
 
112
                   previous section.
 
113
 
 
114
       _doc        describes the content of the column.
 
115
 
 
116
       _S_p_e_c_i_a_l _T_e_x_t _K_e_y_s
 
117
 
 
118
       _re         Regular expression upon which the text will be
 
119
                   checked (everything as a single line).
 
120
 
 
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
 
124
                   will be returned).
 
125
 
 
126
       _sub        they work analog to the description in the
 
127
                   previous section.
 
128
 
 
129
       _doc        Ditto.
 
130
 
 
131
 
 
132
 
 
133
 
 
134
       CCCCoooonnnnffffiiiigggguuuurrrraaaattttiiiioooonnnn SSSSyyyynnnnttttaaaaxxxx
 
135
 
 
136
       _G_e_n_e_r_a_l _S_y_n_t_a_x
 
137
 
 
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
 
140
       trimmed.
 
141
 
 
142
       '\' at the end of the line marks a continued line on the
 
143
       next line. A single space will be inserted between the
 
144
       concatenated lines.
 
145
 
 
146
       '@include filename' is used to include another file.
 
147
 
 
148
       '@define a some value' will replace all occurences of 'a'
 
149
       in the following text with 'some value'.
 
150
 
 
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.
 
155
 
 
156
       _S_e_c_t_i_o_n_s
 
157
 
 
158
       ISG::ParseConfig supports hierarchical configurations
 
159
       through sections, whose syntax is as follows:
 
160
 
 
161
       Level 1        *** section name ***
 
162
 
 
163
       Level 2        + section name
 
164
 
 
165
       Level 3        ++ section name
 
166
 
 
167
       Level n, n>1   +..+ section name (number of '+' determines
 
168
                      level)
 
169
 
 
170
       _A_s_s_i_g_n_m_e_n_t_s
 
171
 
 
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
 
175
       sign are optional.
 
176
 
 
177
       _T_a_b_u_l_a_r _D_a_t_a
 
178
 
 
179
       The data is interpreted as one or more columns separated
 
180
       by spaces.
 
181
 
 
182
       EEEExxxxaaaammmmpppplllleeee
 
183
 
 
184
       _C_o_d_e
 
185
 
 
186
 
 
187
 
 
188
 
 
189
 
 
190
 
 
191
 
 
192
 
 
193
 
 
194
 
 
195
 
 
196
 
 
197
 
 
198
 
 
199
        my $parser = ISG::ParseConfig->new({
 
200
          _sections => [ 'network', 'hosts' ],
 
201
          network => {
 
202
             _vars     => [ 'dns' ],
 
203
             _sections => [ "/$RE_IP/" ],
 
204
             dns       => {
 
205
                _doc => "address of the dns server",
 
206
                _re => $RE_HOST,
 
207
                _re_error =>
 
208
                   'dns must be an host name or ip address',
 
209
                },
 
210
             "/$RE_IP/" => {
 
211
                _doc    => "Ip Adress",
 
212
                _vars   => [ 'dns', 'netmask', 'gateway' ],
 
213
                dns     => {
 
214
                   _doc => "address of the dns server",
 
215
                   _re => $RE_HOST,
 
216
                   _re_error =>
 
217
                      'dns must be an host name or ip address'
 
218
                   },
 
219
                netmask => {
 
220
                   _doc => "Netmask",
 
221
                   _re => $RE_IP,
 
222
                   _re_error =>
 
223
                      'netmask must be a dotted ip address'
 
224
                   },
 
225
                gateway => {
 
226
                   _doc => "Default Gateway address in IP notation",
 
227
                   _re => $RE_IP,
 
228
                   _re_error =>
 
229
                      'gateway must be a dotted ip address' },
 
230
                },
 
231
             },
 
232
          hosts => {
 
233
             _doc => "Details about the hosts",
 
234
             _table  => {
 
235
                 _doc => "Description of all the Hosts",
 
236
                _key => 0,
 
237
                _columns => 3,
 
238
                0 => {
 
239
                   _doc => "Ethernet Address",
 
240
                   _re => $RE_MAC,
 
241
                   _re_error =>
 
242
                      'first column must be an ethernet mac address',
 
243
                   },
 
244
                1 => {
 
245
                   _doc => "IP Address",
 
246
                   _re => $RE_IP,
 
247
                   _re_error =>
 
248
                      'second column must be a dotted ip address',
 
249
                   },
 
250
                },
 
251
             },
 
252
          });
 
253
 
 
254
        my $cfg = $parser->parse('test.cfg') or
 
255
          die "ERROR: $parser->{err}\n";
 
256
        print Dumper($cfg);
 
257
        print $praser->makepod;
 
258
 
 
259
       _C_o_n_f_i_g_u_r_a_t_i_o_n
 
260
 
 
261
        *** network ***
 
262
 
 
263
          dns      = 129.132.7.87
 
264
 
 
265
        + 129.132.7.64
 
266
 
 
267
          netmask  = 255.255.255.192
 
268
          gateway  = 129.132.7.65
 
269
 
 
270
        *** hosts ***
 
271
 
 
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
 
275
 
 
276
       _R_e_s_u_l_t
 
277
 
 
278
        {
 
279
          'hosts' => {
 
280
                       '00:50:fe:bc:65:11' => [
 
281
                                                '00:50:fe:bc:65:11',
 
282
                                                '129.132.7.97',
 
283
                                                'plain.hades'
 
284
                                              ],
 
285
                       '00:50:fe:bc:65:12' => [
 
286
                                                '00:50:fe:bc:65:12',
 
287
                                                '129.132.7.98',
 
288
                                                'isg.ee.hades'
 
289
                                              ],
 
290
                       '00:50:fe:bc:65:14' => [
 
291
                                                '00:50:fe:bc:65:14',
 
292
                                                '129.132.7.99',
 
293
                                                'isg.ee.hades'
 
294
                                              ]
 
295
                     },
 
296
          'network' => {
 
297
                         '129.132.7.64' => {
 
298
                                             'netmask' => '255.255.255.192',
 
299
                                             'gateway' => '129.132.7.65'
 
300
                                           },
 
301
                         'dns' => '129.132.7.87'
 
302
                       }
 
303
        };
 
304
 
 
305
 
 
306
CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
 
307
       Copyright (c) 2000, 2001 by ETH Zurich. All rights
 
308
       reserved.
 
309
 
 
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
 
315
       later version.
 
316
 
 
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
 
321
       details.
 
322
 
 
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
 
326
       02139, USA.
 
327
 
 
328
AAAAUUUUTTTTHHHHOOOORRRR
 
329
       David Schweikert <dws@ee.ethz.ch>
 
330
       Tobias Oetiker <oetiker@ee.ethz.ch>
 
331
 
 
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
 
340
 
 
341
 
 
342
 
 
343
 
 
344
2002-03-27                     1.6            ISG::ParseConfig(3)