Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / obj / conf / cf-lex.c @ 2b5ca73a

History | View | Annotate | Download (67.8 KB)

1
#line 2 "obj/conf/cf-lex.c"
2

    
3
#line 4 "obj/conf/cf-lex.c"
4

    
5
#define  YY_INT_ALIGNED short int
6

    
7
/* A lexical scanner generated by flex */
8

    
9
#define yy_create_buffer cf__create_buffer
10
#define yy_delete_buffer cf__delete_buffer
11
#define yy_flex_debug cf__flex_debug
12
#define yy_init_buffer cf__init_buffer
13
#define yy_flush_buffer cf__flush_buffer
14
#define yy_load_buffer_state cf__load_buffer_state
15
#define yy_switch_to_buffer cf__switch_to_buffer
16
#define yyin cf_in
17
#define yyleng cf_leng
18
#define yylex cf_lex
19
#define yylineno cf_lineno
20
#define yyout cf_out
21
#define yyrestart cf_restart
22
#define yytext cf_text
23
#define yywrap cf_wrap
24
#define yyalloc cf_alloc
25
#define yyrealloc cf_realloc
26
#define yyfree cf_free
27

    
28
#define FLEX_SCANNER
29
#define YY_FLEX_MAJOR_VERSION 2
30
#define YY_FLEX_MINOR_VERSION 6
31
#define YY_FLEX_SUBMINOR_VERSION 1
32
#if YY_FLEX_SUBMINOR_VERSION > 0
33
#define FLEX_BETA
34
#endif
35

    
36
/* First, we deal with  platform-specific or compiler-specific issues. */
37

    
38
/* begin standard C headers. */
39
#include <stdio.h>
40
#include <string.h>
41
#include <errno.h>
42
#include <stdlib.h>
43

    
44
/* end standard C headers. */
45

    
46
/* flex integer type definitions */
47

    
48
#ifndef FLEXINT_H
49
#define FLEXINT_H
50

    
51
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
52

    
53
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
54

    
55
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
56
 * if you want the limit (max/min) macros for int types. 
57
 */
58
#ifndef __STDC_LIMIT_MACROS
59
#define __STDC_LIMIT_MACROS 1
60
#endif
61

    
62
#include <inttypes.h>
63
typedef int8_t flex_int8_t;
64
typedef uint8_t flex_uint8_t;
65
typedef int16_t flex_int16_t;
66
typedef uint16_t flex_uint16_t;
67
typedef int32_t flex_int32_t;
68
typedef uint32_t flex_uint32_t;
69
#else
70
typedef signed char flex_int8_t;
71
typedef short int flex_int16_t;
72
typedef int flex_int32_t;
73
typedef unsigned char flex_uint8_t; 
74
typedef unsigned short int flex_uint16_t;
75
typedef unsigned int flex_uint32_t;
76

    
77
/* Limits of integral types. */
78
#ifndef INT8_MIN
79
#define INT8_MIN               (-128)
80
#endif
81
#ifndef INT16_MIN
82
#define INT16_MIN              (-32767-1)
83
#endif
84
#ifndef INT32_MIN
85
#define INT32_MIN              (-2147483647-1)
86
#endif
87
#ifndef INT8_MAX
88
#define INT8_MAX               (127)
89
#endif
90
#ifndef INT16_MAX
91
#define INT16_MAX              (32767)
92
#endif
93
#ifndef INT32_MAX
94
#define INT32_MAX              (2147483647)
95
#endif
96
#ifndef UINT8_MAX
97
#define UINT8_MAX              (255U)
98
#endif
99
#ifndef UINT16_MAX
100
#define UINT16_MAX             (65535U)
101
#endif
102
#ifndef UINT32_MAX
103
#define UINT32_MAX             (4294967295U)
104
#endif
105

    
106
#endif /* ! C99 */
107

    
108
#endif /* ! FLEXINT_H */
109

    
110
/* TODO: this is always defined, so inline it */
111
#define yyconst const
112

    
113
#if defined(__GNUC__) && __GNUC__ >= 3
114
#define yynoreturn __attribute__((__noreturn__))
115
#else
116
#define yynoreturn
117
#endif
118

    
119
/* Returned upon end-of-file. */
120
#define YY_NULL 0
121

    
122
/* Promotes a possibly negative, possibly signed char to an unsigned
123
 * integer for use as an array index.  If the signed char is negative,
124
 * we want to instead treat it as an 8-bit unsigned char, hence the
125
 * double cast.
126
 */
127
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
128

    
129
/* Enter a start condition.  This macro really ought to take a parameter,
130
 * but we do it the disgusting crufty way forced on us by the ()-less
131
 * definition of BEGIN.
132
 */
133
#define BEGIN (yy_start) = 1 + 2 *
134

    
135
/* Translate the current start state into a value that can be later handed
136
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
137
 * compatibility.
138
 */
139
#define YY_START (((yy_start) - 1) / 2)
140
#define YYSTATE YY_START
141

    
142
/* Action number for EOF rule of a given start state. */
143
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
144

    
145
/* Special action meaning "start processing a new file". */
146
#define YY_NEW_FILE cf_restart(cf_in  )
147

    
148
#define YY_END_OF_BUFFER_CHAR 0
149

    
150
/* Size of default input buffer. */
151
#ifndef YY_BUF_SIZE
152
#ifdef __ia64__
153
/* On IA-64, the buffer size is 16k, not 8k.
154
 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
155
 * Ditto for the __ia64__ case accordingly.
156
 */
157
#define YY_BUF_SIZE 32768
158
#else
159
#define YY_BUF_SIZE 16384
160
#endif /* __ia64__ */
161
#endif
162

    
163
/* The state buf must be large enough to hold one state per character in the main buffer.
164
 */
165
#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
166

    
167
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
168
#define YY_TYPEDEF_YY_BUFFER_STATE
169
typedef struct yy_buffer_state *YY_BUFFER_STATE;
170
#endif
171

    
172
#ifndef YY_TYPEDEF_YY_SIZE_T
173
#define YY_TYPEDEF_YY_SIZE_T
174
typedef size_t yy_size_t;
175
#endif
176

    
177
extern int cf_leng;
178

    
179
extern FILE *cf_in, *cf_out;
180

    
181
#define EOB_ACT_CONTINUE_SCAN 0
182
#define EOB_ACT_END_OF_FILE 1
183
#define EOB_ACT_LAST_MATCH 2
184

    
185
    #define YY_LESS_LINENO(n)
186
    #define YY_LINENO_REWIND_TO(ptr)
187
    
188
/* Return all but the first "n" matched characters back to the input stream. */
189
#define yyless(n) \
190
        do \
191
                { \
192
                /* Undo effects of setting up cf_text. */ \
193
        int yyless_macro_arg = (n); \
194
        YY_LESS_LINENO(yyless_macro_arg);\
195
                *yy_cp = (yy_hold_char); \
196
                YY_RESTORE_YY_MORE_OFFSET \
197
                (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
198
                YY_DO_BEFORE_ACTION; /* set up cf_text again */ \
199
                } \
200
        while ( 0 )
201

    
202
#define unput(c) yyunput( c, (yytext_ptr)  )
203

    
204
#ifndef YY_STRUCT_YY_BUFFER_STATE
205
#define YY_STRUCT_YY_BUFFER_STATE
206
struct yy_buffer_state
207
        {
208
        FILE *yy_input_file;
209

    
210
        char *yy_ch_buf;                /* input buffer */
211
        char *yy_buf_pos;                /* current position in input buffer */
212

    
213
        /* Size of input buffer in bytes, not including room for EOB
214
         * characters.
215
         */
216
        int yy_buf_size;
217

    
218
        /* Number of characters read into yy_ch_buf, not including EOB
219
         * characters.
220
         */
221
        int yy_n_chars;
222

    
223
        /* Whether we "own" the buffer - i.e., we know we created it,
224
         * and can realloc() it to grow it, and should free() it to
225
         * delete it.
226
         */
227
        int yy_is_our_buffer;
228

    
229
        /* Whether this is an "interactive" input source; if so, and
230
         * if we're using stdio for input, then we want to use getc()
231
         * instead of fread(), to make sure we stop fetching input after
232
         * each newline.
233
         */
234
        int yy_is_interactive;
235

    
236
        /* Whether we're considered to be at the beginning of a line.
237
         * If so, '^' rules will be active on the next match, otherwise
238
         * not.
239
         */
240
        int yy_at_bol;
241

    
242
    int yy_bs_lineno; /**< The line count. */
243
    int yy_bs_column; /**< The column count. */
244

    
245
        /* Whether to try to fill the input buffer when we reach the
246
         * end of it.
247
         */
248
        int yy_fill_buffer;
249

    
250
        int yy_buffer_status;
251

    
252
#define YY_BUFFER_NEW 0
253
#define YY_BUFFER_NORMAL 1
254
        /* When an EOF's been seen but there's still some text to process
255
         * then we mark the buffer as YY_EOF_PENDING, to indicate that we
256
         * shouldn't try reading from the input source any more.  We might
257
         * still have a bunch of tokens to match, though, because of
258
         * possible backing-up.
259
         *
260
         * When we actually see the EOF, we change the status to "new"
261
         * (via cf_restart()), so that the user can continue scanning by
262
         * just pointing cf_in at a new input file.
263
         */
264
#define YY_BUFFER_EOF_PENDING 2
265

    
266
        };
267
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
268

    
269
/* Stack of input buffers. */
270
static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
271
static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
272
static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
273

    
274
/* We provide macros for accessing buffer states in case in the
275
 * future we want to put the buffer states in a more general
276
 * "scanner state".
277
 *
278
 * Returns the top of the stack, or NULL.
279
 */
280
#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
281
                          ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
282
                          : NULL)
283

    
284
/* Same as previous macro, but useful when we know that the buffer stack is not
285
 * NULL or when we need an lvalue. For internal use only.
286
 */
287
#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
288

    
289
/* yy_hold_char holds the character lost when cf_text is formed. */
290
static char yy_hold_char;
291
static int yy_n_chars;                /* number of characters read into yy_ch_buf */
292
int cf_leng;
293

    
294
/* Points to current character in buffer. */
295
static char *yy_c_buf_p = NULL;
296
static int yy_init = 0;                /* whether we need to initialize */
297
static int yy_start = 0;        /* start state number */
298

    
299
/* Flag which is used to allow cf_wrap()'s to do buffer switches
300
 * instead of setting up a fresh cf_in.  A bit of a hack ...
301
 */
302
static int yy_did_buffer_switch_on_eof;
303

    
304
void cf_restart (FILE *input_file  );
305
void cf__switch_to_buffer (YY_BUFFER_STATE new_buffer  );
306
YY_BUFFER_STATE cf__create_buffer (FILE *file,int size  );
307
void cf__delete_buffer (YY_BUFFER_STATE b  );
308
void cf__flush_buffer (YY_BUFFER_STATE b  );
309
void cf_push_buffer_state (YY_BUFFER_STATE new_buffer  );
310
void cf_pop_buffer_state (void );
311

    
312
static void cf_ensure_buffer_stack (void );
313
static void cf__load_buffer_state (void );
314
static void cf__init_buffer (YY_BUFFER_STATE b,FILE *file  );
315

    
316
#define YY_FLUSH_BUFFER cf__flush_buffer(YY_CURRENT_BUFFER )
317

    
318
YY_BUFFER_STATE cf__scan_buffer (char *base,yy_size_t size  );
319
YY_BUFFER_STATE cf__scan_string (yyconst char *yy_str  );
320
YY_BUFFER_STATE cf__scan_bytes (yyconst char *bytes,int len  );
321

    
322
void *cf_alloc (yy_size_t  );
323
void *cf_realloc (void *,yy_size_t  );
324
void cf_free (void *  );
325

    
326
#define yy_new_buffer cf__create_buffer
327

    
328
#define yy_set_interactive(is_interactive) \
329
        { \
330
        if ( ! YY_CURRENT_BUFFER ){ \
331
        cf_ensure_buffer_stack (); \
332
                YY_CURRENT_BUFFER_LVALUE =    \
333
            cf__create_buffer(cf_in,YY_BUF_SIZE ); \
334
        } \
335
        YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
336
        }
337

    
338
#define yy_set_bol(at_bol) \
339
        { \
340
        if ( ! YY_CURRENT_BUFFER ){\
341
        cf_ensure_buffer_stack (); \
342
                YY_CURRENT_BUFFER_LVALUE =    \
343
            cf__create_buffer(cf_in,YY_BUF_SIZE ); \
344
        } \
345
        YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
346
        }
347

    
348
#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
349

    
350
/* Begin user sect3 */
351

    
352
#define cf_wrap() (/*CONSTCOND*/1)
353
#define YY_SKIP_YYWRAP
354

    
355
typedef unsigned char YY_CHAR;
356

    
357
FILE *cf_in = NULL, *cf_out = NULL;
358

    
359
typedef int yy_state_type;
360

    
361
extern int cf_lineno;
362

    
363
int cf_lineno = 1;
364

    
365
extern char *cf_text;
366
#ifdef yytext_ptr
367
#undef yytext_ptr
368
#endif
369
#define yytext_ptr cf_text
370

    
371
static yy_state_type yy_get_previous_state (void );
372
static yy_state_type yy_try_NUL_trans (yy_state_type current_state  );
373
static int yy_get_next_buffer (void );
374
static void yynoreturn yy_fatal_error (yyconst char* msg  );
375

    
376
/* Done after the current pattern has been matched and before the
377
 * corresponding action - sets up cf_text.
378
 */
379
#define YY_DO_BEFORE_ACTION \
380
        (yytext_ptr) = yy_bp; \
381
        cf_leng = (int) (yy_cp - yy_bp); \
382
        (yy_hold_char) = *yy_cp; \
383
        *yy_cp = '\0'; \
384
        (yy_c_buf_p) = yy_cp;
385

    
386
#define YY_NUM_RULES 35
387
#define YY_END_OF_BUFFER 36
388
/* This struct is not used in this scanner,
389
   but its presence is necessary. */
390
struct yy_trans_info
391
        {
392
        flex_int32_t yy_verify;
393
        flex_int32_t yy_nxt;
394
        };
395
static yyconst flex_int16_t yy_accept[122] =
396
    {   0,
397
        0,    0,    0,    0,    0,    0,    0,    0,   36,   20,
398
       16,   17,   13,   20,   18,   13,   20,   20,   13,   13,
399
        8,    8,    8,   13,   13,   13,   13,   10,   10,   13,
400
       10,   13,   16,   10,   22,   21,   26,   24,   26,   26,
401
       11,   16,   27,   28,    0,   15,   14,   31,   10,    0,
402
       12,   19,    0,    8,    0,    0,    0,    0,    0,    6,
403
       29,   34,   30,   10,    0,   10,   33,   10,   32,   16,
404
        0,   10,   23,   25,    0,    2,    7,    2,    0,    6,
405
        6,    6,   10,    0,   10,    0,    0,    0,    0,    6,
406
        6,    6,   10,    0,   10,    0,    3,    0,    9,    0,
407

    
408
       10,    0,    0,    0,   10,    5,    0,    0,   10,    0,
409
        0,    0,    0,    0,    4,    6,    0,    0,    0,    1,
410
        0
411
    } ;
412

    
413
static yyconst YY_CHAR yy_ec[256] =
414
    {   0,
415
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
416
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
417
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
418
        1,    2,    4,    5,    6,    1,    7,    8,    9,    7,
419
        7,   10,    7,    7,   11,   12,   13,   14,   15,   16,
420
       15,   15,   15,   15,   15,   15,   15,   17,   18,   19,
421
       20,   21,    7,    1,   22,   22,   22,   22,   22,   22,
422
       23,   23,   23,   23,   23,   23,   23,   23,   23,   23,
423
       23,   23,   23,   23,   23,   23,   23,   23,   23,   23,
424
       24,    1,   25,    1,   23,    1,   22,   22,   26,   27,
425

    
426
       28,   22,   23,   23,   29,   23,   23,   30,   23,   31,
427
       23,   23,   23,   23,   32,   23,   33,   23,   23,   34,
428
       23,   23,    7,   35,    7,   36,    1,    1,    1,    1,
429
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
430
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
431
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
432
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
433
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
434
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
435
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
436

    
437
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
438
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
439
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
440
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
441
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
442
        1,    1,    1,    1,    1
443
    } ;
444

    
445
static yyconst YY_CHAR yy_meta[37] =
446
    {   0,
447
        1,    1,    2,    1,    1,    1,    1,    1,    3,    1,
448
        3,    3,    1,    4,    4,    4,    5,    1,    1,    1,
449
        1,    4,    6,    1,    1,    4,    4,    4,    6,    6,
450
        6,    6,    6,    6,    1,    1
451
    } ;
452

    
453
static yyconst flex_uint16_t yy_base[133] =
454
    {   0,
455
        0,   35,  259,  258,   35,   36,    0,    0,  260,  263,
456
      257,  263,   20,   38,  263,  263,  250,  248,  244,  245,
457
       53,   25,  220,  236,  232,  226,  230,   74,    0,  229,
458
      218,  212,   42,  215,  263,  263,  263,  263,  232,  234,
459
      263,  241,  263,  263,   47,  263,  263,  263,  263,  233,
460
      263,  263,   39,    0,   46,  220,    0,   58,  213,   95,
461
      263,  263,  263,    0,  179,    0,  263,  163,  263,   49,
462
      163,  167,  263,  263,   70,  175,    0,  174,  173,  177,
463
      110,   78,  160,  161,  156,   99,  114,  166,  104,  160,
464
        0,  119,  143,  115,  107,  127,    0,  132,  263,   83,
465

    
466
       72,  135,  138,   56,   49,  141,  147,   48,   93,  150,
467
      153,  168,  169,   61,  161,  164,   53,  179,  180,   52,
468
      263,  198,  204,  210,  216,  220,  223,  225,  228,   43,
469
      230,  235
470
    } ;
471

    
472
static yyconst flex_int16_t yy_def[133] =
473
    {   0,
474
      121,    1,  122,  122,  123,  123,  124,  124,  121,  121,
475
      121,  121,  121,  125,  121,  121,  121,  126,  121,  121,
476
      121,   21,   21,  127,  121,  121,  121,  121,  128,  121,
477
       28,  121,  121,  128,  121,  121,  121,  121,  121,  121,
478
      121,  121,  121,  121,  125,  121,  121,  121,  121,  126,
479
      121,  121,  121,   22,  127,  129,  130,   55,  127,  121,
480
      121,  121,  121,   28,  127,  128,  121,  128,  121,  121,
481
      121,  128,  121,  121,  121,   55,  130,   58,  131,   60,
482
      121,   60,  128,  121,  128,  121,  131,  131,  121,   81,
483
       81,   81,  128,  121,  128,  121,   87,  121,  121,  121,
484

    
485
      128,  121,  121,  121,  128,  121,  121,  121,  128,  121,
486
      121,  121,  121,  132,  121,  121,  132,  132,  132,  132,
487
        0,  121,  121,  121,  121,  121,  121,  121,  121,  121,
488
      121,  121
489
    } ;
490

    
491
static yyconst flex_uint16_t yy_nxt[300] =
492
    {   0,
493
       10,   11,   12,   13,   14,   15,   16,   17,   18,   16,
494
       16,   19,   20,   21,   22,   23,   24,   16,   25,   26,
495
       27,   28,   29,   30,   16,   28,   28,   31,   29,   29,
496
       29,   29,   29,   29,   32,   16,   33,   38,   38,   43,
497
       46,   58,   47,   70,   39,   39,   77,   40,   40,   46,
498
       70,   47,   75,   75,   75,   44,  118,  118,  121,   76,
499
       76,   76,   60,   34,   53,  118,   54,   54,   54,   55,
500
       71,   78,   78,   78,   56,  112,  109,   71,   56,   56,
501
       56,   86,  108,   75,   75,   75,   57,   64,   64,   64,
502
       65,   82,   82,   82,  113,   64,   66,  114,  105,   64,
503

    
504
       64,   64,   66,   66,   66,   66,   66,   66,   80,   80,
505
       80,   81,   96,   96,   96,  104,   82,   98,   98,   98,
506
       82,   82,   82,   90,   90,   90,   91,   97,   97,   97,
507
       81,   92,   92,   92,   92,   92,   92,   92,  102,  101,
508
       96,   96,   96,  103,  100,   98,   98,   98,  106,  106,
509
      106,  107,  107,  107,  106,  106,  106,  110,  111,   99,
510
      107,  107,  107,  115,  115,  115,  116,  116,  116,  113,
511
      113,   89,  114,  114,  115,  115,  115,  116,  116,  116,
512
      119,  119,   81,  118,  118,   95,   94,   93,   89,   81,
513
       79,   87,   85,   84,   83,   60,  120,  120,   35,   35,
514

    
515
       35,   35,   35,   35,   37,   37,   37,   37,   37,   37,
516
       41,   41,   41,   41,   41,   41,   45,   45,   45,   45,
517
       45,   45,   50,   50,   50,   50,   59,   59,   66,   79,
518
       66,   56,   56,   88,   88,  117,   65,  117,  117,  117,
519
      117,   49,   42,   74,   73,   72,   69,   68,   67,   63,
520
       62,   61,   60,  121,   52,   51,   49,   48,   42,  121,
521
       36,   36,    9,  121,  121,  121,  121,  121,  121,  121,
522
      121,  121,  121,  121,  121,  121,  121,  121,  121,  121,
523
      121,  121,  121,  121,  121,  121,  121,  121,  121,  121,
524
      121,  121,  121,  121,  121,  121,  121,  121,  121
525

    
526
    } ;
527

    
528
static yyconst flex_int16_t yy_chk[300] =
529
    {   0,
530
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
531
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
532
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
533
        1,    1,    1,    1,    1,    1,    2,    5,    6,   13,
534
       14,   22,   14,   33,    5,    6,  130,    5,    6,   45,
535
       70,   45,   53,   53,   53,   13,  120,  117,   22,   55,
536
       55,   55,   55,    2,   21,  114,   21,   21,   21,   21,
537
       33,   58,   58,   58,   21,  108,  105,   70,   21,   21,
538
       21,   75,  104,   75,   75,   75,   21,   28,   28,   28,
539
       28,   82,   82,   82,  109,   28,   28,  109,  101,   28,
540

    
541
       28,   28,   28,   28,   28,   28,   28,   28,   60,   60,
542
       60,   60,   86,   86,   86,  100,   60,   89,   89,   89,
543
       60,   60,   60,   81,   81,   81,   81,   87,   87,   87,
544
       87,   81,   92,   92,   92,   81,   81,   81,   96,   95,
545
       96,   96,   96,   98,   94,   98,   98,   98,  102,  102,
546
      102,  103,  103,  103,  106,  106,  106,  106,  107,   93,
547
      107,  107,  107,  110,  110,  110,  111,  111,  111,  112,
548
      113,   90,  112,  113,  115,  115,  115,  116,  116,  116,
549
      118,  119,   88,  118,  119,   85,   84,   83,   80,   79,
550
       78,   76,   72,   71,   68,   65,  118,  119,  122,  122,
551

    
552
      122,  122,  122,  122,  123,  123,  123,  123,  123,  123,
553
      124,  124,  124,  124,  124,  124,  125,  125,  125,  125,
554
      125,  125,  126,  126,  126,  126,  127,  127,  128,   59,
555
      128,  129,  129,  131,  131,  132,   56,  132,  132,  132,
556
      132,   50,   42,   40,   39,   34,   32,   31,   30,   27,
557
       26,   25,   24,   23,   20,   19,   18,   17,   11,    9,
558
        4,    3,  121,  121,  121,  121,  121,  121,  121,  121,
559
      121,  121,  121,  121,  121,  121,  121,  121,  121,  121,
560
      121,  121,  121,  121,  121,  121,  121,  121,  121,  121,
561
      121,  121,  121,  121,  121,  121,  121,  121,  121
562

    
563
    } ;
564

    
565
static yy_state_type yy_last_accepting_state;
566
static char *yy_last_accepting_cpos;
567

    
568
extern int cf__flex_debug;
569
int cf__flex_debug = 0;
570

    
571
/* The intent behind this definition is that it'll catch
572
 * any uses of REJECT which flex missed.
573
 */
574
#define REJECT reject_used_but_not_detected
575
#define yymore() yymore_used_but_not_detected
576
#define YY_MORE_ADJ 0
577
#define YY_RESTORE_YY_MORE_OFFSET
578
char *cf_text;
579
#line 1 "conf/cf-lex.l"
580
/*
581
 *        BIRD -- Configuration Lexer
582
 *
583
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
584
 *
585
 *        Can be freely distributed and used under the terms of the GNU GPL.
586
 */
587
/**
588
 * DOC: Lexical analyzer
589
 *
590
 * The lexical analyzer used for configuration files and CLI commands
591
 * is generated using the |flex| tool accompanied by a couple of
592
 * functions maintaining the hash tables containing information about
593
 * symbols and keywords.
594
 *
595
 * Each symbol is represented by a &symbol structure containing name
596
 * of the symbol, its lexical scope, symbol class (%SYM_PROTO for a
597
 * name of a protocol, %SYM_CONSTANT for a constant etc.) and class
598
 * dependent data.  When an unknown symbol is encountered, it's
599
 * automatically added to the symbol table with class %SYM_VOID.
600
 *
601
 * The keyword tables are generated from the grammar templates
602
 * using the |gen_keywords.m4| script.
603
 */
604
#line 28 "conf/cf-lex.l"
605
#undef REJECT     /* Avoid name clashes */
606

    
607
#include <errno.h>
608
#include <stdlib.h>
609
#include <stdarg.h>
610
#include <stdint.h>
611
#include <unistd.h>
612
#include <libgen.h>
613
#include <glob.h>
614
#include <fcntl.h>
615
#include <sys/stat.h>
616
#include <sys/types.h>
617
#include <sys/stat.h>
618

    
619
#define PARSER 1
620

    
621
#include "nest/bird.h"
622
#include "nest/route.h"
623
#include "nest/protocol.h"
624
#include "filter/filter.h"
625
#include "conf/conf.h"
626
#include "conf/cf-parse.tab.h"
627
#include "lib/string.h"
628
#include "lib/hash.h"
629

    
630
struct keyword {
631
  byte *name;
632
  int value;
633
  struct keyword *next;
634
};
635

    
636
#include "conf/keywords.h"
637

    
638
/* Could be defined by Bison in cf-parse.tab.h, inteferes with SYM hash */
639
#ifdef SYM
640
#undef SYM
641
#endif
642

    
643

    
644
static uint cf_hash(byte *c);
645

    
646
#define KW_KEY(n)                n->name
647
#define KW_NEXT(n)                n->next
648
#define KW_EQ(a,b)                !strcmp(a,b)
649
#define KW_FN(k)                cf_hash(k)
650
#define KW_ORDER                8 /* Fixed */
651

    
652
#define SYM_KEY(n)                n->name, n->scope->active
653
#define SYM_NEXT(n)                n->next
654
#define SYM_EQ(a,s1,b,s2)        !strcmp(a,b) && s1 == s2
655
#define SYM_FN(k,s)                cf_hash(k)
656
#define SYM_ORDER                6 /* Initial */
657

    
658
#define SYM_REHASH                sym_rehash
659
#define SYM_PARAMS                /8, *1, 2, 2, 6, 20
660

    
661

    
662
HASH_DEFINE_REHASH_FN(SYM, struct symbol)
663

    
664
HASH(struct keyword) kw_hash;
665

    
666

    
667
static struct sym_scope *conf_this_scope;
668

    
669
linpool *cfg_mem;
670

    
671
int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
672
struct include_file_stack *ifs;
673
static struct include_file_stack *ifs_head;
674

    
675
#define MAX_INCLUDE_DEPTH 8
676

    
677
#define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max, ifs->fd);
678
#define YY_NO_UNPUT
679
#define YY_FATAL_ERROR(msg) cf_error(msg)
680

    
681
static void cf_include(char *arg, int alen);
682
static int check_eof(void);
683

    
684
#define YY_NO_INPUT 1
685

    
686
#line 687 "obj/conf/cf-lex.c"
687

    
688
#define INITIAL 0
689
#define COMMENT 1
690
#define CCOMM 2
691
#define CLI 3
692

    
693
#ifndef YY_NO_UNISTD_H
694
/* Special case for "unistd.h", since it is non-ANSI. We include it way
695
 * down here because we want the user's section 1 to have been scanned first.
696
 * The user has a chance to override it with an option.
697
 */
698
#include <unistd.h>
699
#endif
700

    
701
#ifndef YY_EXTRA_TYPE
702
#define YY_EXTRA_TYPE void *
703
#endif
704

    
705
static int yy_init_globals (void );
706

    
707
/* Accessor methods to globals.
708
   These are made visible to non-reentrant scanners for convenience. */
709

    
710
int cf_lex_destroy (void );
711

    
712
int cf_get_debug (void );
713

    
714
void cf_set_debug (int debug_flag  );
715

    
716
YY_EXTRA_TYPE cf_get_extra (void );
717

    
718
void cf_set_extra (YY_EXTRA_TYPE user_defined  );
719

    
720
FILE *cf_get_in (void );
721

    
722
void cf_set_in  (FILE * _in_str  );
723

    
724
FILE *cf_get_out (void );
725

    
726
void cf_set_out  (FILE * _out_str  );
727

    
728
                        int cf_get_leng (void );
729

    
730
char *cf_get_text (void );
731

    
732
int cf_get_lineno (void );
733

    
734
void cf_set_lineno (int _line_number  );
735

    
736
/* Macros after this point can all be overridden by user definitions in
737
 * section 1.
738
 */
739

    
740
#ifndef YY_SKIP_YYWRAP
741
#ifdef __cplusplus
742
extern "C" int cf_wrap (void );
743
#else
744
extern int cf_wrap (void );
745
#endif
746
#endif
747

    
748
#ifndef YY_NO_UNPUT
749
    
750
#endif
751

    
752
#ifndef yytext_ptr
753
static void yy_flex_strncpy (char *,yyconst char *,int );
754
#endif
755

    
756
#ifdef YY_NEED_STRLEN
757
static int yy_flex_strlen (yyconst char * );
758
#endif
759

    
760
#ifndef YY_NO_INPUT
761

    
762
#ifdef __cplusplus
763
static int yyinput (void );
764
#else
765
static int input (void );
766
#endif
767

    
768
#endif
769

    
770
/* Amount of stuff to slurp up with each read. */
771
#ifndef YY_READ_BUF_SIZE
772
#ifdef __ia64__
773
/* On IA-64, the buffer size is 16k, not 8k */
774
#define YY_READ_BUF_SIZE 16384
775
#else
776
#define YY_READ_BUF_SIZE 8192
777
#endif /* __ia64__ */
778
#endif
779

    
780
/* Copy whatever the last rule matched to the standard output. */
781
#ifndef ECHO
782
/* This used to be an fputs(), but since the string might contain NUL's,
783
 * we now use fwrite().
784
 */
785
#define ECHO do { if (fwrite( cf_text, (size_t) cf_leng, 1, cf_out )) {} } while (0)
786
#endif
787

    
788
/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
789
 * is returned in "result".
790
 */
791
#ifndef YY_INPUT
792
#define YY_INPUT(buf,result,max_size) \
793
        if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
794
                { \
795
                int c = '*'; \
796
                size_t n; \
797
                for ( n = 0; n < max_size && \
798
                             (c = getc( cf_in )) != EOF && c != '\n'; ++n ) \
799
                        buf[n] = (char) c; \
800
                if ( c == '\n' ) \
801
                        buf[n++] = (char) c; \
802
                if ( c == EOF && ferror( cf_in ) ) \
803
                        YY_FATAL_ERROR( "input in flex scanner failed" ); \
804
                result = n; \
805
                } \
806
        else \
807
                { \
808
                errno=0; \
809
                while ( (result = (int) fread(buf, 1, max_size, cf_in))==0 && ferror(cf_in)) \
810
                        { \
811
                        if( errno != EINTR) \
812
                                { \
813
                                YY_FATAL_ERROR( "input in flex scanner failed" ); \
814
                                break; \
815
                                } \
816
                        errno=0; \
817
                        clearerr(cf_in); \
818
                        } \
819
                }\
820
\
821

    
822
#endif
823

    
824
/* No semi-colon after return; correct usage is to write "yyterminate();" -
825
 * we don't want an extra ';' after the "return" because that will cause
826
 * some compilers to complain about unreachable statements.
827
 */
828
#ifndef yyterminate
829
#define yyterminate() return YY_NULL
830
#endif
831

    
832
/* Number of entries by which start-condition stack grows. */
833
#ifndef YY_START_STACK_INCR
834
#define YY_START_STACK_INCR 25
835
#endif
836

    
837
/* Report a fatal error. */
838
#ifndef YY_FATAL_ERROR
839
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
840
#endif
841

    
842
/* end tables serialization structures and prototypes */
843

    
844
/* Default declaration of generated scanner - a define so the user can
845
 * easily add parameters.
846
 */
847
#ifndef YY_DECL
848
#define YY_DECL_IS_OURS 1
849

    
850
extern int cf_lex (void);
851

    
852
#define YY_DECL int cf_lex (void)
853
#endif /* !YY_DECL */
854

    
855
/* Code executed at the beginning of each rule, after cf_text and cf_leng
856
 * have been set up.
857
 */
858
#ifndef YY_USER_ACTION
859
#define YY_USER_ACTION
860
#endif
861

    
862
/* Code executed at the end of each rule. */
863
#ifndef YY_BREAK
864
#define YY_BREAK /*LINTED*/break;
865
#endif
866

    
867
#define YY_RULE_SETUP \
868
        if ( cf_leng > 0 ) \
869
                YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
870
                                (cf_text[cf_leng - 1] == '\n'); \
871
        YY_USER_ACTION
872

    
873
/** The main scanner function which does all the work.
874
 */
875
YY_DECL
876
{
877
        yy_state_type yy_current_state;
878
        char *yy_cp, *yy_bp;
879
        int yy_act;
880
    
881
        if ( !(yy_init) )
882
                {
883
                (yy_init) = 1;
884

    
885
#ifdef YY_USER_INIT
886
                YY_USER_INIT;
887
#endif
888

    
889
                if ( ! (yy_start) )
890
                        (yy_start) = 1;        /* first start state */
891

    
892
                if ( ! cf_in )
893
                        cf_in = stdin;
894

    
895
                if ( ! cf_out )
896
                        cf_out = stdout;
897

    
898
                if ( ! YY_CURRENT_BUFFER ) {
899
                        cf_ensure_buffer_stack ();
900
                        YY_CURRENT_BUFFER_LVALUE =
901
                                cf__create_buffer(cf_in,YY_BUF_SIZE );
902
                }
903

    
904
                cf__load_buffer_state( );
905
                }
906

    
907
        {
908
#line 123 "conf/cf-lex.l"
909

    
910
#line 911 "obj/conf/cf-lex.c"
911

    
912
        while ( /*CONSTCOND*/1 )                /* loops until end-of-file is reached */
913
                {
914
                yy_cp = (yy_c_buf_p);
915

    
916
                /* Support of cf_text. */
917
                *yy_cp = (yy_hold_char);
918

    
919
                /* yy_bp points to the position in yy_ch_buf of the start of
920
                 * the current run.
921
                 */
922
                yy_bp = yy_cp;
923

    
924
                yy_current_state = (yy_start);
925
                yy_current_state += YY_AT_BOL();
926
yy_match:
927
                do
928
                        {
929
                        YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
930
                        if ( yy_accept[yy_current_state] )
931
                                {
932
                                (yy_last_accepting_state) = yy_current_state;
933
                                (yy_last_accepting_cpos) = yy_cp;
934
                                }
935
                        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
936
                                {
937
                                yy_current_state = (int) yy_def[yy_current_state];
938
                                if ( yy_current_state >= 122 )
939
                                        yy_c = yy_meta[(unsigned int) yy_c];
940
                                }
941
                        yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
942
                        ++yy_cp;
943
                        }
944
                while ( yy_current_state != 121 );
945
                yy_cp = (yy_last_accepting_cpos);
946
                yy_current_state = (yy_last_accepting_state);
947

    
948
yy_find_action:
949
                yy_act = yy_accept[yy_current_state];
950

    
951
                YY_DO_BEFORE_ACTION;
952

    
953
do_action:        /* This label is used only to access EOF actions. */
954

    
955
                switch ( yy_act )
956
        { /* beginning of action switch */
957
                        case 0: /* must back up */
958
                        /* undo the effects of YY_DO_BEFORE_ACTION */
959
                        *yy_cp = (yy_hold_char);
960
                        yy_cp = (yy_last_accepting_cpos);
961
                        yy_current_state = (yy_last_accepting_state);
962
                        goto yy_find_action;
963

    
964
case 1:
965
YY_RULE_SETUP
966
#line 124 "conf/cf-lex.l"
967
{
968
  char *start, *end;
969

    
970
  if (!ifs->depth)
971
    cf_error("Include not allowed in CLI");
972

    
973
  start = strchr(cf_text, '"');
974
  start++;
975

    
976
  end = strchr(start, '"');
977
  *end = 0;
978

    
979
  if (start == end)
980
    cf_error("Include with empty argument");
981

    
982
  cf_include(start, end-start);
983
}
984
        YY_BREAK
985
case 2:
986
YY_RULE_SETUP
987
#line 142 "conf/cf-lex.l"
988
{
989
  uint len1 UNUSED, len2;
990
  u64 l;
991
  char *e;
992

    
993
  errno = 0;
994
  l = strtoul(cf_text, &e, 10);
995
  if (e && (*e != ':') || (errno == ERANGE) || (l >> 32))
996
    cf_error("ASN out of range");
997

    
998
  if (l >> 16)
999
  {
1000
    len1 = 32;
1001
    len2 = 16;
1002
    cf_lval.i64 = (2ULL << 48) | (((u64) l) << len2);
1003
  }
1004
  else
1005
  {
1006
    len1 = 16;
1007
    len2 = 32;
1008
    cf_lval.i64 = 0 | (((u64) l) << len2);
1009
  }
1010

    
1011
  errno = 0;
1012
  l = strtoul(e+1, &e, 10);
1013
  if (e && *e || (errno == ERANGE) || (l >> len2))
1014
    cf_error("Number out of range");
1015
  cf_lval.i64 |= l;
1016

    
1017
  return VPN_RD;
1018
}
1019
        YY_BREAK
1020
case 3:
1021
YY_RULE_SETUP
1022
#line 174 "conf/cf-lex.l"
1023
{
1024
  uint len1, len2;
1025
  u64 l;
1026
  char *e;
1027

    
1028
  if (cf_text[0] == '0')
1029
  {
1030
    cf_lval.i64 = 0;
1031
    len1 = 16;
1032
    len2 = 32;
1033
  }
1034
  else
1035
  {
1036
    cf_lval.i64 = 2ULL << 48;
1037
    len1 = 32;
1038
    len2 = 16;
1039
  }
1040

    
1041
  errno = 0;
1042
  l = strtoul(cf_text+2, &e, 10);
1043
  if (e && (*e != ':') || (errno == ERANGE) || (l >> len1))
1044
    cf_error("ASN out of range");
1045
  cf_lval.i64 |= ((u64) l) << len2;
1046

    
1047
  errno = 0;
1048
  l = strtoul(e+1, &e, 10);
1049
  if (e && *e || (errno == ERANGE) || (l >> len2))
1050
    cf_error("Number out of range");
1051
  cf_lval.i64 |= l;
1052

    
1053
  return VPN_RD;
1054
}
1055
        YY_BREAK
1056
case 4:
1057
YY_RULE_SETUP
1058
#line 207 "conf/cf-lex.l"
1059
{
1060
  unsigned long int l;
1061
  ip4_addr ip4;
1062
  char *e;
1063

    
1064
  cf_lval.i64 = 1ULL << 48;
1065

    
1066
  e = strchr(cf_text, ':');
1067
  *e++ = '\0';
1068
  if (!ip4_pton(cf_text, &ip4))
1069
    cf_error("Invalid IPv4 address %s in Route Distinguisher", cf_text);
1070
  cf_lval.i64 |= ((u64) ip4_to_u32(ip4)) << 16;
1071

    
1072
  errno = 0;
1073
  l = strtoul(e, &e, 10);
1074
  if (e && *e || (errno == ERANGE) || (l >> 16))
1075
    cf_error("Number out of range");
1076
  cf_lval.i64 |= l;
1077

    
1078
  return VPN_RD;
1079
}
1080
        YY_BREAK
1081
case 5:
1082
YY_RULE_SETUP
1083
#line 229 "conf/cf-lex.l"
1084
{
1085
  if (!ip4_pton(cf_text, &cf_lval.ip4))
1086
    cf_error("Invalid IPv4 address %s", cf_text);
1087
  return IP4;
1088
}
1089
        YY_BREAK
1090
case 6:
1091
YY_RULE_SETUP
1092
#line 235 "conf/cf-lex.l"
1093
{
1094
  if (!ip6_pton(cf_text, &cf_lval.ip6))
1095
    cf_error("Invalid IPv6 address %s", cf_text);
1096
  return IP6;
1097
}
1098
        YY_BREAK
1099
case 7:
1100
YY_RULE_SETUP
1101
#line 241 "conf/cf-lex.l"
1102
{
1103
  char *e;
1104
  unsigned long int l;
1105
  errno = 0;
1106
  l = strtoul(cf_text+2, &e, 16);
1107
  if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
1108
    cf_error("Number out of range");
1109
  cf_lval.i = l;
1110
  return NUM;
1111
}
1112
        YY_BREAK
1113
case 8:
1114
YY_RULE_SETUP
1115
#line 252 "conf/cf-lex.l"
1116
{
1117
  char *e;
1118
  unsigned long int l;
1119
  errno = 0;
1120
  l = strtoul(cf_text, &e, 10);
1121
  if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
1122
    cf_error("Number out of range");
1123
  cf_lval.i = l;
1124
  return NUM;
1125
}
1126
        YY_BREAK
1127
case 9:
1128
YY_RULE_SETUP
1129
#line 263 "conf/cf-lex.l"
1130
{
1131
  /* Hack to distinguish if..else from else: in case */
1132
  return ELSECOL;
1133
}
1134
        YY_BREAK
1135
case 10:
1136
YY_RULE_SETUP
1137
#line 268 "conf/cf-lex.l"
1138
{
1139
  if(*cf_text == '\'') {
1140
    cf_text[cf_leng-1] = 0;
1141
    cf_text++;
1142
  }
1143

    
1144
  struct keyword *k = HASH_FIND(kw_hash, KW, cf_text);
1145
  if (k)
1146
  {
1147
    if (k->value > 0)
1148
      return k->value;
1149
    else
1150
    {
1151
      cf_lval.i = -k->value;
1152
      return ENUM;
1153
    }
1154
  }
1155

    
1156
  cf_lval.s = cf_get_symbol(cf_text);
1157
  return SYM;
1158
}
1159
        YY_BREAK
1160
case 11:
1161
/* rule 11 can match eol */
1162
YY_RULE_SETUP
1163
#line 290 "conf/cf-lex.l"
1164
{
1165
  BEGIN(INITIAL);
1166
  return CLI_MARKER;
1167
}
1168
        YY_BREAK
1169
case 12:
1170
YY_RULE_SETUP
1171
#line 295 "conf/cf-lex.l"
1172
{
1173
  return DDOT;
1174
}
1175
        YY_BREAK
1176
case 13:
1177
YY_RULE_SETUP
1178
#line 299 "conf/cf-lex.l"
1179
{
1180
  return cf_text[0];
1181
}
1182
        YY_BREAK
1183
case 14:
1184
YY_RULE_SETUP
1185
#line 303 "conf/cf-lex.l"
1186
{
1187
  cf_text[cf_leng-1] = 0;
1188
  cf_lval.t = cfg_strdup(cf_text+1);
1189
  cf_text[cf_leng-1] = '"';
1190
  return TEXT;
1191
}
1192
        YY_BREAK
1193
case 15:
1194
/* rule 15 can match eol */
1195
YY_RULE_SETUP
1196
#line 310 "conf/cf-lex.l"
1197
cf_error("Unterminated string");
1198
        YY_BREAK
1199
case YY_STATE_EOF(INITIAL):
1200
case YY_STATE_EOF(COMMENT):
1201
#line 312 "conf/cf-lex.l"
1202
{ if (check_eof()) return END; }
1203
        YY_BREAK
1204
case 16:
1205
YY_RULE_SETUP
1206
#line 314 "conf/cf-lex.l"
1207

    
1208
        YY_BREAK
1209
case 17:
1210
/* rule 17 can match eol */
1211
YY_RULE_SETUP
1212
#line 316 "conf/cf-lex.l"
1213
ifs->lino++;
1214
        YY_BREAK
1215
case 18:
1216
YY_RULE_SETUP
1217
#line 318 "conf/cf-lex.l"
1218
BEGIN(COMMENT);
1219
        YY_BREAK
1220
case 19:
1221
YY_RULE_SETUP
1222
#line 320 "conf/cf-lex.l"
1223
BEGIN(CCOMM);
1224
        YY_BREAK
1225
case 20:
1226
YY_RULE_SETUP
1227
#line 322 "conf/cf-lex.l"
1228
cf_error("Unknown character");
1229
        YY_BREAK
1230
case 21:
1231
/* rule 21 can match eol */
1232
YY_RULE_SETUP
1233
#line 324 "conf/cf-lex.l"
1234
{
1235
  ifs->lino++;
1236
  BEGIN(INITIAL);
1237
}
1238
        YY_BREAK
1239
case 22:
1240
YY_RULE_SETUP
1241
#line 329 "conf/cf-lex.l"
1242

    
1243
        YY_BREAK
1244
case 23:
1245
YY_RULE_SETUP
1246
#line 331 "conf/cf-lex.l"
1247
BEGIN(INITIAL);
1248
        YY_BREAK
1249
case 24:
1250
/* rule 24 can match eol */
1251
YY_RULE_SETUP
1252
#line 332 "conf/cf-lex.l"
1253
ifs->lino++;
1254
        YY_BREAK
1255
case 25:
1256
YY_RULE_SETUP
1257
#line 333 "conf/cf-lex.l"
1258
cf_error("Comment nesting not supported");
1259
        YY_BREAK
1260
case YY_STATE_EOF(CCOMM):
1261
#line 334 "conf/cf-lex.l"
1262
cf_error("Unterminated comment");
1263
        YY_BREAK
1264
case 26:
1265
YY_RULE_SETUP
1266
#line 335 "conf/cf-lex.l"
1267

    
1268
        YY_BREAK
1269
case 27:
1270
YY_RULE_SETUP
1271
#line 337 "conf/cf-lex.l"
1272
return NEQ;
1273
        YY_BREAK
1274
case 28:
1275
YY_RULE_SETUP
1276
#line 338 "conf/cf-lex.l"
1277
return NMA;
1278
        YY_BREAK
1279
case 29:
1280
YY_RULE_SETUP
1281
#line 339 "conf/cf-lex.l"
1282
return LEQ;
1283
        YY_BREAK
1284
case 30:
1285
YY_RULE_SETUP
1286
#line 340 "conf/cf-lex.l"
1287
return GEQ;
1288
        YY_BREAK
1289
case 31:
1290
YY_RULE_SETUP
1291
#line 341 "conf/cf-lex.l"
1292
return AND;
1293
        YY_BREAK
1294
case 32:
1295
YY_RULE_SETUP
1296
#line 342 "conf/cf-lex.l"
1297
return OR;
1298
        YY_BREAK
1299
case 33:
1300
YY_RULE_SETUP
1301
#line 344 "conf/cf-lex.l"
1302
return PO;
1303
        YY_BREAK
1304
case 34:
1305
YY_RULE_SETUP
1306
#line 345 "conf/cf-lex.l"
1307
return PC;
1308
        YY_BREAK
1309
case 35:
1310
YY_RULE_SETUP
1311
#line 347 "conf/cf-lex.l"
1312
YY_FATAL_ERROR( "flex scanner jammed" );
1313
        YY_BREAK
1314
#line 1315 "obj/conf/cf-lex.c"
1315
case YY_STATE_EOF(CLI):
1316
        yyterminate();
1317

    
1318
        case YY_END_OF_BUFFER:
1319
                {
1320
                /* Amount of text matched not including the EOB char. */
1321
                int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
1322

    
1323
                /* Undo the effects of YY_DO_BEFORE_ACTION. */
1324
                *yy_cp = (yy_hold_char);
1325
                YY_RESTORE_YY_MORE_OFFSET
1326

    
1327
                if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1328
                        {
1329
                        /* We're scanning a new file or input source.  It's
1330
                         * possible that this happened because the user
1331
                         * just pointed cf_in at a new source and called
1332
                         * cf_lex().  If so, then we have to assure
1333
                         * consistency between YY_CURRENT_BUFFER and our
1334
                         * globals.  Here is the right place to do so, because
1335
                         * this is the first action (other than possibly a
1336
                         * back-up) that will match for the new input source.
1337
                         */
1338
                        (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1339
                        YY_CURRENT_BUFFER_LVALUE->yy_input_file = cf_in;
1340
                        YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1341
                        }
1342

    
1343
                /* Note that here we test for yy_c_buf_p "<=" to the position
1344
                 * of the first EOB in the buffer, since yy_c_buf_p will
1345
                 * already have been incremented past the NUL character
1346
                 * (since all states make transitions on EOB to the
1347
                 * end-of-buffer state).  Contrast this with the test
1348
                 * in input().
1349
                 */
1350
                if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1351
                        { /* This was really a NUL. */
1352
                        yy_state_type yy_next_state;
1353

    
1354
                        (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
1355

    
1356
                        yy_current_state = yy_get_previous_state(  );
1357

    
1358
                        /* Okay, we're now positioned to make the NUL
1359
                         * transition.  We couldn't have
1360
                         * yy_get_previous_state() go ahead and do it
1361
                         * for us because it doesn't know how to deal
1362
                         * with the possibility of jamming (and we don't
1363
                         * want to build jamming into it because then it
1364
                         * will run more slowly).
1365
                         */
1366

    
1367
                        yy_next_state = yy_try_NUL_trans( yy_current_state );
1368

    
1369
                        yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1370

    
1371
                        if ( yy_next_state )
1372
                                {
1373
                                /* Consume the NUL. */
1374
                                yy_cp = ++(yy_c_buf_p);
1375
                                yy_current_state = yy_next_state;
1376
                                goto yy_match;
1377
                                }
1378

    
1379
                        else
1380
                                {
1381
                                yy_cp = (yy_last_accepting_cpos);
1382
                                yy_current_state = (yy_last_accepting_state);
1383
                                goto yy_find_action;
1384
                                }
1385
                        }
1386

    
1387
                else switch ( yy_get_next_buffer(  ) )
1388
                        {
1389
                        case EOB_ACT_END_OF_FILE:
1390
                                {
1391
                                (yy_did_buffer_switch_on_eof) = 0;
1392

    
1393
                                if ( cf_wrap( ) )
1394
                                        {
1395
                                        /* Note: because we've taken care in
1396
                                         * yy_get_next_buffer() to have set up
1397
                                         * cf_text, we can now set up
1398
                                         * yy_c_buf_p so that if some total
1399
                                         * hoser (like flex itself) wants to
1400
                                         * call the scanner after we return the
1401
                                         * YY_NULL, it'll still work - another
1402
                                         * YY_NULL will get returned.
1403
                                         */
1404
                                        (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
1405

    
1406
                                        yy_act = YY_STATE_EOF(YY_START);
1407
                                        goto do_action;
1408
                                        }
1409

    
1410
                                else
1411
                                        {
1412
                                        if ( ! (yy_did_buffer_switch_on_eof) )
1413
                                                YY_NEW_FILE;
1414
                                        }
1415
                                break;
1416
                                }
1417

    
1418
                        case EOB_ACT_CONTINUE_SCAN:
1419
                                (yy_c_buf_p) =
1420
                                        (yytext_ptr) + yy_amount_of_matched_text;
1421

    
1422
                                yy_current_state = yy_get_previous_state(  );
1423

    
1424
                                yy_cp = (yy_c_buf_p);
1425
                                yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1426
                                goto yy_match;
1427

    
1428
                        case EOB_ACT_LAST_MATCH:
1429
                                (yy_c_buf_p) =
1430
                                &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
1431

    
1432
                                yy_current_state = yy_get_previous_state(  );
1433

    
1434
                                yy_cp = (yy_c_buf_p);
1435
                                yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1436
                                goto yy_find_action;
1437
                        }
1438
                break;
1439
                }
1440

    
1441
        default:
1442
                YY_FATAL_ERROR(
1443
                        "fatal flex scanner internal error--no action found" );
1444
        } /* end of action switch */
1445
                } /* end of scanning one token */
1446
        } /* end of user's declarations */
1447
} /* end of cf_lex */
1448

    
1449
/* yy_get_next_buffer - try to read in a new buffer
1450
 *
1451
 * Returns a code representing an action:
1452
 *        EOB_ACT_LAST_MATCH -
1453
 *        EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1454
 *        EOB_ACT_END_OF_FILE - end of file
1455
 */
1456
static int yy_get_next_buffer (void)
1457
{
1458
            char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1459
        char *source = (yytext_ptr);
1460
        int number_to_move, i;
1461
        int ret_val;
1462

    
1463
        if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1464
                YY_FATAL_ERROR(
1465
                "fatal flex scanner internal error--end of buffer missed" );
1466

    
1467
        if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1468
                { /* Don't try to fill the buffer, so this is an EOF. */
1469
                if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
1470
                        {
1471
                        /* We matched a single character, the EOB, so
1472
                         * treat this as a final EOF.
1473
                         */
1474
                        return EOB_ACT_END_OF_FILE;
1475
                        }
1476

    
1477
                else
1478
                        {
1479
                        /* We matched some text prior to the EOB, first
1480
                         * process it.
1481
                         */
1482
                        return EOB_ACT_LAST_MATCH;
1483
                        }
1484
                }
1485

    
1486
        /* Try to read more data. */
1487

    
1488
        /* First move last chars to start of buffer. */
1489
        number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
1490

    
1491
        for ( i = 0; i < number_to_move; ++i )
1492
                *(dest++) = *(source++);
1493

    
1494
        if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1495
                /* don't do the read, it's not guaranteed to return an EOF,
1496
                 * just force an EOF
1497
                 */
1498
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
1499

    
1500
        else
1501
                {
1502
                        int num_to_read =
1503
                        YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1504

    
1505
                while ( num_to_read <= 0 )
1506
                        { /* Not enough room in the buffer - grow it. */
1507

    
1508
                        /* just a shorter name for the current buffer */
1509
                        YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1510

    
1511
                        int yy_c_buf_p_offset =
1512
                                (int) ((yy_c_buf_p) - b->yy_ch_buf);
1513

    
1514
                        if ( b->yy_is_our_buffer )
1515
                                {
1516
                                int new_size = b->yy_buf_size * 2;
1517

    
1518
                                if ( new_size <= 0 )
1519
                                        b->yy_buf_size += b->yy_buf_size / 8;
1520
                                else
1521
                                        b->yy_buf_size *= 2;
1522

    
1523
                                b->yy_ch_buf = (char *)
1524
                                        /* Include room in for 2 EOB chars. */
1525
                                        cf_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2  );
1526
                                }
1527
                        else
1528
                                /* Can't grow it, we don't own it. */
1529
                                b->yy_ch_buf = NULL;
1530

    
1531
                        if ( ! b->yy_ch_buf )
1532
                                YY_FATAL_ERROR(
1533
                                "fatal error - scanner input buffer overflow" );
1534

    
1535
                        (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
1536

    
1537
                        num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1538
                                                number_to_move - 1;
1539

    
1540
                        }
1541

    
1542
                if ( num_to_read > YY_READ_BUF_SIZE )
1543
                        num_to_read = YY_READ_BUF_SIZE;
1544

    
1545
                /* Read in more data. */
1546
                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1547
                        (yy_n_chars), num_to_read );
1548

    
1549
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1550
                }
1551

    
1552
        if ( (yy_n_chars) == 0 )
1553
                {
1554
                if ( number_to_move == YY_MORE_ADJ )
1555
                        {
1556
                        ret_val = EOB_ACT_END_OF_FILE;
1557
                        cf_restart(cf_in  );
1558
                        }
1559

    
1560
                else
1561
                        {
1562
                        ret_val = EOB_ACT_LAST_MATCH;
1563
                        YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1564
                                YY_BUFFER_EOF_PENDING;
1565
                        }
1566
                }
1567

    
1568
        else
1569
                ret_val = EOB_ACT_CONTINUE_SCAN;
1570

    
1571
        if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1572
                /* Extend the array by 50%, plus the number we really need. */
1573
                int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1574
                YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cf_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
1575
                if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1576
                        YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1577
        }
1578

    
1579
        (yy_n_chars) += number_to_move;
1580
        YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
1581
        YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
1582

    
1583
        (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1584

    
1585
        return ret_val;
1586
}
1587

    
1588
/* yy_get_previous_state - get the state just before the EOB char was reached */
1589

    
1590
    static yy_state_type yy_get_previous_state (void)
1591
{
1592
        yy_state_type yy_current_state;
1593
        char *yy_cp;
1594
    
1595
        yy_current_state = (yy_start);
1596
        yy_current_state += YY_AT_BOL();
1597

    
1598
        for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1599
                {
1600
                YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1601
                if ( yy_accept[yy_current_state] )
1602
                        {
1603
                        (yy_last_accepting_state) = yy_current_state;
1604
                        (yy_last_accepting_cpos) = yy_cp;
1605
                        }
1606
                while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1607
                        {
1608
                        yy_current_state = (int) yy_def[yy_current_state];
1609
                        if ( yy_current_state >= 122 )
1610
                                yy_c = yy_meta[(unsigned int) yy_c];
1611
                        }
1612
                yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1613
                }
1614

    
1615
        return yy_current_state;
1616
}
1617

    
1618
/* yy_try_NUL_trans - try to make a transition on the NUL character
1619
 *
1620
 * synopsis
1621
 *        next_state = yy_try_NUL_trans( current_state );
1622
 */
1623
    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state )
1624
{
1625
        int yy_is_jam;
1626
            char *yy_cp = (yy_c_buf_p);
1627

    
1628
        YY_CHAR yy_c = 1;
1629
        if ( yy_accept[yy_current_state] )
1630
                {
1631
                (yy_last_accepting_state) = yy_current_state;
1632
                (yy_last_accepting_cpos) = yy_cp;
1633
                }
1634
        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1635
                {
1636
                yy_current_state = (int) yy_def[yy_current_state];
1637
                if ( yy_current_state >= 122 )
1638
                        yy_c = yy_meta[(unsigned int) yy_c];
1639
                }
1640
        yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1641
        yy_is_jam = (yy_current_state == 121);
1642

    
1643
                return yy_is_jam ? 0 : yy_current_state;
1644
}
1645

    
1646
#ifndef YY_NO_UNPUT
1647

    
1648
#endif
1649

    
1650
#ifndef YY_NO_INPUT
1651
#ifdef __cplusplus
1652
    static int yyinput (void)
1653
#else
1654
    static int input  (void)
1655
#endif
1656

    
1657
{
1658
        int c;
1659
    
1660
        *(yy_c_buf_p) = (yy_hold_char);
1661

    
1662
        if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
1663
                {
1664
                /* yy_c_buf_p now points to the character we want to return.
1665
                 * If this occurs *before* the EOB characters, then it's a
1666
                 * valid NUL; if not, then we've hit the end of the buffer.
1667
                 */
1668
                if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1669
                        /* This was really a NUL. */
1670
                        *(yy_c_buf_p) = '\0';
1671

    
1672
                else
1673
                        { /* need more input */
1674
                        int offset = (yy_c_buf_p) - (yytext_ptr);
1675
                        ++(yy_c_buf_p);
1676

    
1677
                        switch ( yy_get_next_buffer(  ) )
1678
                                {
1679
                                case EOB_ACT_LAST_MATCH:
1680
                                        /* This happens because yy_g_n_b()
1681
                                         * sees that we've accumulated a
1682
                                         * token and flags that we need to
1683
                                         * try matching the token before
1684
                                         * proceeding.  But for input(),
1685
                                         * there's no matching to consider.
1686
                                         * So convert the EOB_ACT_LAST_MATCH
1687
                                         * to EOB_ACT_END_OF_FILE.
1688
                                         */
1689

    
1690
                                        /* Reset buffer status. */
1691
                                        cf_restart(cf_in );
1692

    
1693
                                        /*FALLTHROUGH*/
1694

    
1695
                                case EOB_ACT_END_OF_FILE:
1696
                                        {
1697
                                        if ( cf_wrap( ) )
1698
                                                return 0;
1699

    
1700
                                        if ( ! (yy_did_buffer_switch_on_eof) )
1701
                                                YY_NEW_FILE;
1702
#ifdef __cplusplus
1703
                                        return yyinput();
1704
#else
1705
                                        return input();
1706
#endif
1707
                                        }
1708

    
1709
                                case EOB_ACT_CONTINUE_SCAN:
1710
                                        (yy_c_buf_p) = (yytext_ptr) + offset;
1711
                                        break;
1712
                                }
1713
                        }
1714
                }
1715

    
1716
        c = *(unsigned char *) (yy_c_buf_p);        /* cast for 8-bit char's */
1717
        *(yy_c_buf_p) = '\0';        /* preserve cf_text */
1718
        (yy_hold_char) = *++(yy_c_buf_p);
1719

    
1720
        YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n');
1721

    
1722
        return c;
1723
}
1724
#endif        /* ifndef YY_NO_INPUT */
1725

    
1726
/** Immediately switch to a different input stream.
1727
 * @param input_file A readable stream.
1728
 * 
1729
 * @note This function does not reset the start condition to @c INITIAL .
1730
 */
1731
    void cf_restart  (FILE * input_file )
1732
{
1733
    
1734
        if ( ! YY_CURRENT_BUFFER ){
1735
        cf_ensure_buffer_stack ();
1736
                YY_CURRENT_BUFFER_LVALUE =
1737
            cf__create_buffer(cf_in,YY_BUF_SIZE );
1738
        }
1739

    
1740
        cf__init_buffer(YY_CURRENT_BUFFER,input_file );
1741
        cf__load_buffer_state( );
1742
}
1743

    
1744
/** Switch to a different input buffer.
1745
 * @param new_buffer The new input buffer.
1746
 * 
1747
 */
1748
    void cf__switch_to_buffer  (YY_BUFFER_STATE  new_buffer )
1749
{
1750
    
1751
        /* TODO. We should be able to replace this entire function body
1752
         * with
1753
         *                cf_pop_buffer_state();
1754
         *                cf_push_buffer_state(new_buffer);
1755
     */
1756
        cf_ensure_buffer_stack ();
1757
        if ( YY_CURRENT_BUFFER == new_buffer )
1758
                return;
1759

    
1760
        if ( YY_CURRENT_BUFFER )
1761
                {
1762
                /* Flush out information for old buffer. */
1763
                *(yy_c_buf_p) = (yy_hold_char);
1764
                YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1765
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1766
                }
1767

    
1768
        YY_CURRENT_BUFFER_LVALUE = new_buffer;
1769
        cf__load_buffer_state( );
1770

    
1771
        /* We don't actually know whether we did this switch during
1772
         * EOF (cf_wrap()) processing, but the only time this flag
1773
         * is looked at is after cf_wrap() is called, so it's safe
1774
         * to go ahead and always set it.
1775
         */
1776
        (yy_did_buffer_switch_on_eof) = 1;
1777
}
1778

    
1779
static void cf__load_buffer_state  (void)
1780
{
1781
            (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1782
        (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1783
        cf_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1784
        (yy_hold_char) = *(yy_c_buf_p);
1785
}
1786

    
1787
/** Allocate and initialize an input buffer state.
1788
 * @param file A readable stream.
1789
 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1790
 * 
1791
 * @return the allocated buffer state.
1792
 */
1793
    YY_BUFFER_STATE cf__create_buffer  (FILE * file, int  size )
1794
{
1795
        YY_BUFFER_STATE b;
1796
    
1797
        b = (YY_BUFFER_STATE) cf_alloc(sizeof( struct yy_buffer_state )  );
1798
        if ( ! b )
1799
                YY_FATAL_ERROR( "out of dynamic memory in cf__create_buffer()" );
1800

    
1801
        b->yy_buf_size = (yy_size_t)size;
1802

    
1803
        /* yy_ch_buf has to be 2 characters longer than the size given because
1804
         * we need to put in 2 end-of-buffer characters.
1805
         */
1806
        b->yy_ch_buf = (char *) cf_alloc(b->yy_buf_size + 2  );
1807
        if ( ! b->yy_ch_buf )
1808
                YY_FATAL_ERROR( "out of dynamic memory in cf__create_buffer()" );
1809

    
1810
        b->yy_is_our_buffer = 1;
1811

    
1812
        cf__init_buffer(b,file );
1813

    
1814
        return b;
1815
}
1816

    
1817
/** Destroy the buffer.
1818
 * @param b a buffer created with cf__create_buffer()
1819
 * 
1820
 */
1821
    void cf__delete_buffer (YY_BUFFER_STATE  b )
1822
{
1823
    
1824
        if ( ! b )
1825
                return;
1826

    
1827
        if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1828
                YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1829

    
1830
        if ( b->yy_is_our_buffer )
1831
                cf_free((void *) b->yy_ch_buf  );
1832

    
1833
        cf_free((void *) b  );
1834
}
1835

    
1836
/* Initializes or reinitializes a buffer.
1837
 * This function is sometimes called more than once on the same buffer,
1838
 * such as during a cf_restart() or at EOF.
1839
 */
1840
    static void cf__init_buffer  (YY_BUFFER_STATE  b, FILE * file )
1841

    
1842
{
1843
        int oerrno = errno;
1844
    
1845
        cf__flush_buffer(b );
1846

    
1847
        b->yy_input_file = file;
1848
        b->yy_fill_buffer = 1;
1849

    
1850
    /* If b is the current buffer, then cf__init_buffer was _probably_
1851
     * called from cf_restart() or through yy_get_next_buffer.
1852
     * In that case, we don't want to reset the lineno or column.
1853
     */
1854
    if (b != YY_CURRENT_BUFFER){
1855
        b->yy_bs_lineno = 1;
1856
        b->yy_bs_column = 0;
1857
    }
1858

    
1859
        b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
1860
    
1861
        errno = oerrno;
1862
}
1863

    
1864
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1865
 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1866
 * 
1867
 */
1868
    void cf__flush_buffer (YY_BUFFER_STATE  b )
1869
{
1870
            if ( ! b )
1871
                return;
1872

    
1873
        b->yy_n_chars = 0;
1874

    
1875
        /* We always need two end-of-buffer characters.  The first causes
1876
         * a transition to the end-of-buffer state.  The second causes
1877
         * a jam in that state.
1878
         */
1879
        b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1880
        b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1881

    
1882
        b->yy_buf_pos = &b->yy_ch_buf[0];
1883

    
1884
        b->yy_at_bol = 1;
1885
        b->yy_buffer_status = YY_BUFFER_NEW;
1886

    
1887
        if ( b == YY_CURRENT_BUFFER )
1888
                cf__load_buffer_state( );
1889
}
1890

    
1891
/** Pushes the new state onto the stack. The new state becomes
1892
 *  the current state. This function will allocate the stack
1893
 *  if necessary.
1894
 *  @param new_buffer The new state.
1895
 *  
1896
 */
1897
void cf_push_buffer_state (YY_BUFFER_STATE new_buffer )
1898
{
1899
            if (new_buffer == NULL)
1900
                return;
1901

    
1902
        cf_ensure_buffer_stack();
1903

    
1904
        /* This block is copied from cf__switch_to_buffer. */
1905
        if ( YY_CURRENT_BUFFER )
1906
                {
1907
                /* Flush out information for old buffer. */
1908
                *(yy_c_buf_p) = (yy_hold_char);
1909
                YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1910
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1911
                }
1912

    
1913
        /* Only push if top exists. Otherwise, replace top. */
1914
        if (YY_CURRENT_BUFFER)
1915
                (yy_buffer_stack_top)++;
1916
        YY_CURRENT_BUFFER_LVALUE = new_buffer;
1917

    
1918
        /* copied from cf__switch_to_buffer. */
1919
        cf__load_buffer_state( );
1920
        (yy_did_buffer_switch_on_eof) = 1;
1921
}
1922

    
1923
/** Removes and deletes the top of the stack, if present.
1924
 *  The next element becomes the new top.
1925
 *  
1926
 */
1927
void cf_pop_buffer_state (void)
1928
{
1929
            if (!YY_CURRENT_BUFFER)
1930
                return;
1931

    
1932
        cf__delete_buffer(YY_CURRENT_BUFFER );
1933
        YY_CURRENT_BUFFER_LVALUE = NULL;
1934
        if ((yy_buffer_stack_top) > 0)
1935
                --(yy_buffer_stack_top);
1936

    
1937
        if (YY_CURRENT_BUFFER) {
1938
                cf__load_buffer_state( );
1939
                (yy_did_buffer_switch_on_eof) = 1;
1940
        }
1941
}
1942

    
1943
/* Allocates the stack if it does not exist.
1944
 *  Guarantees space for at least one push.
1945
 */
1946
static void cf_ensure_buffer_stack (void)
1947
{
1948
        int num_to_alloc;
1949
    
1950
        if (!(yy_buffer_stack)) {
1951

    
1952
                /* First allocation is just for 2 elements, since we don't know if this
1953
                 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1954
                 * immediate realloc on the next call.
1955
         */
1956
      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1957
                (yy_buffer_stack) = (struct yy_buffer_state**)cf_alloc
1958
                                                                (num_to_alloc * sizeof(struct yy_buffer_state*)
1959
                                                                );
1960
                if ( ! (yy_buffer_stack) )
1961
                        YY_FATAL_ERROR( "out of dynamic memory in cf_ensure_buffer_stack()" );
1962

    
1963
                memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1964

    
1965
                (yy_buffer_stack_max) = num_to_alloc;
1966
                (yy_buffer_stack_top) = 0;
1967
                return;
1968
        }
1969

    
1970
        if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1971

    
1972
                /* Increase the buffer to prepare for a possible push. */
1973
                yy_size_t grow_size = 8 /* arbitrary grow size */;
1974

    
1975
                num_to_alloc = (yy_buffer_stack_max) + grow_size;
1976
                (yy_buffer_stack) = (struct yy_buffer_state**)cf_realloc
1977
                                                                ((yy_buffer_stack),
1978
                                                                num_to_alloc * sizeof(struct yy_buffer_state*)
1979
                                                                );
1980
                if ( ! (yy_buffer_stack) )
1981
                        YY_FATAL_ERROR( "out of dynamic memory in cf_ensure_buffer_stack()" );
1982

    
1983
                /* zero only the new slots.*/
1984
                memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
1985
                (yy_buffer_stack_max) = num_to_alloc;
1986
        }
1987
}
1988

    
1989
/** Setup the input buffer state to scan directly from a user-specified character buffer.
1990
 * @param base the character buffer
1991
 * @param size the size in bytes of the character buffer
1992
 * 
1993
 * @return the newly allocated buffer state object.
1994
 */
1995
YY_BUFFER_STATE cf__scan_buffer  (char * base, yy_size_t  size )
1996
{
1997
        YY_BUFFER_STATE b;
1998
    
1999
        if ( size < 2 ||
2000
             base[size-2] != YY_END_OF_BUFFER_CHAR ||
2001
             base[size-1] != YY_END_OF_BUFFER_CHAR )
2002
                /* They forgot to leave room for the EOB's. */
2003
                return NULL;
2004

    
2005
        b = (YY_BUFFER_STATE) cf_alloc(sizeof( struct yy_buffer_state )  );
2006
        if ( ! b )
2007
                YY_FATAL_ERROR( "out of dynamic memory in cf__scan_buffer()" );
2008

    
2009
        b->yy_buf_size = size - 2;        /* "- 2" to take care of EOB's */
2010
        b->yy_buf_pos = b->yy_ch_buf = base;
2011
        b->yy_is_our_buffer = 0;
2012
        b->yy_input_file = NULL;
2013
        b->yy_n_chars = b->yy_buf_size;
2014
        b->yy_is_interactive = 0;
2015
        b->yy_at_bol = 1;
2016
        b->yy_fill_buffer = 0;
2017
        b->yy_buffer_status = YY_BUFFER_NEW;
2018

    
2019
        cf__switch_to_buffer(b  );
2020

    
2021
        return b;
2022
}
2023

    
2024
/** Setup the input buffer state to scan a string. The next call to cf_lex() will
2025
 * scan from a @e copy of @a str.
2026
 * @param yystr a NUL-terminated string to scan
2027
 * 
2028
 * @return the newly allocated buffer state object.
2029
 * @note If you want to scan bytes that may contain NUL values, then use
2030
 *       cf__scan_bytes() instead.
2031
 */
2032
YY_BUFFER_STATE cf__scan_string (yyconst char * yystr )
2033
{
2034
    
2035
        return cf__scan_bytes(yystr,(int) strlen(yystr) );
2036
}
2037

    
2038
/** Setup the input buffer state to scan the given bytes. The next call to cf_lex() will
2039
 * scan from a @e copy of @a bytes.
2040
 * @param yybytes the byte buffer to scan
2041
 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2042
 * 
2043
 * @return the newly allocated buffer state object.
2044
 */
2045
YY_BUFFER_STATE cf__scan_bytes  (yyconst char * yybytes, int  _yybytes_len )
2046
{
2047
        YY_BUFFER_STATE b;
2048
        char *buf;
2049
        yy_size_t n;
2050
        int i;
2051
    
2052
        /* Get memory for full buffer, including space for trailing EOB's. */
2053
        n = (yy_size_t) (_yybytes_len + 2);
2054
        buf = (char *) cf_alloc(n  );
2055
        if ( ! buf )
2056
                YY_FATAL_ERROR( "out of dynamic memory in cf__scan_bytes()" );
2057

    
2058
        for ( i = 0; i < _yybytes_len; ++i )
2059
                buf[i] = yybytes[i];
2060

    
2061
        buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2062

    
2063
        b = cf__scan_buffer(buf,n );
2064
        if ( ! b )
2065
                YY_FATAL_ERROR( "bad buffer in cf__scan_bytes()" );
2066

    
2067
        /* It's okay to grow etc. this buffer, and we should throw it
2068
         * away when we're done.
2069
         */
2070
        b->yy_is_our_buffer = 1;
2071

    
2072
        return b;
2073
}
2074

    
2075
#ifndef YY_EXIT_FAILURE
2076
#define YY_EXIT_FAILURE 2
2077
#endif
2078

    
2079
static void yynoreturn yy_fatal_error (yyconst char* msg )
2080
{
2081
                        (void) fprintf( stderr, "%s\n", msg );
2082
        exit( YY_EXIT_FAILURE );
2083
}
2084

    
2085
/* Redefine yyless() so it works in section 3 code. */
2086

    
2087
#undef yyless
2088
#define yyless(n) \
2089
        do \
2090
                { \
2091
                /* Undo effects of setting up cf_text. */ \
2092
        int yyless_macro_arg = (n); \
2093
        YY_LESS_LINENO(yyless_macro_arg);\
2094
                cf_text[cf_leng] = (yy_hold_char); \
2095
                (yy_c_buf_p) = cf_text + yyless_macro_arg; \
2096
                (yy_hold_char) = *(yy_c_buf_p); \
2097
                *(yy_c_buf_p) = '\0'; \
2098
                cf_leng = yyless_macro_arg; \
2099
                } \
2100
        while ( 0 )
2101

    
2102
/* Accessor  methods (get/set functions) to struct members. */
2103

    
2104
/** Get the current line number.
2105
 * 
2106
 */
2107
int cf_get_lineno  (void)
2108
{
2109
    
2110
    return cf_lineno;
2111
}
2112

    
2113
/** Get the input stream.
2114
 * 
2115
 */
2116
FILE *cf_get_in  (void)
2117
{
2118
        return cf_in;
2119
}
2120

    
2121
/** Get the output stream.
2122
 * 
2123
 */
2124
FILE *cf_get_out  (void)
2125
{
2126
        return cf_out;
2127
}
2128

    
2129
/** Get the length of the current token.
2130
 * 
2131
 */
2132
int cf_get_leng  (void)
2133
{
2134
        return cf_leng;
2135
}
2136

    
2137
/** Get the current token.
2138
 * 
2139
 */
2140

    
2141
char *cf_get_text  (void)
2142
{
2143
        return cf_text;
2144
}
2145

    
2146
/** Set the current line number.
2147
 * @param _line_number line number
2148
 * 
2149
 */
2150
void cf_set_lineno (int  _line_number )
2151
{
2152
    
2153
    cf_lineno = _line_number;
2154
}
2155

    
2156
/** Set the input stream. This does not discard the current
2157
 * input buffer.
2158
 * @param _in_str A readable stream.
2159
 * 
2160
 * @see cf__switch_to_buffer
2161
 */
2162
void cf_set_in (FILE *  _in_str )
2163
{
2164
        cf_in = _in_str ;
2165
}
2166

    
2167
void cf_set_out (FILE *  _out_str )
2168
{
2169
        cf_out = _out_str ;
2170
}
2171

    
2172
int cf_get_debug  (void)
2173
{
2174
        return cf__flex_debug;
2175
}
2176

    
2177
void cf_set_debug (int  _bdebug )
2178
{
2179
        cf__flex_debug = _bdebug ;
2180
}
2181

    
2182
static int yy_init_globals (void)
2183
{
2184
        /* Initialization is the same as for the non-reentrant scanner.
2185
     * This function is called from cf_lex_destroy(), so don't allocate here.
2186
     */
2187

    
2188
    (yy_buffer_stack) = NULL;
2189
    (yy_buffer_stack_top) = 0;
2190
    (yy_buffer_stack_max) = 0;
2191
    (yy_c_buf_p) = NULL;
2192
    (yy_init) = 0;
2193
    (yy_start) = 0;
2194

    
2195
/* Defined in main.c */
2196
#ifdef YY_STDINIT
2197
    cf_in = stdin;
2198
    cf_out = stdout;
2199
#else
2200
    cf_in = NULL;
2201
    cf_out = NULL;
2202
#endif
2203

    
2204
    /* For future reference: Set errno on error, since we are called by
2205
     * cf_lex_init()
2206
     */
2207
    return 0;
2208
}
2209

    
2210
/* cf_lex_destroy is for both reentrant and non-reentrant scanners. */
2211
int cf_lex_destroy  (void)
2212
{
2213
    
2214
    /* Pop the buffer stack, destroying each element. */
2215
        while(YY_CURRENT_BUFFER){
2216
                cf__delete_buffer(YY_CURRENT_BUFFER  );
2217
                YY_CURRENT_BUFFER_LVALUE = NULL;
2218
                cf_pop_buffer_state();
2219
        }
2220

    
2221
        /* Destroy the stack itself. */
2222
        cf_free((yy_buffer_stack) );
2223
        (yy_buffer_stack) = NULL;
2224

    
2225
    /* Reset the globals. This is important in a non-reentrant scanner so the next time
2226
     * cf_lex() is called, initialization will occur. */
2227
    yy_init_globals( );
2228

    
2229
    return 0;
2230
}
2231

    
2232
/*
2233
 * Internal utility routines.
2234
 */
2235

    
2236
#ifndef yytext_ptr
2237
static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
2238
{
2239
                
2240
        int i;
2241
        for ( i = 0; i < n; ++i )
2242
                s1[i] = s2[i];
2243
}
2244
#endif
2245

    
2246
#ifdef YY_NEED_STRLEN
2247
static int yy_flex_strlen (yyconst char * s )
2248
{
2249
        int n;
2250
        for ( n = 0; s[n]; ++n )
2251
                ;
2252

    
2253
        return n;
2254
}
2255
#endif
2256

    
2257
void *cf_alloc (yy_size_t  size )
2258
{
2259
                        return malloc(size);
2260
}
2261

    
2262
void *cf_realloc  (void * ptr, yy_size_t  size )
2263
{
2264
                
2265
        /* The cast to (char *) in the following accommodates both
2266
         * implementations that use char* generic pointers, and those
2267
         * that use void* generic pointers.  It works with the latter
2268
         * because both ANSI C and C++ allow castless assignment from
2269
         * any pointer type to void*, and deal with argument conversions
2270
         * as though doing an assignment.
2271
         */
2272
        return realloc(ptr, size);
2273
}
2274

    
2275
void cf_free (void * ptr )
2276
{
2277
                        free( (char *) ptr );        /* see cf_realloc() for (char *) cast */
2278
}
2279

    
2280
#define YYTABLES_NAME "yytables"
2281

    
2282
#line 347 "conf/cf-lex.l"
2283

    
2284

    
2285

    
2286
static uint
2287
cf_hash(byte *c)
2288
{
2289
  uint h = 13 << 24;
2290

    
2291
  while (*c)
2292
    h = h + (h >> 2) + (h >> 5) + ((uint) *c++ << 24);
2293
  return h;
2294
}
2295

    
2296

    
2297
/*
2298
 * IFS stack - it contains structures needed for recursive processing
2299
 * of include in config files. On the top of the stack is a structure
2300
 * for currently processed file. Other structures are either for
2301
 * active files interrupted because of include directive (these have
2302
 * fd and flex buffer) or for inactive files scheduled to be processed
2303
 * later (when parent requested including of several files by wildcard
2304
 * match - these do not have fd and flex buffer yet).
2305
 *
2306
 * FIXME: Most of these ifs and include functions are really sysdep/unix.
2307
 */
2308

    
2309
static struct include_file_stack *
2310
push_ifs(struct include_file_stack *old)
2311
{
2312
  struct include_file_stack *ret;
2313
  ret = cfg_allocz(sizeof(struct include_file_stack));
2314
  ret->lino = 1;
2315
  ret->prev = old;
2316
  return ret;
2317
}
2318

    
2319
static struct include_file_stack *
2320
pop_ifs(struct include_file_stack *old)
2321
{
2322
 cf__delete_buffer(old->buffer);
2323
 close(old->fd);
2324
 return old->prev;
2325
}
2326

    
2327
static void
2328
enter_ifs(struct include_file_stack *new)
2329
{
2330
  if (!new->buffer)
2331
    {
2332
      new->fd = open(new->file_name, O_RDONLY);
2333
      if (new->fd < 0)
2334
        {
2335
          ifs = ifs->up;
2336
          cf_error("Unable to open included file %s: %m", new->file_name);
2337
        }
2338

    
2339
      new->buffer = cf__create_buffer(NULL,YY_BUF_SIZE);
2340
    }
2341

    
2342
  cf__switch_to_buffer(new->buffer);
2343
}
2344

    
2345
/**
2346
 * cf_lex_unwind - unwind lexer state during error
2347
 *
2348
 * cf_lex_unwind() frees the internal state on IFS stack when the lexical
2349
 * analyzer is terminated by cf_error().
2350
 */
2351
void
2352
cf_lex_unwind(void)
2353
{
2354
  struct include_file_stack *n;
2355

    
2356
  for (n = ifs; n != ifs_head; n = n->prev)
2357
    {
2358
      /* Memory is freed automatically */
2359
      if (n->buffer)
2360
        cf__delete_buffer(n->buffer);
2361
      if (n->fd)
2362
        close(n->fd);
2363
    }
2364

    
2365
  ifs = ifs_head;
2366
}
2367

    
2368
static void
2369
cf_include(char *arg, int alen)
2370
{
2371
  struct include_file_stack *base_ifs = ifs;
2372
  int new_depth, rv, i;
2373
  char *patt;
2374
  glob_t g = {};
2375

    
2376
  new_depth = ifs->depth + 1;
2377
  if (new_depth > MAX_INCLUDE_DEPTH)
2378
    cf_error("Max include depth reached");
2379

    
2380
  /* expand arg to properly handle relative filenames */
2381
  if (*arg != '/')
2382
    {
2383
      int dlen = strlen(ifs->file_name);
2384
      char *dir = alloca(dlen + 1);
2385
      patt = alloca(dlen + alen + 2);
2386
      memcpy(dir, ifs->file_name, dlen + 1);
2387
      sprintf(patt, "%s/%s", dirname(dir), arg);
2388
    }
2389
  else
2390
    patt = arg;
2391

    
2392
  /* Skip globbing if there are no wildcards, mainly to get proper
2393
     response when the included config file is missing */
2394
  if (!strpbrk(arg, "?*["))
2395
    {
2396
      ifs = push_ifs(ifs);
2397
      ifs->file_name = cfg_strdup(patt);
2398
      ifs->depth = new_depth;
2399
      ifs->up = base_ifs;
2400
      enter_ifs(ifs);
2401
      return;
2402
    }
2403

    
2404
  /* Expand the pattern */
2405
  rv = glob(patt, GLOB_ERR | GLOB_NOESCAPE, NULL, &g);
2406
  if (rv == GLOB_ABORTED)
2407
    cf_error("Unable to match pattern %s: %m", patt);
2408
  if ((rv != 0) || (g.gl_pathc <= 0))
2409
    return;
2410

    
2411
  /*
2412
   * Now we put all found files to ifs stack in reverse order, they
2413
   * will be activated and processed in order as ifs stack is popped
2414
   * by pop_ifs() and enter_ifs() in check_eof().
2415
   */
2416
  for(i = g.gl_pathc - 1; i >= 0; i--)
2417
    {
2418
      char *fname = g.gl_pathv[i];
2419
      struct stat fs;
2420

    
2421
      if (stat(fname, &fs) < 0)
2422
        {
2423
          globfree(&g);
2424
          cf_error("Unable to stat included file %s: %m", fname);
2425
        }
2426

    
2427
      if (fs.st_mode & S_IFDIR)
2428
        continue;
2429

    
2430
      /* Prepare new stack item */
2431
      ifs = push_ifs(ifs);
2432
      ifs->file_name = cfg_strdup(fname);
2433
      ifs->depth = new_depth;
2434
      ifs->up = base_ifs;
2435
    }
2436

    
2437
  globfree(&g);
2438
  enter_ifs(ifs);
2439
}
2440

    
2441
static int
2442
check_eof(void)
2443
{
2444
  if (ifs == ifs_head)
2445
    {
2446
      /* EOF in main config file */
2447
      ifs->lino = 1; /* Why this? */
2448
      return 1;
2449
    }
2450

    
2451
  ifs = pop_ifs(ifs);
2452
  enter_ifs(ifs);
2453
  return 0;
2454
}
2455

    
2456
static struct symbol *
2457
cf_new_symbol(byte *c)
2458
{
2459
  struct symbol *s;
2460

    
2461
  uint l = strlen(c);
2462
  if (l > SYM_MAX_LEN)
2463
    cf_error("Symbol too long");
2464

    
2465
  s = cfg_alloc(sizeof(struct symbol) + l);
2466
  s->scope = conf_this_scope;
2467
  s->class = SYM_VOID;
2468
  s->def = NULL;
2469
  s->aux = 0;
2470
  strcpy(s->name, c);
2471

    
2472
  if (!new_config->sym_hash.data)
2473
    HASH_INIT(new_config->sym_hash, new_config->pool, SYM_ORDER);
2474

    
2475
  HASH_INSERT2(new_config->sym_hash, SYM, new_config->pool, s);
2476

    
2477
  return s;
2478
}
2479

    
2480
/**
2481
 * cf_find_symbol - find a symbol by name
2482
 * @cfg: specificed config
2483
 * @c: symbol name
2484
 *
2485
 * This functions searches the symbol table in the config @cfg for a symbol of
2486
 * given name. First it examines the current scope, then the second recent one
2487
 * and so on until it either finds the symbol and returns a pointer to its
2488
 * &symbol structure or reaches the end of the scope chain and returns %NULL to
2489
 * signify no match.
2490
 */
2491
struct symbol *
2492
cf_find_symbol(struct config *cfg, byte *c)
2493
{
2494
  struct symbol *s;
2495

    
2496
  if (cfg->sym_hash.data &&
2497
      (s = HASH_FIND(cfg->sym_hash, SYM, c, 1)))
2498
    return s;
2499

    
2500
  if (cfg->fallback &&
2501
      cfg->fallback->sym_hash.data &&
2502
      (s = HASH_FIND(cfg->fallback->sym_hash, SYM, c, 1)))
2503
    return s;
2504

    
2505
  return NULL;
2506
}
2507

    
2508
/**
2509
 * cf_get_symbol - get a symbol by name
2510
 * @c: symbol name
2511
 *
2512
 * This functions searches the symbol table of the currently parsed config
2513
 * (@new_config) for a symbol of given name. It returns either the already
2514
 * existing symbol or a newly allocated undefined (%SYM_VOID) symbol if no
2515
 * existing symbol is found.
2516
 */
2517
struct symbol *
2518
cf_get_symbol(byte *c)
2519
{
2520
  return cf_find_symbol(new_config, c) ?: cf_new_symbol(c);
2521
}
2522

    
2523
struct symbol *
2524
cf_default_name(char *template, int *counter)
2525
{
2526
  char buf[SYM_MAX_LEN];
2527
  struct symbol *s;
2528
  char *perc = strchr(template, '%');
2529

    
2530
  for(;;)
2531
    {
2532
      bsprintf(buf, template, ++(*counter));
2533
      s = cf_get_symbol(buf);
2534
      if (s->class == SYM_VOID)
2535
        return s;
2536
      if (!perc)
2537
        break;
2538
    }
2539
  cf_error("Unable to generate default name");
2540
}
2541

    
2542
/**
2543
 * cf_define_symbol - define meaning of a symbol
2544
 * @sym: symbol to be defined
2545
 * @type: symbol class to assign
2546
 * @def: class dependent data
2547
 *
2548
 * Defines new meaning of a symbol. If the symbol is an undefined
2549
 * one (%SYM_VOID), it's just re-defined to the new type. If it's defined
2550
 * in different scope, a new symbol in current scope is created and the
2551
 * meaning is assigned to it. If it's already defined in the current scope,
2552
 * an error is reported via cf_error().
2553
 *
2554
 * Result: Pointer to the newly defined symbol. If we are in the top-level
2555
 * scope, it's the same @sym as passed to the function.
2556
 */
2557
struct symbol *
2558
cf_define_symbol(struct symbol *sym, int type, void *def)
2559
{
2560
  if (sym->class)
2561
    {
2562
      if (sym->scope == conf_this_scope)
2563
        cf_error("Symbol already defined");
2564
      sym = cf_new_symbol(sym->name);
2565
    }
2566
  sym->class = type;
2567
  sym->def = def;
2568
  return sym;
2569
}
2570

    
2571
static void
2572
cf_lex_init_kh(void)
2573
{
2574
  HASH_INIT(kw_hash, &root_pool, KW_ORDER);
2575

    
2576
  struct keyword *k;
2577
  for (k=keyword_list; k->name; k++)
2578
    HASH_INSERT(kw_hash, KW, k);
2579
}
2580

    
2581
/**
2582
 * cf_lex_init - initialize the lexer
2583
 * @is_cli: true if we're going to parse CLI command, false for configuration
2584
 * @c: configuration structure
2585
 *
2586
 * cf_lex_init() initializes the lexical analyzer and prepares it for
2587
 * parsing of a new input.
2588
 */
2589
void
2590
cf_lex_init(int is_cli, struct config *c)
2591
{
2592
  if (!kw_hash.data)
2593
    cf_lex_init_kh();
2594

    
2595
  ifs_head = ifs = push_ifs(NULL);
2596
  if (!is_cli)
2597
    {
2598
      ifs->file_name = c->file_name;
2599
      ifs->fd = c->file_fd;
2600
      ifs->depth = 1;
2601
    }
2602

    
2603
  cf_restart(NULL);
2604
  ifs->buffer = YY_CURRENT_BUFFER;
2605

    
2606
  if (is_cli)
2607
    BEGIN(CLI);
2608
  else
2609
    BEGIN(INITIAL);
2610

    
2611
  conf_this_scope = cfg_allocz(sizeof(struct sym_scope));
2612
  conf_this_scope->active = 1;
2613
}
2614

    
2615
/**
2616
 * cf_push_scope - enter new scope
2617
 * @sym: symbol representing scope name
2618
 *
2619
 * If we want to enter a new scope to process declarations inside
2620
 * a nested block, we can just call cf_push_scope() to push a new
2621
 * scope onto the scope stack which will cause all new symbols to be
2622
 * defined in this scope and all existing symbols to be sought for
2623
 * in all scopes stored on the stack.
2624
 */
2625
void
2626
cf_push_scope(struct symbol *sym)
2627
{
2628
  struct sym_scope *s = cfg_alloc(sizeof(struct sym_scope));
2629

    
2630
  s->next = conf_this_scope;
2631
  conf_this_scope = s;
2632
  s->active = 1;
2633
  s->name = sym;
2634
}
2635

    
2636
/**
2637
 * cf_pop_scope - leave a scope
2638
 *
2639
 * cf_pop_scope() pops the topmost scope from the scope stack,
2640
 * leaving all its symbols in the symbol table, but making them
2641
 * invisible to the rest of the config.
2642
 */
2643
void
2644
cf_pop_scope(void)
2645
{
2646
  conf_this_scope->active = 0;
2647
  conf_this_scope = conf_this_scope->next;
2648
  ASSERT(conf_this_scope);
2649
}
2650

    
2651
/**
2652
 * cf_symbol_class_name - get name of a symbol class
2653
 * @sym: symbol
2654
 *
2655
 * This function returns a string representing the class
2656
 * of the given symbol.
2657
 */
2658
char *
2659
cf_symbol_class_name(struct symbol *sym)
2660
{
2661
  if (cf_symbol_is_constant(sym))
2662
    return "constant";
2663

    
2664
  switch (sym->class)
2665
    {
2666
    case SYM_VOID:
2667
      return "undefined";
2668
    case SYM_PROTO:
2669
      return "protocol";
2670
    case SYM_TEMPLATE:
2671
      return "protocol template";
2672
    case SYM_FUNCTION:
2673
      return "function";
2674
    case SYM_FILTER:
2675
      return "filter";
2676
    case SYM_TABLE:
2677
      return "routing table";
2678
    default:
2679
      return "unknown type";
2680
    }
2681
}
2682

    
2683

    
2684
/**
2685
 * DOC: Parser
2686
 *
2687
 * Both the configuration and CLI commands are analyzed using a syntax
2688
 * driven parser generated by the |bison| tool from a grammar which
2689
 * is constructed from information gathered from grammar snippets by
2690
 * the |gen_parser.m4| script.
2691
 *
2692
 * Grammar snippets are files (usually with extension |.Y|) contributed
2693
 * by various BIRD modules in order to provide information about syntax of their
2694
 * configuration and their CLI commands. Each snipped consists of several
2695
 * sections, each of them starting with a special keyword: |CF_HDR| for
2696
 * a list of |#include| directives needed by the C code, |CF_DEFINES|
2697
 * for a list of C declarations, |CF_DECLS| for |bison| declarations
2698
 * including keyword definitions specified as |CF_KEYWORDS|, |CF_GRAMMAR|
2699
 * for the grammar rules, |CF_CODE| for auxiliary C code and finally
2700
 * |CF_END| at the end of the snippet.
2701
 *
2702
 * To create references between the snippets, it's possible to define
2703
 * multi-part rules by utilizing the |CF_ADDTO| macro which adds a new
2704
 * alternative to a multi-part rule.
2705
 *
2706
 * CLI commands are defined using a |CF_CLI| macro. Its parameters are:
2707
 * the list of keywords determining the command, the list of parameters,
2708
 * help text for the parameters and help text for the command.
2709
 *
2710
 * Values of |enum| filter types can be defined using |CF_ENUM| with
2711
 * the following parameters: name of filter type, prefix common for all
2712
 * literals of this type and names of all the possible values.
2713
 */
2714