1*76404edcSAsim Jamshed /* Driver template for the LEMON parser generator.
2*76404edcSAsim Jamshed ** The author disclaims copyright to this source code.
3*76404edcSAsim Jamshed */
4*76404edcSAsim Jamshed /* First off, code is include which follows the "include" declaration
5*76404edcSAsim Jamshed ** in the input file. */
6*76404edcSAsim Jamshed #include <stdio.h>
7*76404edcSAsim Jamshed #line 5 "./configparser.y"
8*76404edcSAsim Jamshed 
9*76404edcSAsim Jamshed #include "configfile.h"
10*76404edcSAsim Jamshed #include "buffer.h"
11*76404edcSAsim Jamshed #include "array.h"
12*76404edcSAsim Jamshed 
13*76404edcSAsim Jamshed #include <assert.h>
14*76404edcSAsim Jamshed #include <stdio.h>
15*76404edcSAsim Jamshed #include <string.h>
16*76404edcSAsim Jamshed 
configparser_push(config_t * ctx,data_config * dc,int isnew)17*76404edcSAsim Jamshed static void configparser_push(config_t *ctx, data_config *dc, int isnew) {
18*76404edcSAsim Jamshed   if (isnew) {
19*76404edcSAsim Jamshed     dc->context_ndx = ctx->all_configs->used;
20*76404edcSAsim Jamshed     assert(dc->context_ndx > ctx->current->context_ndx);
21*76404edcSAsim Jamshed     array_insert_unique(ctx->all_configs, (data_unset *)dc);
22*76404edcSAsim Jamshed     dc->parent = ctx->current;
23*76404edcSAsim Jamshed     array_insert_unique(dc->parent->childs, (data_unset *)dc);
24*76404edcSAsim Jamshed   }
25*76404edcSAsim Jamshed   if (ctx->configs_stack->used > 0 && ctx->current->context_ndx == 0) {
26*76404edcSAsim Jamshed     fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");
27*76404edcSAsim Jamshed     exit(-1);
28*76404edcSAsim Jamshed   }
29*76404edcSAsim Jamshed   array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current);
30*76404edcSAsim Jamshed   ctx->current = dc;
31*76404edcSAsim Jamshed }
32*76404edcSAsim Jamshed 
configparser_pop(config_t * ctx)33*76404edcSAsim Jamshed static data_config *configparser_pop(config_t *ctx) {
34*76404edcSAsim Jamshed   data_config *old = ctx->current;
35*76404edcSAsim Jamshed   ctx->current = (data_config *) array_pop(ctx->configs_stack);
36*76404edcSAsim Jamshed   return old;
37*76404edcSAsim Jamshed }
38*76404edcSAsim Jamshed 
39*76404edcSAsim Jamshed /* return a copied variable */
configparser_get_variable(config_t * ctx,const buffer * key)40*76404edcSAsim Jamshed static data_unset *configparser_get_variable(config_t *ctx, const buffer *key) {
41*76404edcSAsim Jamshed   data_unset *du;
42*76404edcSAsim Jamshed   data_config *dc;
43*76404edcSAsim Jamshed 
44*76404edcSAsim Jamshed #if 0
45*76404edcSAsim Jamshed   fprintf(stderr, "get var %s\n", key->ptr);
46*76404edcSAsim Jamshed #endif
47*76404edcSAsim Jamshed   for (dc = ctx->current; dc; dc = dc->parent) {
48*76404edcSAsim Jamshed #if 0
49*76404edcSAsim Jamshed     fprintf(stderr, "get var on block: %s\n", dc->key->ptr);
50*76404edcSAsim Jamshed     array_print(dc->value, 0);
51*76404edcSAsim Jamshed #endif
52*76404edcSAsim Jamshed     if (NULL != (du = array_get_element(dc->value, key->ptr))) {
53*76404edcSAsim Jamshed       return du->copy(du);
54*76404edcSAsim Jamshed     }
55*76404edcSAsim Jamshed   }
56*76404edcSAsim Jamshed   return NULL;
57*76404edcSAsim Jamshed }
58*76404edcSAsim Jamshed 
59*76404edcSAsim Jamshed /* op1 is to be eat/return by this function if success, op1->key is not cared
60*76404edcSAsim Jamshed    op2 is left untouch, unreferenced
61*76404edcSAsim Jamshed  */
configparser_merge_data(data_unset * op1,const data_unset * op2)62*76404edcSAsim Jamshed data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
63*76404edcSAsim Jamshed   /* type mismatch */
64*76404edcSAsim Jamshed   if (op1->type != op2->type) {
65*76404edcSAsim Jamshed     if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {
66*76404edcSAsim Jamshed       data_string *ds = (data_string *)op1;
67*76404edcSAsim Jamshed       buffer_append_long(ds->value, ((data_integer*)op2)->value);
68*76404edcSAsim Jamshed       return op1;
69*76404edcSAsim Jamshed     } else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
70*76404edcSAsim Jamshed       data_string *ds = data_string_init();
71*76404edcSAsim Jamshed       buffer_append_long(ds->value, ((data_integer*)op1)->value);
72*76404edcSAsim Jamshed       buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);
73*76404edcSAsim Jamshed       op1->free(op1);
74*76404edcSAsim Jamshed       return (data_unset *)ds;
75*76404edcSAsim Jamshed     } else {
76*76404edcSAsim Jamshed       fprintf(stderr, "data type mismatch, cannot merge\n");
77*76404edcSAsim Jamshed       return NULL;
78*76404edcSAsim Jamshed     }
79*76404edcSAsim Jamshed   }
80*76404edcSAsim Jamshed 
81*76404edcSAsim Jamshed   switch (op1->type) {
82*76404edcSAsim Jamshed     case TYPE_STRING:
83*76404edcSAsim Jamshed       buffer_append_string_buffer(((data_string *)op1)->value, ((data_string *)op2)->value);
84*76404edcSAsim Jamshed       break;
85*76404edcSAsim Jamshed     case TYPE_INTEGER:
86*76404edcSAsim Jamshed       ((data_integer *)op1)->value += ((data_integer *)op2)->value;
87*76404edcSAsim Jamshed       break;
88*76404edcSAsim Jamshed     case TYPE_ARRAY: {
89*76404edcSAsim Jamshed       array *dst = ((data_array *)op1)->value;
90*76404edcSAsim Jamshed       array *src = ((data_array *)op2)->value;
91*76404edcSAsim Jamshed       data_unset *du;
92*76404edcSAsim Jamshed       size_t i;
93*76404edcSAsim Jamshed 
94*76404edcSAsim Jamshed       for (i = 0; i < src->used; i ++) {
95*76404edcSAsim Jamshed         du = (data_unset *)src->data[i];
96*76404edcSAsim Jamshed         if (du) {
97*76404edcSAsim Jamshed           array_insert_unique(dst, du->copy(du));
98*76404edcSAsim Jamshed         }
99*76404edcSAsim Jamshed       }
100*76404edcSAsim Jamshed       break;
101*76404edcSAsim Jamshed     default:
102*76404edcSAsim Jamshed       assert(0);
103*76404edcSAsim Jamshed       break;
104*76404edcSAsim Jamshed     }
105*76404edcSAsim Jamshed   }
106*76404edcSAsim Jamshed   return op1;
107*76404edcSAsim Jamshed }
108*76404edcSAsim Jamshed 
109*76404edcSAsim Jamshed 
110*76404edcSAsim Jamshed #line 111 "configparser.c"
111*76404edcSAsim Jamshed /* Next is all token values, in a form suitable for use by makeheaders.
112*76404edcSAsim Jamshed ** This section will be null unless lemon is run with the -m switch.
113*76404edcSAsim Jamshed */
114*76404edcSAsim Jamshed /*
115*76404edcSAsim Jamshed ** These constants (all generated automatically by the parser generator)
116*76404edcSAsim Jamshed ** specify the various kinds of tokens (terminals) that the parser
117*76404edcSAsim Jamshed ** understands.
118*76404edcSAsim Jamshed **
119*76404edcSAsim Jamshed ** Each symbol here is a terminal symbol in the grammar.
120*76404edcSAsim Jamshed */
121*76404edcSAsim Jamshed /* Make sure the INTERFACE macro is defined.
122*76404edcSAsim Jamshed */
123*76404edcSAsim Jamshed #ifndef INTERFACE
124*76404edcSAsim Jamshed # define INTERFACE 1
125*76404edcSAsim Jamshed #endif
126*76404edcSAsim Jamshed /* The next thing included is series of defines which control
127*76404edcSAsim Jamshed ** various aspects of the generated parser.
128*76404edcSAsim Jamshed **    YYCODETYPE         is the data type used for storing terminal
129*76404edcSAsim Jamshed **                       and nonterminal numbers.  "unsigned char" is
130*76404edcSAsim Jamshed **                       used if there are fewer than 250 terminals
131*76404edcSAsim Jamshed **                       and nonterminals.  "int" is used otherwise.
132*76404edcSAsim Jamshed **    YYNOCODE           is a number of type YYCODETYPE which corresponds
133*76404edcSAsim Jamshed **                       to no legal terminal or nonterminal number.  This
134*76404edcSAsim Jamshed **                       number is used to fill in empty slots of the hash
135*76404edcSAsim Jamshed **                       table.
136*76404edcSAsim Jamshed **    YYFALLBACK         If defined, this indicates that one or more tokens
137*76404edcSAsim Jamshed **                       have fall-back values which should be used if the
138*76404edcSAsim Jamshed **                       original value of the token will not parse.
139*76404edcSAsim Jamshed **    YYACTIONTYPE       is the data type used for storing terminal
140*76404edcSAsim Jamshed **                       and nonterminal numbers.  "unsigned char" is
141*76404edcSAsim Jamshed **                       used if there are fewer than 250 rules and
142*76404edcSAsim Jamshed **                       states combined.  "int" is used otherwise.
143*76404edcSAsim Jamshed **    configparserTOKENTYPE     is the data type used for minor tokens given
144*76404edcSAsim Jamshed **                       directly to the parser from the tokenizer.
145*76404edcSAsim Jamshed **    YYMINORTYPE        is the data type used for all minor tokens.
146*76404edcSAsim Jamshed **                       This is typically a union of many types, one of
147*76404edcSAsim Jamshed **                       which is configparserTOKENTYPE.  The entry in the union
148*76404edcSAsim Jamshed **                       for base tokens is called "yy0".
149*76404edcSAsim Jamshed **    YYSTACKDEPTH       is the maximum depth of the parser's stack.
150*76404edcSAsim Jamshed **    configparserARG_SDECL     A static variable declaration for the %extra_argument
151*76404edcSAsim Jamshed **    configparserARG_PDECL     A parameter declaration for the %extra_argument
152*76404edcSAsim Jamshed **    configparserARG_STORE     Code to store %extra_argument into yypParser
153*76404edcSAsim Jamshed **    configparserARG_FETCH     Code to extract %extra_argument from yypParser
154*76404edcSAsim Jamshed **    YYNSTATE           the combined number of states.
155*76404edcSAsim Jamshed **    YYNRULE            the number of rules in the grammar
156*76404edcSAsim Jamshed **    YYERRORSYMBOL      is the code number of the error symbol.  If not
157*76404edcSAsim Jamshed **                       defined, then do no error processing.
158*76404edcSAsim Jamshed */
159*76404edcSAsim Jamshed /*  */
160*76404edcSAsim Jamshed #define YYCODETYPE unsigned char
161*76404edcSAsim Jamshed #define YYNOCODE 48
162*76404edcSAsim Jamshed #define YYACTIONTYPE unsigned char
163*76404edcSAsim Jamshed #define configparserTOKENTYPE buffer *
164*76404edcSAsim Jamshed typedef union {
165*76404edcSAsim Jamshed   configparserTOKENTYPE yy0;
166*76404edcSAsim Jamshed   config_cond_t yy27;
167*76404edcSAsim Jamshed   array * yy40;
168*76404edcSAsim Jamshed   data_unset * yy41;
169*76404edcSAsim Jamshed   buffer * yy43;
170*76404edcSAsim Jamshed   data_config * yy78;
171*76404edcSAsim Jamshed   int yy95;
172*76404edcSAsim Jamshed } YYMINORTYPE;
173*76404edcSAsim Jamshed #define YYSTACKDEPTH 100
174*76404edcSAsim Jamshed #define configparserARG_SDECL config_t *ctx;
175*76404edcSAsim Jamshed #define configparserARG_PDECL ,config_t *ctx
176*76404edcSAsim Jamshed #define configparserARG_FETCH config_t *ctx = yypParser->ctx
177*76404edcSAsim Jamshed #define configparserARG_STORE yypParser->ctx = ctx
178*76404edcSAsim Jamshed #define YYNSTATE 63
179*76404edcSAsim Jamshed #define YYNRULE 40
180*76404edcSAsim Jamshed #define YYERRORSYMBOL 26
181*76404edcSAsim Jamshed #define YYERRSYMDT yy95
182*76404edcSAsim Jamshed #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
183*76404edcSAsim Jamshed #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
184*76404edcSAsim Jamshed #define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
185*76404edcSAsim Jamshed 
186*76404edcSAsim Jamshed /* Next are that tables used to determine what action to take based on the
187*76404edcSAsim Jamshed ** current state and lookahead token.  These tables are used to implement
188*76404edcSAsim Jamshed ** functions that take a state number and lookahead value and return an
189*76404edcSAsim Jamshed ** action integer.
190*76404edcSAsim Jamshed **
191*76404edcSAsim Jamshed ** Suppose the action integer is N.  Then the action is determined as
192*76404edcSAsim Jamshed ** follows
193*76404edcSAsim Jamshed **
194*76404edcSAsim Jamshed **   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
195*76404edcSAsim Jamshed **                                      token onto the stack and goto state N.
196*76404edcSAsim Jamshed **
197*76404edcSAsim Jamshed **   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
198*76404edcSAsim Jamshed **
199*76404edcSAsim Jamshed **   N == YYNSTATE+YYNRULE              A syntax error has occurred.
200*76404edcSAsim Jamshed **
201*76404edcSAsim Jamshed **   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
202*76404edcSAsim Jamshed **
203*76404edcSAsim Jamshed **   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
204*76404edcSAsim Jamshed **                                      slots in the yy_action[] table.
205*76404edcSAsim Jamshed **
206*76404edcSAsim Jamshed ** The action table is constructed as a single large table named yy_action[].
207*76404edcSAsim Jamshed ** Given state S and lookahead X, the action is computed as
208*76404edcSAsim Jamshed **
209*76404edcSAsim Jamshed **      yy_action[ yy_shift_ofst[S] + X ]
210*76404edcSAsim Jamshed **
211*76404edcSAsim Jamshed ** If the index value yy_shift_ofst[S]+X is out of range or if the value
212*76404edcSAsim Jamshed ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
213*76404edcSAsim Jamshed ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
214*76404edcSAsim Jamshed ** and that yy_default[S] should be used instead.
215*76404edcSAsim Jamshed **
216*76404edcSAsim Jamshed ** The formula above is for computing the action when the lookahead is
217*76404edcSAsim Jamshed ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
218*76404edcSAsim Jamshed ** a reduce action) then the yy_reduce_ofst[] array is used in place of
219*76404edcSAsim Jamshed ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
220*76404edcSAsim Jamshed ** YY_SHIFT_USE_DFLT.
221*76404edcSAsim Jamshed **
222*76404edcSAsim Jamshed ** The following are the tables generated in this section:
223*76404edcSAsim Jamshed **
224*76404edcSAsim Jamshed **  yy_action[]        A single table containing all actions.
225*76404edcSAsim Jamshed **  yy_lookahead[]     A table containing the lookahead for each entry in
226*76404edcSAsim Jamshed **                     yy_action.  Used to detect hash collisions.
227*76404edcSAsim Jamshed **  yy_shift_ofst[]    For each state, the offset into yy_action for
228*76404edcSAsim Jamshed **                     shifting terminals.
229*76404edcSAsim Jamshed **  yy_reduce_ofst[]   For each state, the offset into yy_action for
230*76404edcSAsim Jamshed **                     shifting non-terminals after a reduce.
231*76404edcSAsim Jamshed **  yy_default[]       Default action for each state.
232*76404edcSAsim Jamshed */
233*76404edcSAsim Jamshed static YYACTIONTYPE yy_action[] = {
234*76404edcSAsim Jamshed  /*     0 */     2,    3,    4,    5,   13,   14,   63,   15,    7,   45,
235*76404edcSAsim Jamshed  /*    10 */    20,   88,   16,   46,   28,   49,   41,   10,   40,   25,
236*76404edcSAsim Jamshed  /*    20 */    22,   50,   46,    8,   15,  104,    1,   20,   28,   18,
237*76404edcSAsim Jamshed  /*    30 */    58,   60,    6,   25,   22,   40,   47,   62,   11,   46,
238*76404edcSAsim Jamshed  /*    40 */    20,    9,   23,   24,   26,   29,   89,   58,   60,   10,
239*76404edcSAsim Jamshed  /*    50 */    17,   38,   28,   27,   37,   19,   30,   25,   22,   34,
240*76404edcSAsim Jamshed  /*    60 */    15,  100,   20,   20,   23,   24,   26,   12,   19,   31,
241*76404edcSAsim Jamshed  /*    70 */    32,   40,   19,   44,   43,   46,   95,   35,   90,   89,
242*76404edcSAsim Jamshed  /*    80 */    28,   49,   42,   58,   60,   25,   22,   59,   28,   27,
243*76404edcSAsim Jamshed  /*    90 */    33,   48,   52,   25,   22,   34,   28,   49,   51,   28,
244*76404edcSAsim Jamshed  /*   100 */    36,   25,   22,   61,   25,   22,   89,   28,   39,   89,
245*76404edcSAsim Jamshed  /*   110 */    89,   89,   25,   22,   54,   55,   56,   57,   89,   28,
246*76404edcSAsim Jamshed  /*   120 */    53,   21,   89,   89,   25,   22,   25,   22,
247*76404edcSAsim Jamshed };
248*76404edcSAsim Jamshed static YYCODETYPE yy_lookahead[] = {
249*76404edcSAsim Jamshed  /*     0 */    29,   30,   31,   32,   33,   34,    0,    1,   44,   38,
250*76404edcSAsim Jamshed  /*    10 */     4,   15,   41,   16,   35,   36,   45,   46,   12,   40,
251*76404edcSAsim Jamshed  /*    20 */    41,   42,   16,   15,    1,   27,   28,    4,   35,   36,
252*76404edcSAsim Jamshed  /*    30 */    24,   25,    1,   40,   41,   12,   17,   14,   13,   16,
253*76404edcSAsim Jamshed  /*    40 */     4,   38,    6,    7,    8,    9,   15,   24,   25,   46,
254*76404edcSAsim Jamshed  /*    50 */     2,    3,   35,   36,   37,    5,   39,   40,   41,   42,
255*76404edcSAsim Jamshed  /*    60 */     1,   11,    4,    4,    6,    7,    8,   28,    5,    9,
256*76404edcSAsim Jamshed  /*    70 */    10,   12,    5,   14,   28,   16,   13,   11,   13,   47,
257*76404edcSAsim Jamshed  /*    80 */    35,   36,   13,   24,   25,   40,   41,   42,   35,   36,
258*76404edcSAsim Jamshed  /*    90 */    37,   18,   43,   40,   41,   42,   35,   36,   19,   35,
259*76404edcSAsim Jamshed  /*   100 */    36,   40,   41,   42,   40,   41,   47,   35,   36,   47,
260*76404edcSAsim Jamshed  /*   110 */    47,   47,   40,   41,   20,   21,   22,   23,   47,   35,
261*76404edcSAsim Jamshed  /*   120 */    36,   35,   47,   47,   40,   41,   40,   41,
262*76404edcSAsim Jamshed };
263*76404edcSAsim Jamshed #define YY_SHIFT_USE_DFLT (-5)
264*76404edcSAsim Jamshed static signed char yy_shift_ofst[] = {
265*76404edcSAsim Jamshed  /*     0 */    -5,    6,   -5,   -5,   -5,   31,   -4,    8,   -3,   -5,
266*76404edcSAsim Jamshed  /*    10 */    25,   -5,   23,   -5,   -5,   -5,   48,   58,   67,   58,
267*76404edcSAsim Jamshed  /*    20 */    -5,   -5,   -5,   -5,   -5,   -5,   36,   50,   -5,   -5,
268*76404edcSAsim Jamshed  /*    30 */    60,   -5,   58,   -5,   66,   58,   67,   -5,   58,   67,
269*76404edcSAsim Jamshed  /*    40 */    65,   69,   -5,   59,   -5,   -5,   19,   73,   58,   67,
270*76404edcSAsim Jamshed  /*    50 */    79,   94,   58,   63,   -5,   -5,   -5,   -5,   58,   -5,
271*76404edcSAsim Jamshed  /*    60 */    58,   -5,   -5,
272*76404edcSAsim Jamshed };
273*76404edcSAsim Jamshed #define YY_REDUCE_USE_DFLT (-37)
274*76404edcSAsim Jamshed static signed char yy_reduce_ofst[] = {
275*76404edcSAsim Jamshed  /*     0 */    -2,  -29,  -37,  -37,  -37,  -36,  -37,  -37,    3,  -37,
276*76404edcSAsim Jamshed  /*    10 */   -37,   39,  -29,  -37,  -37,  -37,  -37,   -7,  -37,   86,
277*76404edcSAsim Jamshed  /*    20 */   -37,  -37,  -37,  -37,  -37,  -37,   17,  -37,  -37,  -37,
278*76404edcSAsim Jamshed  /*    30 */   -37,  -37,   53,  -37,  -37,   64,  -37,  -37,   72,  -37,
279*76404edcSAsim Jamshed  /*    40 */   -37,  -37,   46,  -29,  -37,  -37,  -37,  -37,  -21,  -37,
280*76404edcSAsim Jamshed  /*    50 */   -37,   49,   84,  -37,  -37,  -37,  -37,  -37,   45,  -37,
281*76404edcSAsim Jamshed  /*    60 */    61,  -37,  -37,
282*76404edcSAsim Jamshed };
283*76404edcSAsim Jamshed static YYACTIONTYPE yy_default[] = {
284*76404edcSAsim Jamshed  /*     0 */    65,  103,   64,   66,   67,  103,   68,  103,  103,   92,
285*76404edcSAsim Jamshed  /*    10 */   103,   65,  103,   69,   70,   71,  103,  103,   72,  103,
286*76404edcSAsim Jamshed  /*    20 */    74,   75,   77,   78,   79,   80,  103,   86,   76,   81,
287*76404edcSAsim Jamshed  /*    30 */   103,   82,   84,   83,  103,  103,   87,   85,  103,   73,
288*76404edcSAsim Jamshed  /*    40 */   103,  103,   65,  103,   91,   93,  103,  103,  103,  100,
289*76404edcSAsim Jamshed  /*    50 */   103,  103,  103,  103,   96,   97,   98,   99,  103,  101,
290*76404edcSAsim Jamshed  /*    60 */   103,  102,   94,
291*76404edcSAsim Jamshed };
292*76404edcSAsim Jamshed #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))
293*76404edcSAsim Jamshed 
294*76404edcSAsim Jamshed /* The next table maps tokens into fallback tokens.  If a construct
295*76404edcSAsim Jamshed ** like the following:
296*76404edcSAsim Jamshed **
297*76404edcSAsim Jamshed **      %fallback ID X Y Z.
298*76404edcSAsim Jamshed **
299*76404edcSAsim Jamshed ** appears in the grammer, then ID becomes a fallback token for X, Y,
300*76404edcSAsim Jamshed ** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
301*76404edcSAsim Jamshed ** but it does not parse, the type of the token is changed to ID and
302*76404edcSAsim Jamshed ** the parse is retried before an error is thrown.
303*76404edcSAsim Jamshed */
304*76404edcSAsim Jamshed #ifdef YYFALLBACK
305*76404edcSAsim Jamshed static const YYCODETYPE yyFallback[] = {
306*76404edcSAsim Jamshed };
307*76404edcSAsim Jamshed #endif /* YYFALLBACK */
308*76404edcSAsim Jamshed 
309*76404edcSAsim Jamshed /* The following structure represents a single element of the
310*76404edcSAsim Jamshed ** parser's stack.  Information stored includes:
311*76404edcSAsim Jamshed **
312*76404edcSAsim Jamshed **   +  The state number for the parser at this level of the stack.
313*76404edcSAsim Jamshed **
314*76404edcSAsim Jamshed **   +  The value of the token stored at this level of the stack.
315*76404edcSAsim Jamshed **      (In other words, the "major" token.)
316*76404edcSAsim Jamshed **
317*76404edcSAsim Jamshed **   +  The semantic value stored at this level of the stack.  This is
318*76404edcSAsim Jamshed **      the information used by the action routines in the grammar.
319*76404edcSAsim Jamshed **      It is sometimes called the "minor" token.
320*76404edcSAsim Jamshed */
321*76404edcSAsim Jamshed struct yyStackEntry {
322*76404edcSAsim Jamshed   int stateno;       /* The state-number */
323*76404edcSAsim Jamshed   int major;         /* The major token value.  This is the code
324*76404edcSAsim Jamshed                      ** number for the token at this stack level */
325*76404edcSAsim Jamshed   YYMINORTYPE minor; /* The user-supplied minor token value.  This
326*76404edcSAsim Jamshed                      ** is the value of the token  */
327*76404edcSAsim Jamshed };
328*76404edcSAsim Jamshed typedef struct yyStackEntry yyStackEntry;
329*76404edcSAsim Jamshed 
330*76404edcSAsim Jamshed /* The state of the parser is completely contained in an instance of
331*76404edcSAsim Jamshed ** the following structure */
332*76404edcSAsim Jamshed struct yyParser {
333*76404edcSAsim Jamshed   int yyidx;                    /* Index of top element in stack */
334*76404edcSAsim Jamshed   int yyerrcnt;                 /* Shifts left before out of the error */
335*76404edcSAsim Jamshed   configparserARG_SDECL                /* A place to hold %extra_argument */
336*76404edcSAsim Jamshed   yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
337*76404edcSAsim Jamshed };
338*76404edcSAsim Jamshed typedef struct yyParser yyParser;
339*76404edcSAsim Jamshed 
340*76404edcSAsim Jamshed #ifndef NDEBUG
341*76404edcSAsim Jamshed #include <stdio.h>
342*76404edcSAsim Jamshed static FILE *yyTraceFILE = NULL;
343*76404edcSAsim Jamshed static char *yyTracePrompt = NULL;
344*76404edcSAsim Jamshed #endif /* NDEBUG */
345*76404edcSAsim Jamshed 
346*76404edcSAsim Jamshed #ifndef NDEBUG
347*76404edcSAsim Jamshed /*
348*76404edcSAsim Jamshed ** Turn parser tracing on by giving a stream to which to write the trace
349*76404edcSAsim Jamshed ** and a prompt to preface each trace message.  Tracing is turned off
350*76404edcSAsim Jamshed ** by making either argument NULL
351*76404edcSAsim Jamshed **
352*76404edcSAsim Jamshed ** Inputs:
353*76404edcSAsim Jamshed ** <ul>
354*76404edcSAsim Jamshed ** <li> A FILE* to which trace output should be written.
355*76404edcSAsim Jamshed **      If NULL, then tracing is turned off.
356*76404edcSAsim Jamshed ** <li> A prefix string written at the beginning of every
357*76404edcSAsim Jamshed **      line of trace output.  If NULL, then tracing is
358*76404edcSAsim Jamshed **      turned off.
359*76404edcSAsim Jamshed ** </ul>
360*76404edcSAsim Jamshed **
361*76404edcSAsim Jamshed ** Outputs:
362*76404edcSAsim Jamshed ** None.
363*76404edcSAsim Jamshed */
364*76404edcSAsim Jamshed #if 0
365*76404edcSAsim Jamshed void configparserTrace(FILE *TraceFILE, char *zTracePrompt){
366*76404edcSAsim Jamshed   yyTraceFILE = TraceFILE;
367*76404edcSAsim Jamshed   yyTracePrompt = zTracePrompt;
368*76404edcSAsim Jamshed   if( yyTraceFILE==0 ) yyTracePrompt = 0;
369*76404edcSAsim Jamshed   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
370*76404edcSAsim Jamshed }
371*76404edcSAsim Jamshed #endif
372*76404edcSAsim Jamshed #endif /* NDEBUG */
373*76404edcSAsim Jamshed 
374*76404edcSAsim Jamshed #ifndef NDEBUG
375*76404edcSAsim Jamshed /* For tracing shifts, the names of all terminals and nonterminals
376*76404edcSAsim Jamshed ** are required.  The following table supplies these names */
377*76404edcSAsim Jamshed static const char *yyTokenName[] = {
378*76404edcSAsim Jamshed   "$",             "EOL",           "ASSIGN",        "APPEND",
379*76404edcSAsim Jamshed   "LKEY",          "PLUS",          "STRING",        "INTEGER",
380*76404edcSAsim Jamshed   "LPARAN",        "RPARAN",        "COMMA",         "ARRAY_ASSIGN",
381*76404edcSAsim Jamshed   "GLOBAL",        "LCURLY",        "RCURLY",        "ELSE",
382*76404edcSAsim Jamshed   "DOLLAR",        "SRVVARNAME",    "LBRACKET",      "RBRACKET",
383*76404edcSAsim Jamshed   "EQ",            "MATCH",         "NE",            "NOMATCH",
384*76404edcSAsim Jamshed   "INCLUDE",       "INCLUDE_SHELL",  "error",         "input",
385*76404edcSAsim Jamshed   "metalines",     "metaline",      "varline",       "global",
386*76404edcSAsim Jamshed   "condlines",     "include",       "include_shell",  "value",
387*76404edcSAsim Jamshed   "expression",    "aelement",      "condline",      "aelements",
388*76404edcSAsim Jamshed   "array",         "key",           "stringop",      "cond",
389*76404edcSAsim Jamshed   "eols",          "globalstart",   "context",
390*76404edcSAsim Jamshed };
391*76404edcSAsim Jamshed #endif /* NDEBUG */
392*76404edcSAsim Jamshed 
393*76404edcSAsim Jamshed #ifndef NDEBUG
394*76404edcSAsim Jamshed /* For tracing reduce actions, the names of all rules are required.
395*76404edcSAsim Jamshed */
396*76404edcSAsim Jamshed static const char *yyRuleName[] = {
397*76404edcSAsim Jamshed  /*   0 */ "input ::= metalines",
398*76404edcSAsim Jamshed  /*   1 */ "metalines ::= metalines metaline",
399*76404edcSAsim Jamshed  /*   2 */ "metalines ::=",
400*76404edcSAsim Jamshed  /*   3 */ "metaline ::= varline",
401*76404edcSAsim Jamshed  /*   4 */ "metaline ::= global",
402*76404edcSAsim Jamshed  /*   5 */ "metaline ::= condlines EOL",
403*76404edcSAsim Jamshed  /*   6 */ "metaline ::= include",
404*76404edcSAsim Jamshed  /*   7 */ "metaline ::= include_shell",
405*76404edcSAsim Jamshed  /*   8 */ "metaline ::= EOL",
406*76404edcSAsim Jamshed  /*   9 */ "varline ::= key ASSIGN expression",
407*76404edcSAsim Jamshed  /*  10 */ "varline ::= key APPEND expression",
408*76404edcSAsim Jamshed  /*  11 */ "key ::= LKEY",
409*76404edcSAsim Jamshed  /*  12 */ "expression ::= expression PLUS value",
410*76404edcSAsim Jamshed  /*  13 */ "expression ::= value",
411*76404edcSAsim Jamshed  /*  14 */ "value ::= key",
412*76404edcSAsim Jamshed  /*  15 */ "value ::= STRING",
413*76404edcSAsim Jamshed  /*  16 */ "value ::= INTEGER",
414*76404edcSAsim Jamshed  /*  17 */ "value ::= array",
415*76404edcSAsim Jamshed  /*  18 */ "array ::= LPARAN RPARAN",
416*76404edcSAsim Jamshed  /*  19 */ "array ::= LPARAN aelements RPARAN",
417*76404edcSAsim Jamshed  /*  20 */ "aelements ::= aelements COMMA aelement",
418*76404edcSAsim Jamshed  /*  21 */ "aelements ::= aelements COMMA",
419*76404edcSAsim Jamshed  /*  22 */ "aelements ::= aelement",
420*76404edcSAsim Jamshed  /*  23 */ "aelement ::= expression",
421*76404edcSAsim Jamshed  /*  24 */ "aelement ::= stringop ARRAY_ASSIGN expression",
422*76404edcSAsim Jamshed  /*  25 */ "eols ::= EOL",
423*76404edcSAsim Jamshed  /*  26 */ "eols ::=",
424*76404edcSAsim Jamshed  /*  27 */ "globalstart ::= GLOBAL",
425*76404edcSAsim Jamshed  /*  28 */ "global ::= globalstart LCURLY metalines RCURLY",
426*76404edcSAsim Jamshed  /*  29 */ "condlines ::= condlines eols ELSE condline",
427*76404edcSAsim Jamshed  /*  30 */ "condlines ::= condline",
428*76404edcSAsim Jamshed  /*  31 */ "condline ::= context LCURLY metalines RCURLY",
429*76404edcSAsim Jamshed  /*  32 */ "context ::= DOLLAR SRVVARNAME LBRACKET stringop RBRACKET cond expression",
430*76404edcSAsim Jamshed  /*  33 */ "cond ::= EQ",
431*76404edcSAsim Jamshed  /*  34 */ "cond ::= MATCH",
432*76404edcSAsim Jamshed  /*  35 */ "cond ::= NE",
433*76404edcSAsim Jamshed  /*  36 */ "cond ::= NOMATCH",
434*76404edcSAsim Jamshed  /*  37 */ "stringop ::= expression",
435*76404edcSAsim Jamshed  /*  38 */ "include ::= INCLUDE stringop",
436*76404edcSAsim Jamshed  /*  39 */ "include_shell ::= INCLUDE_SHELL stringop",
437*76404edcSAsim Jamshed };
438*76404edcSAsim Jamshed #endif /* NDEBUG */
439*76404edcSAsim Jamshed 
440*76404edcSAsim Jamshed /*
441*76404edcSAsim Jamshed ** This function returns the symbolic name associated with a token
442*76404edcSAsim Jamshed ** value.
443*76404edcSAsim Jamshed */
444*76404edcSAsim Jamshed #if 0
445*76404edcSAsim Jamshed const char *configparserTokenName(int tokenType){
446*76404edcSAsim Jamshed #ifndef NDEBUG
447*76404edcSAsim Jamshed   if( tokenType>0 && (size_t)tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
448*76404edcSAsim Jamshed     return yyTokenName[tokenType];
449*76404edcSAsim Jamshed   }else{
450*76404edcSAsim Jamshed     return "Unknown";
451*76404edcSAsim Jamshed   }
452*76404edcSAsim Jamshed #else
453*76404edcSAsim Jamshed   return "";
454*76404edcSAsim Jamshed #endif
455*76404edcSAsim Jamshed }
456*76404edcSAsim Jamshed #endif
457*76404edcSAsim Jamshed 
458*76404edcSAsim Jamshed /*
459*76404edcSAsim Jamshed ** This function allocates a new parser.
460*76404edcSAsim Jamshed ** The only argument is a pointer to a function which works like
461*76404edcSAsim Jamshed ** malloc.
462*76404edcSAsim Jamshed **
463*76404edcSAsim Jamshed ** Inputs:
464*76404edcSAsim Jamshed ** A pointer to the function used to allocate memory.
465*76404edcSAsim Jamshed **
466*76404edcSAsim Jamshed ** Outputs:
467*76404edcSAsim Jamshed ** A pointer to a parser.  This pointer is used in subsequent calls
468*76404edcSAsim Jamshed ** to configparser and configparserFree.
469*76404edcSAsim Jamshed */
configparserAlloc(void * (* mallocProc)(size_t))470*76404edcSAsim Jamshed void *configparserAlloc(void *(*mallocProc)(size_t)){
471*76404edcSAsim Jamshed   yyParser *pParser;
472*76404edcSAsim Jamshed   pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
473*76404edcSAsim Jamshed   if( pParser ){
474*76404edcSAsim Jamshed     pParser->yyidx = -1;
475*76404edcSAsim Jamshed   }
476*76404edcSAsim Jamshed   return pParser;
477*76404edcSAsim Jamshed }
478*76404edcSAsim Jamshed 
479*76404edcSAsim Jamshed /* The following function deletes the value associated with a
480*76404edcSAsim Jamshed ** symbol.  The symbol can be either a terminal or nonterminal.
481*76404edcSAsim Jamshed ** "yymajor" is the symbol code, and "yypminor" is a pointer to
482*76404edcSAsim Jamshed ** the value.
483*76404edcSAsim Jamshed */
yy_destructor(YYCODETYPE yymajor,YYMINORTYPE * yypminor)484*76404edcSAsim Jamshed static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
485*76404edcSAsim Jamshed   switch( yymajor ){
486*76404edcSAsim Jamshed     /* Here is inserted the actions which take place when a
487*76404edcSAsim Jamshed     ** terminal or non-terminal is destroyed.  This can happen
488*76404edcSAsim Jamshed     ** when the symbol is popped from the stack during a
489*76404edcSAsim Jamshed     ** reduce or during error processing or when a parser is
490*76404edcSAsim Jamshed     ** being destroyed before it is finished parsing.
491*76404edcSAsim Jamshed     **
492*76404edcSAsim Jamshed     ** Note: during a reduce, the only symbols destroyed are those
493*76404edcSAsim Jamshed     ** which appear on the RHS of the rule, but which are not used
494*76404edcSAsim Jamshed     ** inside the C code.
495*76404edcSAsim Jamshed     */
496*76404edcSAsim Jamshed     case 1:
497*76404edcSAsim Jamshed     case 2:
498*76404edcSAsim Jamshed     case 3:
499*76404edcSAsim Jamshed     case 4:
500*76404edcSAsim Jamshed     case 5:
501*76404edcSAsim Jamshed     case 6:
502*76404edcSAsim Jamshed     case 7:
503*76404edcSAsim Jamshed     case 8:
504*76404edcSAsim Jamshed     case 9:
505*76404edcSAsim Jamshed     case 10:
506*76404edcSAsim Jamshed     case 11:
507*76404edcSAsim Jamshed     case 12:
508*76404edcSAsim Jamshed     case 13:
509*76404edcSAsim Jamshed     case 14:
510*76404edcSAsim Jamshed     case 15:
511*76404edcSAsim Jamshed     case 16:
512*76404edcSAsim Jamshed     case 17:
513*76404edcSAsim Jamshed     case 18:
514*76404edcSAsim Jamshed     case 19:
515*76404edcSAsim Jamshed     case 20:
516*76404edcSAsim Jamshed     case 21:
517*76404edcSAsim Jamshed     case 22:
518*76404edcSAsim Jamshed     case 23:
519*76404edcSAsim Jamshed     case 24:
520*76404edcSAsim Jamshed     case 25:
521*76404edcSAsim Jamshed #line 144 "./configparser.y"
522*76404edcSAsim Jamshed { buffer_free((yypminor->yy0)); }
523*76404edcSAsim Jamshed #line 523 "configparser.c"
524*76404edcSAsim Jamshed       break;
525*76404edcSAsim Jamshed     case 35:
526*76404edcSAsim Jamshed #line 135 "./configparser.y"
527*76404edcSAsim Jamshed { (yypminor->yy41)->free((yypminor->yy41)); }
528*76404edcSAsim Jamshed #line 528 "configparser.c"
529*76404edcSAsim Jamshed       break;
530*76404edcSAsim Jamshed     case 36:
531*76404edcSAsim Jamshed #line 136 "./configparser.y"
532*76404edcSAsim Jamshed { (yypminor->yy41)->free((yypminor->yy41)); }
533*76404edcSAsim Jamshed #line 533 "configparser.c"
534*76404edcSAsim Jamshed       break;
535*76404edcSAsim Jamshed     case 37:
536*76404edcSAsim Jamshed #line 137 "./configparser.y"
537*76404edcSAsim Jamshed { (yypminor->yy41)->free((yypminor->yy41)); }
538*76404edcSAsim Jamshed #line 538 "configparser.c"
539*76404edcSAsim Jamshed       break;
540*76404edcSAsim Jamshed     case 39:
541*76404edcSAsim Jamshed #line 138 "./configparser.y"
542*76404edcSAsim Jamshed { array_free((yypminor->yy40)); }
543*76404edcSAsim Jamshed #line 543 "configparser.c"
544*76404edcSAsim Jamshed       break;
545*76404edcSAsim Jamshed     case 40:
546*76404edcSAsim Jamshed #line 139 "./configparser.y"
547*76404edcSAsim Jamshed { array_free((yypminor->yy40)); }
548*76404edcSAsim Jamshed #line 548 "configparser.c"
549*76404edcSAsim Jamshed       break;
550*76404edcSAsim Jamshed     case 41:
551*76404edcSAsim Jamshed #line 140 "./configparser.y"
552*76404edcSAsim Jamshed { buffer_free((yypminor->yy43)); }
553*76404edcSAsim Jamshed #line 553 "configparser.c"
554*76404edcSAsim Jamshed       break;
555*76404edcSAsim Jamshed     case 42:
556*76404edcSAsim Jamshed #line 141 "./configparser.y"
557*76404edcSAsim Jamshed { buffer_free((yypminor->yy43)); }
558*76404edcSAsim Jamshed #line 558 "configparser.c"
559*76404edcSAsim Jamshed       break;
560*76404edcSAsim Jamshed     default:  break;   /* If no destructor action specified: do nothing */
561*76404edcSAsim Jamshed   }
562*76404edcSAsim Jamshed }
563*76404edcSAsim Jamshed 
564*76404edcSAsim Jamshed /*
565*76404edcSAsim Jamshed ** Pop the parser's stack once.
566*76404edcSAsim Jamshed **
567*76404edcSAsim Jamshed ** If there is a destructor routine associated with the token which
568*76404edcSAsim Jamshed ** is popped from the stack, then call it.
569*76404edcSAsim Jamshed **
570*76404edcSAsim Jamshed ** Return the major token number for the symbol popped.
571*76404edcSAsim Jamshed */
yy_pop_parser_stack(yyParser * pParser)572*76404edcSAsim Jamshed static int yy_pop_parser_stack(yyParser *pParser){
573*76404edcSAsim Jamshed   YYCODETYPE yymajor;
574*76404edcSAsim Jamshed   yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
575*76404edcSAsim Jamshed 
576*76404edcSAsim Jamshed   if( pParser->yyidx<0 ) return 0;
577*76404edcSAsim Jamshed #ifndef NDEBUG
578*76404edcSAsim Jamshed   if( yyTraceFILE && pParser->yyidx>=0 ){
579*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"%sPopping %s\n",
580*76404edcSAsim Jamshed       yyTracePrompt,
581*76404edcSAsim Jamshed       yyTokenName[yytos->major]);
582*76404edcSAsim Jamshed   }
583*76404edcSAsim Jamshed #endif
584*76404edcSAsim Jamshed   yymajor = yytos->major;
585*76404edcSAsim Jamshed   yy_destructor( yymajor, &yytos->minor);
586*76404edcSAsim Jamshed   pParser->yyidx--;
587*76404edcSAsim Jamshed   return yymajor;
588*76404edcSAsim Jamshed }
589*76404edcSAsim Jamshed 
590*76404edcSAsim Jamshed /*
591*76404edcSAsim Jamshed ** Deallocate and destroy a parser.  Destructors are all called for
592*76404edcSAsim Jamshed ** all stack elements before shutting the parser down.
593*76404edcSAsim Jamshed **
594*76404edcSAsim Jamshed ** Inputs:
595*76404edcSAsim Jamshed ** <ul>
596*76404edcSAsim Jamshed ** <li>  A pointer to the parser.  This should be a pointer
597*76404edcSAsim Jamshed **       obtained from configparserAlloc.
598*76404edcSAsim Jamshed ** <li>  A pointer to a function used to reclaim memory obtained
599*76404edcSAsim Jamshed **       from malloc.
600*76404edcSAsim Jamshed ** </ul>
601*76404edcSAsim Jamshed */
configparserFree(void * p,void (* freeProc)(void *))602*76404edcSAsim Jamshed void configparserFree(
603*76404edcSAsim Jamshed   void *p,                    /* The parser to be deleted */
604*76404edcSAsim Jamshed   void (*freeProc)(void*)     /* Function used to reclaim memory */
605*76404edcSAsim Jamshed ){
606*76404edcSAsim Jamshed   yyParser *pParser = (yyParser*)p;
607*76404edcSAsim Jamshed   if( pParser==NULL ) return;
608*76404edcSAsim Jamshed   while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
609*76404edcSAsim Jamshed   (*freeProc)((void*)pParser);
610*76404edcSAsim Jamshed }
611*76404edcSAsim Jamshed 
612*76404edcSAsim Jamshed /*
613*76404edcSAsim Jamshed ** Find the appropriate action for a parser given the terminal
614*76404edcSAsim Jamshed ** look-ahead token iLookAhead.
615*76404edcSAsim Jamshed **
616*76404edcSAsim Jamshed ** If the look-ahead token is YYNOCODE, then check to see if the action is
617*76404edcSAsim Jamshed ** independent of the look-ahead.  If it is, return the action, otherwise
618*76404edcSAsim Jamshed ** return YY_NO_ACTION.
619*76404edcSAsim Jamshed */
yy_find_shift_action(yyParser * pParser,int iLookAhead)620*76404edcSAsim Jamshed static int yy_find_shift_action(
621*76404edcSAsim Jamshed   yyParser *pParser,        /* The parser */
622*76404edcSAsim Jamshed   int iLookAhead            /* The look-ahead token */
623*76404edcSAsim Jamshed ){
624*76404edcSAsim Jamshed   int i;
625*76404edcSAsim Jamshed   int stateno = pParser->yystack[pParser->yyidx].stateno;
626*76404edcSAsim Jamshed 
627*76404edcSAsim Jamshed   /* if( pParser->yyidx<0 ) return YY_NO_ACTION;  */
628*76404edcSAsim Jamshed   i = yy_shift_ofst[stateno];
629*76404edcSAsim Jamshed   if( i==YY_SHIFT_USE_DFLT ){
630*76404edcSAsim Jamshed     return yy_default[stateno];
631*76404edcSAsim Jamshed   }
632*76404edcSAsim Jamshed   if( iLookAhead==YYNOCODE ){
633*76404edcSAsim Jamshed     return YY_NO_ACTION;
634*76404edcSAsim Jamshed   }
635*76404edcSAsim Jamshed   i += iLookAhead;
636*76404edcSAsim Jamshed   if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
637*76404edcSAsim Jamshed #ifdef YYFALLBACK
638*76404edcSAsim Jamshed     int iFallback;            /* Fallback token */
639*76404edcSAsim Jamshed     if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
640*76404edcSAsim Jamshed            && (iFallback = yyFallback[iLookAhead])!=0 ){
641*76404edcSAsim Jamshed #ifndef NDEBUG
642*76404edcSAsim Jamshed       if( yyTraceFILE ){
643*76404edcSAsim Jamshed         fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
644*76404edcSAsim Jamshed            yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
645*76404edcSAsim Jamshed       }
646*76404edcSAsim Jamshed #endif
647*76404edcSAsim Jamshed       return yy_find_shift_action(pParser, iFallback);
648*76404edcSAsim Jamshed     }
649*76404edcSAsim Jamshed #endif
650*76404edcSAsim Jamshed     return yy_default[stateno];
651*76404edcSAsim Jamshed   }else{
652*76404edcSAsim Jamshed     return yy_action[i];
653*76404edcSAsim Jamshed   }
654*76404edcSAsim Jamshed }
655*76404edcSAsim Jamshed 
656*76404edcSAsim Jamshed /*
657*76404edcSAsim Jamshed ** Find the appropriate action for a parser given the non-terminal
658*76404edcSAsim Jamshed ** look-ahead token iLookAhead.
659*76404edcSAsim Jamshed **
660*76404edcSAsim Jamshed ** If the look-ahead token is YYNOCODE, then check to see if the action is
661*76404edcSAsim Jamshed ** independent of the look-ahead.  If it is, return the action, otherwise
662*76404edcSAsim Jamshed ** return YY_NO_ACTION.
663*76404edcSAsim Jamshed */
yy_find_reduce_action(yyParser * pParser,int iLookAhead)664*76404edcSAsim Jamshed static int yy_find_reduce_action(
665*76404edcSAsim Jamshed   yyParser *pParser,        /* The parser */
666*76404edcSAsim Jamshed   int iLookAhead            /* The look-ahead token */
667*76404edcSAsim Jamshed ){
668*76404edcSAsim Jamshed   int i;
669*76404edcSAsim Jamshed   int stateno = pParser->yystack[pParser->yyidx].stateno;
670*76404edcSAsim Jamshed 
671*76404edcSAsim Jamshed   i = yy_reduce_ofst[stateno];
672*76404edcSAsim Jamshed   if( i==YY_REDUCE_USE_DFLT ){
673*76404edcSAsim Jamshed     return yy_default[stateno];
674*76404edcSAsim Jamshed   }
675*76404edcSAsim Jamshed   if( iLookAhead==YYNOCODE ){
676*76404edcSAsim Jamshed     return YY_NO_ACTION;
677*76404edcSAsim Jamshed   }
678*76404edcSAsim Jamshed   i += iLookAhead;
679*76404edcSAsim Jamshed   if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
680*76404edcSAsim Jamshed     return yy_default[stateno];
681*76404edcSAsim Jamshed   }else{
682*76404edcSAsim Jamshed     return yy_action[i];
683*76404edcSAsim Jamshed   }
684*76404edcSAsim Jamshed }
685*76404edcSAsim Jamshed 
686*76404edcSAsim Jamshed /*
687*76404edcSAsim Jamshed ** Perform a shift action.
688*76404edcSAsim Jamshed */
yy_shift(yyParser * yypParser,int yyNewState,int yyMajor,YYMINORTYPE * yypMinor)689*76404edcSAsim Jamshed static void yy_shift(
690*76404edcSAsim Jamshed   yyParser *yypParser,          /* The parser to be shifted */
691*76404edcSAsim Jamshed   int yyNewState,               /* The new state to shift in */
692*76404edcSAsim Jamshed   int yyMajor,                  /* The major token to shift in */
693*76404edcSAsim Jamshed   YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
694*76404edcSAsim Jamshed ){
695*76404edcSAsim Jamshed   yyStackEntry *yytos;
696*76404edcSAsim Jamshed   yypParser->yyidx++;
697*76404edcSAsim Jamshed   if( yypParser->yyidx>=YYSTACKDEPTH ){
698*76404edcSAsim Jamshed      configparserARG_FETCH;
699*76404edcSAsim Jamshed      yypParser->yyidx--;
700*76404edcSAsim Jamshed #ifndef NDEBUG
701*76404edcSAsim Jamshed      if( yyTraceFILE ){
702*76404edcSAsim Jamshed        fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
703*76404edcSAsim Jamshed      }
704*76404edcSAsim Jamshed #endif
705*76404edcSAsim Jamshed      while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
706*76404edcSAsim Jamshed      /* Here code is inserted which will execute if the parser
707*76404edcSAsim Jamshed      ** stack every overflows */
708*76404edcSAsim Jamshed      configparserARG_STORE; /* Suppress warning about unused %extra_argument var */
709*76404edcSAsim Jamshed      return;
710*76404edcSAsim Jamshed   }
711*76404edcSAsim Jamshed   yytos = &yypParser->yystack[yypParser->yyidx];
712*76404edcSAsim Jamshed   yytos->stateno = yyNewState;
713*76404edcSAsim Jamshed   yytos->major = yyMajor;
714*76404edcSAsim Jamshed   yytos->minor = *yypMinor;
715*76404edcSAsim Jamshed #ifndef NDEBUG
716*76404edcSAsim Jamshed   if( yyTraceFILE && yypParser->yyidx>0 ){
717*76404edcSAsim Jamshed     int i;
718*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
719*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
720*76404edcSAsim Jamshed     for(i=1; i<=yypParser->yyidx; i++)
721*76404edcSAsim Jamshed       fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
722*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"\n");
723*76404edcSAsim Jamshed   }
724*76404edcSAsim Jamshed #endif
725*76404edcSAsim Jamshed }
726*76404edcSAsim Jamshed 
727*76404edcSAsim Jamshed /* The following table contains information about every rule that
728*76404edcSAsim Jamshed ** is used during the reduce.
729*76404edcSAsim Jamshed */
730*76404edcSAsim Jamshed static struct {
731*76404edcSAsim Jamshed   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
732*76404edcSAsim Jamshed   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
733*76404edcSAsim Jamshed } yyRuleInfo[] = {
734*76404edcSAsim Jamshed   { 27, 1 },
735*76404edcSAsim Jamshed   { 28, 2 },
736*76404edcSAsim Jamshed   { 28, 0 },
737*76404edcSAsim Jamshed   { 29, 1 },
738*76404edcSAsim Jamshed   { 29, 1 },
739*76404edcSAsim Jamshed   { 29, 2 },
740*76404edcSAsim Jamshed   { 29, 1 },
741*76404edcSAsim Jamshed   { 29, 1 },
742*76404edcSAsim Jamshed   { 29, 1 },
743*76404edcSAsim Jamshed   { 30, 3 },
744*76404edcSAsim Jamshed   { 30, 3 },
745*76404edcSAsim Jamshed   { 41, 1 },
746*76404edcSAsim Jamshed   { 36, 3 },
747*76404edcSAsim Jamshed   { 36, 1 },
748*76404edcSAsim Jamshed   { 35, 1 },
749*76404edcSAsim Jamshed   { 35, 1 },
750*76404edcSAsim Jamshed   { 35, 1 },
751*76404edcSAsim Jamshed   { 35, 1 },
752*76404edcSAsim Jamshed   { 40, 2 },
753*76404edcSAsim Jamshed   { 40, 3 },
754*76404edcSAsim Jamshed   { 39, 3 },
755*76404edcSAsim Jamshed   { 39, 2 },
756*76404edcSAsim Jamshed   { 39, 1 },
757*76404edcSAsim Jamshed   { 37, 1 },
758*76404edcSAsim Jamshed   { 37, 3 },
759*76404edcSAsim Jamshed   { 44, 1 },
760*76404edcSAsim Jamshed   { 44, 0 },
761*76404edcSAsim Jamshed   { 45, 1 },
762*76404edcSAsim Jamshed   { 31, 4 },
763*76404edcSAsim Jamshed   { 32, 4 },
764*76404edcSAsim Jamshed   { 32, 1 },
765*76404edcSAsim Jamshed   { 38, 4 },
766*76404edcSAsim Jamshed   { 46, 7 },
767*76404edcSAsim Jamshed   { 43, 1 },
768*76404edcSAsim Jamshed   { 43, 1 },
769*76404edcSAsim Jamshed   { 43, 1 },
770*76404edcSAsim Jamshed   { 43, 1 },
771*76404edcSAsim Jamshed   { 42, 1 },
772*76404edcSAsim Jamshed   { 33, 2 },
773*76404edcSAsim Jamshed   { 34, 2 },
774*76404edcSAsim Jamshed };
775*76404edcSAsim Jamshed 
776*76404edcSAsim Jamshed static void yy_accept(yyParser*);  /* Forward Declaration */
777*76404edcSAsim Jamshed 
778*76404edcSAsim Jamshed /*
779*76404edcSAsim Jamshed ** Perform a reduce action and the shift that must immediately
780*76404edcSAsim Jamshed ** follow the reduce.
781*76404edcSAsim Jamshed */
yy_reduce(yyParser * yypParser,int yyruleno)782*76404edcSAsim Jamshed static void yy_reduce(
783*76404edcSAsim Jamshed   yyParser *yypParser,         /* The parser */
784*76404edcSAsim Jamshed   int yyruleno                 /* Number of the rule by which to reduce */
785*76404edcSAsim Jamshed ){
786*76404edcSAsim Jamshed   int yygoto;                     /* The next state */
787*76404edcSAsim Jamshed   int yyact;                      /* The next action */
788*76404edcSAsim Jamshed   YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
789*76404edcSAsim Jamshed   yyStackEntry *yymsp;            /* The top of the parser's stack */
790*76404edcSAsim Jamshed   int yysize;                     /* Amount to pop the stack */
791*76404edcSAsim Jamshed   configparserARG_FETCH;
792*76404edcSAsim Jamshed   yymsp = &yypParser->yystack[yypParser->yyidx];
793*76404edcSAsim Jamshed #ifndef NDEBUG
794*76404edcSAsim Jamshed   if( yyTraceFILE && yyruleno>=0
795*76404edcSAsim Jamshed         && (size_t)yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
796*76404edcSAsim Jamshed     fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
797*76404edcSAsim Jamshed       yyRuleName[yyruleno]);
798*76404edcSAsim Jamshed   }
799*76404edcSAsim Jamshed #endif /* NDEBUG */
800*76404edcSAsim Jamshed 
801*76404edcSAsim Jamshed   switch( yyruleno ){
802*76404edcSAsim Jamshed   /* Beginning here are the reduction cases.  A typical example
803*76404edcSAsim Jamshed   ** follows:
804*76404edcSAsim Jamshed   **   case 0:
805*76404edcSAsim Jamshed   **  #line <lineno> <grammarfile>
806*76404edcSAsim Jamshed   **     { ... }           // User supplied code
807*76404edcSAsim Jamshed   **  #line <lineno> <thisfile>
808*76404edcSAsim Jamshed   **     break;
809*76404edcSAsim Jamshed   */
810*76404edcSAsim Jamshed       case 0:
811*76404edcSAsim Jamshed         /* No destructor defined for metalines */
812*76404edcSAsim Jamshed         break;
813*76404edcSAsim Jamshed       case 1:
814*76404edcSAsim Jamshed         /* No destructor defined for metalines */
815*76404edcSAsim Jamshed         /* No destructor defined for metaline */
816*76404edcSAsim Jamshed         break;
817*76404edcSAsim Jamshed       case 2:
818*76404edcSAsim Jamshed         break;
819*76404edcSAsim Jamshed       case 3:
820*76404edcSAsim Jamshed         /* No destructor defined for varline */
821*76404edcSAsim Jamshed         break;
822*76404edcSAsim Jamshed       case 4:
823*76404edcSAsim Jamshed         /* No destructor defined for global */
824*76404edcSAsim Jamshed         break;
825*76404edcSAsim Jamshed       case 5:
826*76404edcSAsim Jamshed #line 117 "./configparser.y"
827*76404edcSAsim Jamshed { yymsp[-1].minor.yy78 = NULL; }
828*76404edcSAsim Jamshed #line 828 "configparser.c"
829*76404edcSAsim Jamshed   yy_destructor(1,&yymsp[0].minor);
830*76404edcSAsim Jamshed         break;
831*76404edcSAsim Jamshed       case 6:
832*76404edcSAsim Jamshed         /* No destructor defined for include */
833*76404edcSAsim Jamshed         break;
834*76404edcSAsim Jamshed       case 7:
835*76404edcSAsim Jamshed         /* No destructor defined for include_shell */
836*76404edcSAsim Jamshed         break;
837*76404edcSAsim Jamshed       case 8:
838*76404edcSAsim Jamshed   yy_destructor(1,&yymsp[0].minor);
839*76404edcSAsim Jamshed         break;
840*76404edcSAsim Jamshed       case 9:
841*76404edcSAsim Jamshed #line 146 "./configparser.y"
842*76404edcSAsim Jamshed {
843*76404edcSAsim Jamshed   if (ctx->ok) {
844*76404edcSAsim Jamshed     buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43);
845*76404edcSAsim Jamshed     if (strncmp(yymsp[-2].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) {
846*76404edcSAsim Jamshed       fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",
847*76404edcSAsim Jamshed           ctx->current->context_ndx,
848*76404edcSAsim Jamshed           ctx->current->key->ptr, yymsp[-2].minor.yy43->ptr);
849*76404edcSAsim Jamshed       ctx->ok = 0;
850*76404edcSAsim Jamshed     } else if (NULL == array_get_element(ctx->current->value, yymsp[0].minor.yy41->key->ptr)) {
851*76404edcSAsim Jamshed       array_insert_unique(ctx->current->value, yymsp[0].minor.yy41);
852*76404edcSAsim Jamshed       yymsp[0].minor.yy41 = NULL;
853*76404edcSAsim Jamshed     } else {
854*76404edcSAsim Jamshed       fprintf(stderr, "Duplicate config variable in conditional %d %s: %s\n",
855*76404edcSAsim Jamshed               ctx->current->context_ndx,
856*76404edcSAsim Jamshed               ctx->current->key->ptr, yymsp[0].minor.yy41->key->ptr);
857*76404edcSAsim Jamshed       ctx->ok = 0;
858*76404edcSAsim Jamshed       yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
859*76404edcSAsim Jamshed       yymsp[0].minor.yy41 = NULL;
860*76404edcSAsim Jamshed     }
861*76404edcSAsim Jamshed   }
862*76404edcSAsim Jamshed   buffer_free(yymsp[-2].minor.yy43);
863*76404edcSAsim Jamshed   yymsp[-2].minor.yy43 = NULL;
864*76404edcSAsim Jamshed }
865*76404edcSAsim Jamshed #line 865 "configparser.c"
866*76404edcSAsim Jamshed   yy_destructor(2,&yymsp[-1].minor);
867*76404edcSAsim Jamshed         break;
868*76404edcSAsim Jamshed       case 10:
869*76404edcSAsim Jamshed #line 170 "./configparser.y"
870*76404edcSAsim Jamshed {
871*76404edcSAsim Jamshed   array *vars = ctx->current->value;
872*76404edcSAsim Jamshed   data_unset *du;
873*76404edcSAsim Jamshed 
874*76404edcSAsim Jamshed   if (strncmp(yymsp[-2].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) {
875*76404edcSAsim Jamshed     fprintf(stderr, "Appending env variable is not supported in conditional %d %s: %s\n",
876*76404edcSAsim Jamshed         ctx->current->context_ndx,
877*76404edcSAsim Jamshed         ctx->current->key->ptr, yymsp[-2].minor.yy43->ptr);
878*76404edcSAsim Jamshed     ctx->ok = 0;
879*76404edcSAsim Jamshed   } else if (NULL != (du = array_get_element(vars, yymsp[-2].minor.yy43->ptr))) {
880*76404edcSAsim Jamshed     /* exists in current block */
881*76404edcSAsim Jamshed     du = configparser_merge_data(du, yymsp[0].minor.yy41);
882*76404edcSAsim Jamshed     if (NULL == du) {
883*76404edcSAsim Jamshed       ctx->ok = 0;
884*76404edcSAsim Jamshed     }
885*76404edcSAsim Jamshed     else {
886*76404edcSAsim Jamshed       buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy43);
887*76404edcSAsim Jamshed       array_replace(vars, du);
888*76404edcSAsim Jamshed     }
889*76404edcSAsim Jamshed     yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
890*76404edcSAsim Jamshed   } else if (NULL != (du = configparser_get_variable(ctx, yymsp[-2].minor.yy43))) {
891*76404edcSAsim Jamshed     du = configparser_merge_data(du, yymsp[0].minor.yy41);
892*76404edcSAsim Jamshed     if (NULL == du) {
893*76404edcSAsim Jamshed       ctx->ok = 0;
894*76404edcSAsim Jamshed     }
895*76404edcSAsim Jamshed     else {
896*76404edcSAsim Jamshed       buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy43);
897*76404edcSAsim Jamshed       array_insert_unique(ctx->current->value, du);
898*76404edcSAsim Jamshed     }
899*76404edcSAsim Jamshed     yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
900*76404edcSAsim Jamshed   } else {
901*76404edcSAsim Jamshed     buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43);
902*76404edcSAsim Jamshed     array_insert_unique(ctx->current->value, yymsp[0].minor.yy41);
903*76404edcSAsim Jamshed   }
904*76404edcSAsim Jamshed   buffer_free(yymsp[-2].minor.yy43);
905*76404edcSAsim Jamshed   yymsp[-2].minor.yy43 = NULL;
906*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
907*76404edcSAsim Jamshed }
908*76404edcSAsim Jamshed #line 908 "configparser.c"
909*76404edcSAsim Jamshed   yy_destructor(3,&yymsp[-1].minor);
910*76404edcSAsim Jamshed         break;
911*76404edcSAsim Jamshed       case 11:
912*76404edcSAsim Jamshed #line 209 "./configparser.y"
913*76404edcSAsim Jamshed {
914*76404edcSAsim Jamshed   if (strchr(yymsp[0].minor.yy0->ptr, '.') == NULL) {
915*76404edcSAsim Jamshed     yygotominor.yy43 = buffer_init_string("var.");
916*76404edcSAsim Jamshed     buffer_append_string_buffer(yygotominor.yy43, yymsp[0].minor.yy0);
917*76404edcSAsim Jamshed     buffer_free(yymsp[0].minor.yy0);
918*76404edcSAsim Jamshed     yymsp[0].minor.yy0 = NULL;
919*76404edcSAsim Jamshed   } else {
920*76404edcSAsim Jamshed     yygotominor.yy43 = yymsp[0].minor.yy0;
921*76404edcSAsim Jamshed     yymsp[0].minor.yy0 = NULL;
922*76404edcSAsim Jamshed   }
923*76404edcSAsim Jamshed }
924*76404edcSAsim Jamshed #line 924 "configparser.c"
925*76404edcSAsim Jamshed         break;
926*76404edcSAsim Jamshed       case 12:
927*76404edcSAsim Jamshed #line 221 "./configparser.y"
928*76404edcSAsim Jamshed {
929*76404edcSAsim Jamshed   yygotominor.yy41 = configparser_merge_data(yymsp[-2].minor.yy41, yymsp[0].minor.yy41);
930*76404edcSAsim Jamshed   if (NULL == yygotominor.yy41) {
931*76404edcSAsim Jamshed     ctx->ok = 0;
932*76404edcSAsim Jamshed   }
933*76404edcSAsim Jamshed   yymsp[-2].minor.yy41 = NULL;
934*76404edcSAsim Jamshed   yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
935*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
936*76404edcSAsim Jamshed }
937*76404edcSAsim Jamshed #line 937 "configparser.c"
938*76404edcSAsim Jamshed   yy_destructor(5,&yymsp[-1].minor);
939*76404edcSAsim Jamshed         break;
940*76404edcSAsim Jamshed       case 13:
941*76404edcSAsim Jamshed #line 231 "./configparser.y"
942*76404edcSAsim Jamshed {
943*76404edcSAsim Jamshed   yygotominor.yy41 = yymsp[0].minor.yy41;
944*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
945*76404edcSAsim Jamshed }
946*76404edcSAsim Jamshed #line 946 "configparser.c"
947*76404edcSAsim Jamshed         break;
948*76404edcSAsim Jamshed       case 14:
949*76404edcSAsim Jamshed #line 236 "./configparser.y"
950*76404edcSAsim Jamshed {
951*76404edcSAsim Jamshed   yygotominor.yy41 = NULL;
952*76404edcSAsim Jamshed   if (strncmp(yymsp[0].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) {
953*76404edcSAsim Jamshed     char *env;
954*76404edcSAsim Jamshed 
955*76404edcSAsim Jamshed     if (NULL != (env = getenv(yymsp[0].minor.yy43->ptr + 4))) {
956*76404edcSAsim Jamshed       data_string *ds;
957*76404edcSAsim Jamshed       ds = data_string_init();
958*76404edcSAsim Jamshed       buffer_append_string(ds->value, env);
959*76404edcSAsim Jamshed       yygotominor.yy41 = (data_unset *)ds;
960*76404edcSAsim Jamshed     }
961*76404edcSAsim Jamshed     else {
962*76404edcSAsim Jamshed       fprintf(stderr, "Undefined env variable: %s\n", yymsp[0].minor.yy43->ptr + 4);
963*76404edcSAsim Jamshed       ctx->ok = 0;
964*76404edcSAsim Jamshed     }
965*76404edcSAsim Jamshed   } else if (NULL == (yygotominor.yy41 = configparser_get_variable(ctx, yymsp[0].minor.yy43))) {
966*76404edcSAsim Jamshed     fprintf(stderr, "Undefined config variable: %s\n", yymsp[0].minor.yy43->ptr);
967*76404edcSAsim Jamshed     ctx->ok = 0;
968*76404edcSAsim Jamshed   }
969*76404edcSAsim Jamshed   if (!yygotominor.yy41) {
970*76404edcSAsim Jamshed     /* make a dummy so it won't crash */
971*76404edcSAsim Jamshed     yygotominor.yy41 = (data_unset *)data_string_init();
972*76404edcSAsim Jamshed   }
973*76404edcSAsim Jamshed   buffer_free(yymsp[0].minor.yy43);
974*76404edcSAsim Jamshed   yymsp[0].minor.yy43 = NULL;
975*76404edcSAsim Jamshed }
976*76404edcSAsim Jamshed #line 976 "configparser.c"
977*76404edcSAsim Jamshed         break;
978*76404edcSAsim Jamshed       case 15:
979*76404edcSAsim Jamshed #line 263 "./configparser.y"
980*76404edcSAsim Jamshed {
981*76404edcSAsim Jamshed   yygotominor.yy41 = (data_unset *)data_string_init();
982*76404edcSAsim Jamshed   buffer_copy_string_buffer(((data_string *)(yygotominor.yy41))->value, yymsp[0].minor.yy0);
983*76404edcSAsim Jamshed   buffer_free(yymsp[0].minor.yy0);
984*76404edcSAsim Jamshed   yymsp[0].minor.yy0 = NULL;
985*76404edcSAsim Jamshed }
986*76404edcSAsim Jamshed #line 986 "configparser.c"
987*76404edcSAsim Jamshed         break;
988*76404edcSAsim Jamshed       case 16:
989*76404edcSAsim Jamshed #line 270 "./configparser.y"
990*76404edcSAsim Jamshed {
991*76404edcSAsim Jamshed   yygotominor.yy41 = (data_unset *)data_integer_init();
992*76404edcSAsim Jamshed   ((data_integer *)(yygotominor.yy41))->value = strtol(yymsp[0].minor.yy0->ptr, NULL, 10);
993*76404edcSAsim Jamshed   buffer_free(yymsp[0].minor.yy0);
994*76404edcSAsim Jamshed   yymsp[0].minor.yy0 = NULL;
995*76404edcSAsim Jamshed }
996*76404edcSAsim Jamshed #line 996 "configparser.c"
997*76404edcSAsim Jamshed         break;
998*76404edcSAsim Jamshed       case 17:
999*76404edcSAsim Jamshed #line 276 "./configparser.y"
1000*76404edcSAsim Jamshed {
1001*76404edcSAsim Jamshed   yygotominor.yy41 = (data_unset *)data_array_init();
1002*76404edcSAsim Jamshed   array_free(((data_array *)(yygotominor.yy41))->value);
1003*76404edcSAsim Jamshed   ((data_array *)(yygotominor.yy41))->value = yymsp[0].minor.yy40;
1004*76404edcSAsim Jamshed   yymsp[0].minor.yy40 = NULL;
1005*76404edcSAsim Jamshed }
1006*76404edcSAsim Jamshed #line 1006 "configparser.c"
1007*76404edcSAsim Jamshed         break;
1008*76404edcSAsim Jamshed       case 18:
1009*76404edcSAsim Jamshed #line 282 "./configparser.y"
1010*76404edcSAsim Jamshed {
1011*76404edcSAsim Jamshed   yygotominor.yy40 = array_init();
1012*76404edcSAsim Jamshed }
1013*76404edcSAsim Jamshed #line 1013 "configparser.c"
1014*76404edcSAsim Jamshed   yy_destructor(8,&yymsp[-1].minor);
1015*76404edcSAsim Jamshed   yy_destructor(9,&yymsp[0].minor);
1016*76404edcSAsim Jamshed         break;
1017*76404edcSAsim Jamshed       case 19:
1018*76404edcSAsim Jamshed #line 285 "./configparser.y"
1019*76404edcSAsim Jamshed {
1020*76404edcSAsim Jamshed   yygotominor.yy40 = yymsp[-1].minor.yy40;
1021*76404edcSAsim Jamshed   yymsp[-1].minor.yy40 = NULL;
1022*76404edcSAsim Jamshed }
1023*76404edcSAsim Jamshed #line 1023 "configparser.c"
1024*76404edcSAsim Jamshed   yy_destructor(8,&yymsp[-2].minor);
1025*76404edcSAsim Jamshed   yy_destructor(9,&yymsp[0].minor);
1026*76404edcSAsim Jamshed         break;
1027*76404edcSAsim Jamshed       case 20:
1028*76404edcSAsim Jamshed #line 290 "./configparser.y"
1029*76404edcSAsim Jamshed {
1030*76404edcSAsim Jamshed   if (buffer_is_empty(yymsp[0].minor.yy41->key) ||
1031*76404edcSAsim Jamshed       NULL == array_get_element(yymsp[-2].minor.yy40, yymsp[0].minor.yy41->key->ptr)) {
1032*76404edcSAsim Jamshed     array_insert_unique(yymsp[-2].minor.yy40, yymsp[0].minor.yy41);
1033*76404edcSAsim Jamshed     yymsp[0].minor.yy41 = NULL;
1034*76404edcSAsim Jamshed   } else {
1035*76404edcSAsim Jamshed     fprintf(stderr, "Duplicate array-key: %s\n",
1036*76404edcSAsim Jamshed             yymsp[0].minor.yy41->key->ptr);
1037*76404edcSAsim Jamshed     ctx->ok = 0;
1038*76404edcSAsim Jamshed     yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
1039*76404edcSAsim Jamshed     yymsp[0].minor.yy41 = NULL;
1040*76404edcSAsim Jamshed   }
1041*76404edcSAsim Jamshed 
1042*76404edcSAsim Jamshed   yygotominor.yy40 = yymsp[-2].minor.yy40;
1043*76404edcSAsim Jamshed   yymsp[-2].minor.yy40 = NULL;
1044*76404edcSAsim Jamshed }
1045*76404edcSAsim Jamshed #line 1045 "configparser.c"
1046*76404edcSAsim Jamshed   yy_destructor(10,&yymsp[-1].minor);
1047*76404edcSAsim Jamshed         break;
1048*76404edcSAsim Jamshed       case 21:
1049*76404edcSAsim Jamshed #line 307 "./configparser.y"
1050*76404edcSAsim Jamshed {
1051*76404edcSAsim Jamshed   yygotominor.yy40 = yymsp[-1].minor.yy40;
1052*76404edcSAsim Jamshed   yymsp[-1].minor.yy40 = NULL;
1053*76404edcSAsim Jamshed }
1054*76404edcSAsim Jamshed #line 1054 "configparser.c"
1055*76404edcSAsim Jamshed   yy_destructor(10,&yymsp[0].minor);
1056*76404edcSAsim Jamshed         break;
1057*76404edcSAsim Jamshed       case 22:
1058*76404edcSAsim Jamshed #line 312 "./configparser.y"
1059*76404edcSAsim Jamshed {
1060*76404edcSAsim Jamshed   yygotominor.yy40 = array_init();
1061*76404edcSAsim Jamshed   array_insert_unique(yygotominor.yy40, yymsp[0].minor.yy41);
1062*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
1063*76404edcSAsim Jamshed }
1064*76404edcSAsim Jamshed #line 1064 "configparser.c"
1065*76404edcSAsim Jamshed         break;
1066*76404edcSAsim Jamshed       case 23:
1067*76404edcSAsim Jamshed #line 318 "./configparser.y"
1068*76404edcSAsim Jamshed {
1069*76404edcSAsim Jamshed   yygotominor.yy41 = yymsp[0].minor.yy41;
1070*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
1071*76404edcSAsim Jamshed }
1072*76404edcSAsim Jamshed #line 1072 "configparser.c"
1073*76404edcSAsim Jamshed         break;
1074*76404edcSAsim Jamshed       case 24:
1075*76404edcSAsim Jamshed #line 322 "./configparser.y"
1076*76404edcSAsim Jamshed {
1077*76404edcSAsim Jamshed   buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43);
1078*76404edcSAsim Jamshed   buffer_free(yymsp[-2].minor.yy43);
1079*76404edcSAsim Jamshed   yymsp[-2].minor.yy43 = NULL;
1080*76404edcSAsim Jamshed 
1081*76404edcSAsim Jamshed   yygotominor.yy41 = yymsp[0].minor.yy41;
1082*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
1083*76404edcSAsim Jamshed }
1084*76404edcSAsim Jamshed #line 1084 "configparser.c"
1085*76404edcSAsim Jamshed   yy_destructor(11,&yymsp[-1].minor);
1086*76404edcSAsim Jamshed         break;
1087*76404edcSAsim Jamshed       case 25:
1088*76404edcSAsim Jamshed   yy_destructor(1,&yymsp[0].minor);
1089*76404edcSAsim Jamshed         break;
1090*76404edcSAsim Jamshed       case 26:
1091*76404edcSAsim Jamshed         break;
1092*76404edcSAsim Jamshed       case 27:
1093*76404edcSAsim Jamshed #line 334 "./configparser.y"
1094*76404edcSAsim Jamshed {
1095*76404edcSAsim Jamshed   data_config *dc;
1096*76404edcSAsim Jamshed   dc = (data_config *)array_get_element(ctx->srv->config_context, "global");
1097*76404edcSAsim Jamshed   assert(dc);
1098*76404edcSAsim Jamshed   configparser_push(ctx, dc, 0);
1099*76404edcSAsim Jamshed }
1100*76404edcSAsim Jamshed #line 1100 "configparser.c"
1101*76404edcSAsim Jamshed   yy_destructor(12,&yymsp[0].minor);
1102*76404edcSAsim Jamshed         break;
1103*76404edcSAsim Jamshed       case 28:
1104*76404edcSAsim Jamshed #line 341 "./configparser.y"
1105*76404edcSAsim Jamshed {
1106*76404edcSAsim Jamshed   data_config *cur;
1107*76404edcSAsim Jamshed 
1108*76404edcSAsim Jamshed   cur = ctx->current;
1109*76404edcSAsim Jamshed   configparser_pop(ctx);
1110*76404edcSAsim Jamshed 
1111*76404edcSAsim Jamshed   assert(cur && ctx->current);
1112*76404edcSAsim Jamshed 
1113*76404edcSAsim Jamshed   yygotominor.yy78 = cur;
1114*76404edcSAsim Jamshed }
1115*76404edcSAsim Jamshed #line 1115 "configparser.c"
1116*76404edcSAsim Jamshed         /* No destructor defined for globalstart */
1117*76404edcSAsim Jamshed   yy_destructor(13,&yymsp[-2].minor);
1118*76404edcSAsim Jamshed         /* No destructor defined for metalines */
1119*76404edcSAsim Jamshed   yy_destructor(14,&yymsp[0].minor);
1120*76404edcSAsim Jamshed         break;
1121*76404edcSAsim Jamshed       case 29:
1122*76404edcSAsim Jamshed #line 352 "./configparser.y"
1123*76404edcSAsim Jamshed {
1124*76404edcSAsim Jamshed   if (yymsp[-3].minor.yy78->context_ndx >= yymsp[0].minor.yy78->context_ndx) {
1125*76404edcSAsim Jamshed     fprintf(stderr, "unreachable else condition\n");
1126*76404edcSAsim Jamshed     ctx->ok = 0;
1127*76404edcSAsim Jamshed   }
1128*76404edcSAsim Jamshed   yymsp[0].minor.yy78->prev = yymsp[-3].minor.yy78;
1129*76404edcSAsim Jamshed   yymsp[-3].minor.yy78->next = yymsp[0].minor.yy78;
1130*76404edcSAsim Jamshed   yygotominor.yy78 = yymsp[0].minor.yy78;
1131*76404edcSAsim Jamshed   yymsp[-3].minor.yy78 = NULL;
1132*76404edcSAsim Jamshed   yymsp[0].minor.yy78 = NULL;
1133*76404edcSAsim Jamshed }
1134*76404edcSAsim Jamshed #line 1134 "configparser.c"
1135*76404edcSAsim Jamshed         /* No destructor defined for eols */
1136*76404edcSAsim Jamshed   yy_destructor(15,&yymsp[-1].minor);
1137*76404edcSAsim Jamshed         break;
1138*76404edcSAsim Jamshed       case 30:
1139*76404edcSAsim Jamshed #line 364 "./configparser.y"
1140*76404edcSAsim Jamshed {
1141*76404edcSAsim Jamshed   yygotominor.yy78 = yymsp[0].minor.yy78;
1142*76404edcSAsim Jamshed   yymsp[0].minor.yy78 = NULL;
1143*76404edcSAsim Jamshed }
1144*76404edcSAsim Jamshed #line 1144 "configparser.c"
1145*76404edcSAsim Jamshed         break;
1146*76404edcSAsim Jamshed       case 31:
1147*76404edcSAsim Jamshed #line 369 "./configparser.y"
1148*76404edcSAsim Jamshed {
1149*76404edcSAsim Jamshed   data_config *cur;
1150*76404edcSAsim Jamshed 
1151*76404edcSAsim Jamshed   cur = ctx->current;
1152*76404edcSAsim Jamshed   configparser_pop(ctx);
1153*76404edcSAsim Jamshed 
1154*76404edcSAsim Jamshed   assert(cur && ctx->current);
1155*76404edcSAsim Jamshed 
1156*76404edcSAsim Jamshed   yygotominor.yy78 = cur;
1157*76404edcSAsim Jamshed }
1158*76404edcSAsim Jamshed #line 1158 "configparser.c"
1159*76404edcSAsim Jamshed         /* No destructor defined for context */
1160*76404edcSAsim Jamshed   yy_destructor(13,&yymsp[-2].minor);
1161*76404edcSAsim Jamshed         /* No destructor defined for metalines */
1162*76404edcSAsim Jamshed   yy_destructor(14,&yymsp[0].minor);
1163*76404edcSAsim Jamshed         break;
1164*76404edcSAsim Jamshed       case 32:
1165*76404edcSAsim Jamshed #line 380 "./configparser.y"
1166*76404edcSAsim Jamshed {
1167*76404edcSAsim Jamshed   data_config *dc;
1168*76404edcSAsim Jamshed   buffer *b, *rvalue, *op;
1169*76404edcSAsim Jamshed 
1170*76404edcSAsim Jamshed   if (ctx->ok && yymsp[0].minor.yy41->type != TYPE_STRING) {
1171*76404edcSAsim Jamshed     fprintf(stderr, "rvalue must be string");
1172*76404edcSAsim Jamshed     ctx->ok = 0;
1173*76404edcSAsim Jamshed   }
1174*76404edcSAsim Jamshed 
1175*76404edcSAsim Jamshed   switch(yymsp[-1].minor.yy27) {
1176*76404edcSAsim Jamshed   case CONFIG_COND_NE:
1177*76404edcSAsim Jamshed     op = buffer_init_string("!=");
1178*76404edcSAsim Jamshed     break;
1179*76404edcSAsim Jamshed   case CONFIG_COND_EQ:
1180*76404edcSAsim Jamshed     op = buffer_init_string("==");
1181*76404edcSAsim Jamshed     break;
1182*76404edcSAsim Jamshed   case CONFIG_COND_NOMATCH:
1183*76404edcSAsim Jamshed     op = buffer_init_string("!~");
1184*76404edcSAsim Jamshed     break;
1185*76404edcSAsim Jamshed   case CONFIG_COND_MATCH:
1186*76404edcSAsim Jamshed     op = buffer_init_string("=~");
1187*76404edcSAsim Jamshed     break;
1188*76404edcSAsim Jamshed   default:
1189*76404edcSAsim Jamshed     assert(0);
1190*76404edcSAsim Jamshed     return;
1191*76404edcSAsim Jamshed   }
1192*76404edcSAsim Jamshed 
1193*76404edcSAsim Jamshed   b = buffer_init();
1194*76404edcSAsim Jamshed   buffer_copy_string_buffer(b, ctx->current->key);
1195*76404edcSAsim Jamshed   buffer_append_string(b, "/");
1196*76404edcSAsim Jamshed   buffer_append_string_buffer(b, yymsp[-5].minor.yy0);
1197*76404edcSAsim Jamshed   buffer_append_string_buffer(b, yymsp[-3].minor.yy43);
1198*76404edcSAsim Jamshed   buffer_append_string_buffer(b, op);
1199*76404edcSAsim Jamshed   rvalue = ((data_string*)yymsp[0].minor.yy41)->value;
1200*76404edcSAsim Jamshed   buffer_append_string_buffer(b, rvalue);
1201*76404edcSAsim Jamshed 
1202*76404edcSAsim Jamshed   if (NULL != (dc = (data_config *)array_get_element(ctx->all_configs, b->ptr))) {
1203*76404edcSAsim Jamshed     configparser_push(ctx, dc, 0);
1204*76404edcSAsim Jamshed   } else {
1205*76404edcSAsim Jamshed     struct {
1206*76404edcSAsim Jamshed       comp_key_t comp;
1207*76404edcSAsim Jamshed       char *comp_key;
1208*76404edcSAsim Jamshed       size_t len;
1209*76404edcSAsim Jamshed     } comps[] = {
1210*76404edcSAsim Jamshed       { COMP_SERVER_SOCKET,      CONST_STR_LEN("SERVER[\"socket\"]"   ) },
1211*76404edcSAsim Jamshed       { COMP_HTTP_URL,           CONST_STR_LEN("HTTP[\"url\"]"        ) },
1212*76404edcSAsim Jamshed       { COMP_HTTP_HOST,          CONST_STR_LEN("HTTP[\"host\"]"       ) },
1213*76404edcSAsim Jamshed       { COMP_HTTP_REFERER,       CONST_STR_LEN("HTTP[\"referer\"]"    ) },
1214*76404edcSAsim Jamshed       { COMP_HTTP_USER_AGENT,    CONST_STR_LEN("HTTP[\"useragent\"]"  ) },
1215*76404edcSAsim Jamshed       { COMP_HTTP_USER_AGENT,    CONST_STR_LEN("HTTP[\"user-agent\"]"  ) },
1216*76404edcSAsim Jamshed       { COMP_HTTP_LANGUAGE,      CONST_STR_LEN("HTTP[\"language\"]"   ) },
1217*76404edcSAsim Jamshed       { COMP_HTTP_COOKIE,        CONST_STR_LEN("HTTP[\"cookie\"]"     ) },
1218*76404edcSAsim Jamshed       { COMP_HTTP_REMOTE_IP,     CONST_STR_LEN("HTTP[\"remoteip\"]"   ) },
1219*76404edcSAsim Jamshed       { COMP_HTTP_REMOTE_IP,     CONST_STR_LEN("HTTP[\"remote-ip\"]"   ) },
1220*76404edcSAsim Jamshed       { COMP_HTTP_QUERY_STRING,  CONST_STR_LEN("HTTP[\"querystring\"]") },
1221*76404edcSAsim Jamshed       { COMP_HTTP_QUERY_STRING,  CONST_STR_LEN("HTTP[\"query-string\"]") },
1222*76404edcSAsim Jamshed       { COMP_HTTP_REQUEST_METHOD, CONST_STR_LEN("HTTP[\"request-method\"]") },
1223*76404edcSAsim Jamshed       { COMP_HTTP_SCHEME,        CONST_STR_LEN("HTTP[\"scheme\"]"     ) },
1224*76404edcSAsim Jamshed       { COMP_UNSET, NULL, 0 },
1225*76404edcSAsim Jamshed     };
1226*76404edcSAsim Jamshed     size_t i;
1227*76404edcSAsim Jamshed 
1228*76404edcSAsim Jamshed     dc = data_config_init();
1229*76404edcSAsim Jamshed 
1230*76404edcSAsim Jamshed     buffer_copy_string_buffer(dc->key, b);
1231*76404edcSAsim Jamshed     buffer_copy_string_buffer(dc->op, op);
1232*76404edcSAsim Jamshed     buffer_copy_string_buffer(dc->comp_key, yymsp[-5].minor.yy0);
1233*76404edcSAsim Jamshed     buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\""));
1234*76404edcSAsim Jamshed     buffer_append_string_buffer(dc->comp_key, yymsp[-3].minor.yy43);
1235*76404edcSAsim Jamshed     buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]"));
1236*76404edcSAsim Jamshed     dc->cond = yymsp[-1].minor.yy27;
1237*76404edcSAsim Jamshed 
1238*76404edcSAsim Jamshed     for (i = 0; comps[i].comp_key; i ++) {
1239*76404edcSAsim Jamshed       if (buffer_is_equal_string(
1240*76404edcSAsim Jamshed             dc->comp_key, comps[i].comp_key, comps[i].len)) {
1241*76404edcSAsim Jamshed         dc->comp = comps[i].comp;
1242*76404edcSAsim Jamshed         break;
1243*76404edcSAsim Jamshed       }
1244*76404edcSAsim Jamshed     }
1245*76404edcSAsim Jamshed     if (COMP_UNSET == dc->comp) {
1246*76404edcSAsim Jamshed       fprintf(stderr, "error comp_key %s", dc->comp_key->ptr);
1247*76404edcSAsim Jamshed       ctx->ok = 0;
1248*76404edcSAsim Jamshed     }
1249*76404edcSAsim Jamshed 
1250*76404edcSAsim Jamshed     switch(yymsp[-1].minor.yy27) {
1251*76404edcSAsim Jamshed     case CONFIG_COND_NE:
1252*76404edcSAsim Jamshed     case CONFIG_COND_EQ:
1253*76404edcSAsim Jamshed       dc->string = buffer_init_buffer(rvalue);
1254*76404edcSAsim Jamshed       break;
1255*76404edcSAsim Jamshed     case CONFIG_COND_NOMATCH:
1256*76404edcSAsim Jamshed     case CONFIG_COND_MATCH: {
1257*76404edcSAsim Jamshed #ifdef HAVE_PCRE_H
1258*76404edcSAsim Jamshed       const char *errptr;
1259*76404edcSAsim Jamshed       int erroff, captures;
1260*76404edcSAsim Jamshed 
1261*76404edcSAsim Jamshed       if (NULL == (dc->regex =
1262*76404edcSAsim Jamshed           pcre_compile(rvalue->ptr, 0, &errptr, &erroff, NULL))) {
1263*76404edcSAsim Jamshed         dc->string = buffer_init_string(errptr);
1264*76404edcSAsim Jamshed         dc->cond = CONFIG_COND_UNSET;
1265*76404edcSAsim Jamshed 
1266*76404edcSAsim Jamshed         fprintf(stderr, "parsing regex failed: %s -> %s at offset %d\n",
1267*76404edcSAsim Jamshed             rvalue->ptr, errptr, erroff);
1268*76404edcSAsim Jamshed 
1269*76404edcSAsim Jamshed         ctx->ok = 0;
1270*76404edcSAsim Jamshed       } else if (NULL == (dc->regex_study =
1271*76404edcSAsim Jamshed           pcre_study(dc->regex, 0, &errptr)) &&
1272*76404edcSAsim Jamshed                  errptr != NULL) {
1273*76404edcSAsim Jamshed         fprintf(stderr, "studying regex failed: %s -> %s\n",
1274*76404edcSAsim Jamshed             rvalue->ptr, errptr);
1275*76404edcSAsim Jamshed         ctx->ok = 0;
1276*76404edcSAsim Jamshed       } else if (0 != (pcre_fullinfo(dc->regex, dc->regex_study, PCRE_INFO_CAPTURECOUNT, &captures))) {
1277*76404edcSAsim Jamshed         fprintf(stderr, "getting capture count for regex failed: %s\n",
1278*76404edcSAsim Jamshed             rvalue->ptr);
1279*76404edcSAsim Jamshed         ctx->ok = 0;
1280*76404edcSAsim Jamshed       } else if (captures > 9) {
1281*76404edcSAsim Jamshed         fprintf(stderr, "Too many captures in regex, use (?:...) instead of (...): %s\n",
1282*76404edcSAsim Jamshed             rvalue->ptr);
1283*76404edcSAsim Jamshed         ctx->ok = 0;
1284*76404edcSAsim Jamshed       } else {
1285*76404edcSAsim Jamshed         dc->string = buffer_init_buffer(rvalue);
1286*76404edcSAsim Jamshed       }
1287*76404edcSAsim Jamshed #else
1288*76404edcSAsim Jamshed       fprintf(stderr, "can't handle '$%s[%s] =~ ...' as you compiled without pcre support. \n"
1289*76404edcSAsim Jamshed 		      "(perhaps just a missing pcre-devel package ?) \n",
1290*76404edcSAsim Jamshed                       yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy43->ptr);
1291*76404edcSAsim Jamshed       ctx->ok = 0;
1292*76404edcSAsim Jamshed #endif
1293*76404edcSAsim Jamshed       break;
1294*76404edcSAsim Jamshed     }
1295*76404edcSAsim Jamshed 
1296*76404edcSAsim Jamshed     default:
1297*76404edcSAsim Jamshed       fprintf(stderr, "unknown condition for $%s[%s]\n",
1298*76404edcSAsim Jamshed                       yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy43->ptr);
1299*76404edcSAsim Jamshed       ctx->ok = 0;
1300*76404edcSAsim Jamshed       break;
1301*76404edcSAsim Jamshed     }
1302*76404edcSAsim Jamshed 
1303*76404edcSAsim Jamshed     configparser_push(ctx, dc, 1);
1304*76404edcSAsim Jamshed   }
1305*76404edcSAsim Jamshed 
1306*76404edcSAsim Jamshed   buffer_free(b);
1307*76404edcSAsim Jamshed   buffer_free(op);
1308*76404edcSAsim Jamshed   buffer_free(yymsp[-5].minor.yy0);
1309*76404edcSAsim Jamshed   yymsp[-5].minor.yy0 = NULL;
1310*76404edcSAsim Jamshed   buffer_free(yymsp[-3].minor.yy43);
1311*76404edcSAsim Jamshed   yymsp[-3].minor.yy43 = NULL;
1312*76404edcSAsim Jamshed   yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
1313*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
1314*76404edcSAsim Jamshed }
1315*76404edcSAsim Jamshed #line 1315 "configparser.c"
1316*76404edcSAsim Jamshed   yy_destructor(16,&yymsp[-6].minor);
1317*76404edcSAsim Jamshed   yy_destructor(18,&yymsp[-4].minor);
1318*76404edcSAsim Jamshed   yy_destructor(19,&yymsp[-2].minor);
1319*76404edcSAsim Jamshed         break;
1320*76404edcSAsim Jamshed       case 33:
1321*76404edcSAsim Jamshed #line 529 "./configparser.y"
1322*76404edcSAsim Jamshed {
1323*76404edcSAsim Jamshed   yygotominor.yy27 = CONFIG_COND_EQ;
1324*76404edcSAsim Jamshed }
1325*76404edcSAsim Jamshed #line 1325 "configparser.c"
1326*76404edcSAsim Jamshed   yy_destructor(20,&yymsp[0].minor);
1327*76404edcSAsim Jamshed         break;
1328*76404edcSAsim Jamshed       case 34:
1329*76404edcSAsim Jamshed #line 532 "./configparser.y"
1330*76404edcSAsim Jamshed {
1331*76404edcSAsim Jamshed   yygotominor.yy27 = CONFIG_COND_MATCH;
1332*76404edcSAsim Jamshed }
1333*76404edcSAsim Jamshed #line 1333 "configparser.c"
1334*76404edcSAsim Jamshed   yy_destructor(21,&yymsp[0].minor);
1335*76404edcSAsim Jamshed         break;
1336*76404edcSAsim Jamshed       case 35:
1337*76404edcSAsim Jamshed #line 535 "./configparser.y"
1338*76404edcSAsim Jamshed {
1339*76404edcSAsim Jamshed   yygotominor.yy27 = CONFIG_COND_NE;
1340*76404edcSAsim Jamshed }
1341*76404edcSAsim Jamshed #line 1341 "configparser.c"
1342*76404edcSAsim Jamshed   yy_destructor(22,&yymsp[0].minor);
1343*76404edcSAsim Jamshed         break;
1344*76404edcSAsim Jamshed       case 36:
1345*76404edcSAsim Jamshed #line 538 "./configparser.y"
1346*76404edcSAsim Jamshed {
1347*76404edcSAsim Jamshed   yygotominor.yy27 = CONFIG_COND_NOMATCH;
1348*76404edcSAsim Jamshed }
1349*76404edcSAsim Jamshed #line 1349 "configparser.c"
1350*76404edcSAsim Jamshed   yy_destructor(23,&yymsp[0].minor);
1351*76404edcSAsim Jamshed         break;
1352*76404edcSAsim Jamshed       case 37:
1353*76404edcSAsim Jamshed #line 542 "./configparser.y"
1354*76404edcSAsim Jamshed {
1355*76404edcSAsim Jamshed   yygotominor.yy43 = NULL;
1356*76404edcSAsim Jamshed   if (ctx->ok) {
1357*76404edcSAsim Jamshed     if (yymsp[0].minor.yy41->type == TYPE_STRING) {
1358*76404edcSAsim Jamshed       yygotominor.yy43 = buffer_init_buffer(((data_string*)yymsp[0].minor.yy41)->value);
1359*76404edcSAsim Jamshed     } else if (yymsp[0].minor.yy41->type == TYPE_INTEGER) {
1360*76404edcSAsim Jamshed       yygotominor.yy43 = buffer_init();
1361*76404edcSAsim Jamshed       buffer_copy_long(yygotominor.yy43, ((data_integer *)yymsp[0].minor.yy41)->value);
1362*76404edcSAsim Jamshed     } else {
1363*76404edcSAsim Jamshed       fprintf(stderr, "operand must be string");
1364*76404edcSAsim Jamshed       ctx->ok = 0;
1365*76404edcSAsim Jamshed     }
1366*76404edcSAsim Jamshed   }
1367*76404edcSAsim Jamshed   yymsp[0].minor.yy41->free(yymsp[0].minor.yy41);
1368*76404edcSAsim Jamshed   yymsp[0].minor.yy41 = NULL;
1369*76404edcSAsim Jamshed }
1370*76404edcSAsim Jamshed #line 1370 "configparser.c"
1371*76404edcSAsim Jamshed         break;
1372*76404edcSAsim Jamshed       case 38:
1373*76404edcSAsim Jamshed #line 559 "./configparser.y"
1374*76404edcSAsim Jamshed {
1375*76404edcSAsim Jamshed   if (ctx->ok) {
1376*76404edcSAsim Jamshed     if (0 != config_parse_file(ctx->srv, ctx, yymsp[0].minor.yy43->ptr)) {
1377*76404edcSAsim Jamshed       ctx->ok = 0;
1378*76404edcSAsim Jamshed     }
1379*76404edcSAsim Jamshed     buffer_free(yymsp[0].minor.yy43);
1380*76404edcSAsim Jamshed     yymsp[0].minor.yy43 = NULL;
1381*76404edcSAsim Jamshed   }
1382*76404edcSAsim Jamshed }
1383*76404edcSAsim Jamshed #line 1383 "configparser.c"
1384*76404edcSAsim Jamshed   yy_destructor(24,&yymsp[-1].minor);
1385*76404edcSAsim Jamshed         break;
1386*76404edcSAsim Jamshed       case 39:
1387*76404edcSAsim Jamshed #line 569 "./configparser.y"
1388*76404edcSAsim Jamshed {
1389*76404edcSAsim Jamshed   if (ctx->ok) {
1390*76404edcSAsim Jamshed     if (0 != config_parse_cmd(ctx->srv, ctx, yymsp[0].minor.yy43->ptr)) {
1391*76404edcSAsim Jamshed       ctx->ok = 0;
1392*76404edcSAsim Jamshed     }
1393*76404edcSAsim Jamshed     buffer_free(yymsp[0].minor.yy43);
1394*76404edcSAsim Jamshed     yymsp[0].minor.yy43 = NULL;
1395*76404edcSAsim Jamshed   }
1396*76404edcSAsim Jamshed }
1397*76404edcSAsim Jamshed #line 1397 "configparser.c"
1398*76404edcSAsim Jamshed   yy_destructor(25,&yymsp[-1].minor);
1399*76404edcSAsim Jamshed         break;
1400*76404edcSAsim Jamshed   };
1401*76404edcSAsim Jamshed   yygoto = yyRuleInfo[yyruleno].lhs;
1402*76404edcSAsim Jamshed   yysize = yyRuleInfo[yyruleno].nrhs;
1403*76404edcSAsim Jamshed   yypParser->yyidx -= yysize;
1404*76404edcSAsim Jamshed   yyact = yy_find_reduce_action(yypParser,yygoto);
1405*76404edcSAsim Jamshed   if( yyact < YYNSTATE ){
1406*76404edcSAsim Jamshed     yy_shift(yypParser,yyact,yygoto,&yygotominor);
1407*76404edcSAsim Jamshed   }else if( yyact == YYNSTATE + YYNRULE + 1 ){
1408*76404edcSAsim Jamshed     yy_accept(yypParser);
1409*76404edcSAsim Jamshed   }
1410*76404edcSAsim Jamshed }
1411*76404edcSAsim Jamshed 
1412*76404edcSAsim Jamshed /*
1413*76404edcSAsim Jamshed ** The following code executes when the parse fails
1414*76404edcSAsim Jamshed */
yy_parse_failed(yyParser * yypParser)1415*76404edcSAsim Jamshed static void yy_parse_failed(
1416*76404edcSAsim Jamshed   yyParser *yypParser           /* The parser */
1417*76404edcSAsim Jamshed ){
1418*76404edcSAsim Jamshed   configparserARG_FETCH;
1419*76404edcSAsim Jamshed #ifndef NDEBUG
1420*76404edcSAsim Jamshed   if( yyTraceFILE ){
1421*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
1422*76404edcSAsim Jamshed   }
1423*76404edcSAsim Jamshed #endif
1424*76404edcSAsim Jamshed   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
1425*76404edcSAsim Jamshed   /* Here code is inserted which will be executed whenever the
1426*76404edcSAsim Jamshed   ** parser fails */
1427*76404edcSAsim Jamshed #line 108 "./configparser.y"
1428*76404edcSAsim Jamshed 
1429*76404edcSAsim Jamshed   ctx->ok = 0;
1430*76404edcSAsim Jamshed 
1431*76404edcSAsim Jamshed #line 1431 "configparser.c"
1432*76404edcSAsim Jamshed   configparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
1433*76404edcSAsim Jamshed }
1434*76404edcSAsim Jamshed 
1435*76404edcSAsim Jamshed /*
1436*76404edcSAsim Jamshed ** The following code executes when a syntax error first occurs.
1437*76404edcSAsim Jamshed */
yy_syntax_error(yyParser * yypParser,int yymajor,YYMINORTYPE yyminor)1438*76404edcSAsim Jamshed static void yy_syntax_error(
1439*76404edcSAsim Jamshed   yyParser *yypParser,           /* The parser */
1440*76404edcSAsim Jamshed   int yymajor,                   /* The major type of the error token */
1441*76404edcSAsim Jamshed   YYMINORTYPE yyminor            /* The minor type of the error token */
1442*76404edcSAsim Jamshed ){
1443*76404edcSAsim Jamshed   configparserARG_FETCH;
1444*76404edcSAsim Jamshed   UNUSED(yymajor);
1445*76404edcSAsim Jamshed   UNUSED(yyminor);
1446*76404edcSAsim Jamshed #define TOKEN (yyminor.yy0)
1447*76404edcSAsim Jamshed   configparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
1448*76404edcSAsim Jamshed }
1449*76404edcSAsim Jamshed 
1450*76404edcSAsim Jamshed /*
1451*76404edcSAsim Jamshed ** The following is executed when the parser accepts
1452*76404edcSAsim Jamshed */
yy_accept(yyParser * yypParser)1453*76404edcSAsim Jamshed static void yy_accept(
1454*76404edcSAsim Jamshed   yyParser *yypParser           /* The parser */
1455*76404edcSAsim Jamshed ){
1456*76404edcSAsim Jamshed   configparserARG_FETCH;
1457*76404edcSAsim Jamshed #ifndef NDEBUG
1458*76404edcSAsim Jamshed   if( yyTraceFILE ){
1459*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
1460*76404edcSAsim Jamshed   }
1461*76404edcSAsim Jamshed #endif
1462*76404edcSAsim Jamshed   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
1463*76404edcSAsim Jamshed   /* Here code is inserted which will be executed whenever the
1464*76404edcSAsim Jamshed   ** parser accepts */
1465*76404edcSAsim Jamshed   configparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
1466*76404edcSAsim Jamshed }
1467*76404edcSAsim Jamshed 
1468*76404edcSAsim Jamshed /* The main parser program.
1469*76404edcSAsim Jamshed ** The first argument is a pointer to a structure obtained from
1470*76404edcSAsim Jamshed ** "configparserAlloc" which describes the current state of the parser.
1471*76404edcSAsim Jamshed ** The second argument is the major token number.  The third is
1472*76404edcSAsim Jamshed ** the minor token.  The fourth optional argument is whatever the
1473*76404edcSAsim Jamshed ** user wants (and specified in the grammar) and is available for
1474*76404edcSAsim Jamshed ** use by the action routines.
1475*76404edcSAsim Jamshed **
1476*76404edcSAsim Jamshed ** Inputs:
1477*76404edcSAsim Jamshed ** <ul>
1478*76404edcSAsim Jamshed ** <li> A pointer to the parser (an opaque structure.)
1479*76404edcSAsim Jamshed ** <li> The major token number.
1480*76404edcSAsim Jamshed ** <li> The minor token number.
1481*76404edcSAsim Jamshed ** <li> An option argument of a grammar-specified type.
1482*76404edcSAsim Jamshed ** </ul>
1483*76404edcSAsim Jamshed **
1484*76404edcSAsim Jamshed ** Outputs:
1485*76404edcSAsim Jamshed ** None.
1486*76404edcSAsim Jamshed */
configparser(void * yyp,int yymajor,configparserTOKENTYPE yyminor configparserARG_PDECL)1487*76404edcSAsim Jamshed void configparser(
1488*76404edcSAsim Jamshed   void *yyp,                   /* The parser */
1489*76404edcSAsim Jamshed   int yymajor,                 /* The major token code number */
1490*76404edcSAsim Jamshed   configparserTOKENTYPE yyminor       /* The value for the token */
1491*76404edcSAsim Jamshed   configparserARG_PDECL               /* Optional %extra_argument parameter */
1492*76404edcSAsim Jamshed ){
1493*76404edcSAsim Jamshed   YYMINORTYPE yyminorunion;
1494*76404edcSAsim Jamshed   int yyact;            /* The parser action. */
1495*76404edcSAsim Jamshed   int yyendofinput;     /* True if we are at the end of input */
1496*76404edcSAsim Jamshed   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
1497*76404edcSAsim Jamshed   yyParser *yypParser;  /* The parser */
1498*76404edcSAsim Jamshed 
1499*76404edcSAsim Jamshed   /* (re)initialize the parser, if necessary */
1500*76404edcSAsim Jamshed   yypParser = (yyParser*)yyp;
1501*76404edcSAsim Jamshed   if( yypParser->yyidx<0 ){
1502*76404edcSAsim Jamshed     if( yymajor==0 ) return;
1503*76404edcSAsim Jamshed     yypParser->yyidx = 0;
1504*76404edcSAsim Jamshed     yypParser->yyerrcnt = -1;
1505*76404edcSAsim Jamshed     yypParser->yystack[0].stateno = 0;
1506*76404edcSAsim Jamshed     yypParser->yystack[0].major = 0;
1507*76404edcSAsim Jamshed   }
1508*76404edcSAsim Jamshed   yyminorunion.yy0 = yyminor;
1509*76404edcSAsim Jamshed   yyendofinput = (yymajor==0);
1510*76404edcSAsim Jamshed   configparserARG_STORE;
1511*76404edcSAsim Jamshed 
1512*76404edcSAsim Jamshed #ifndef NDEBUG
1513*76404edcSAsim Jamshed   if( yyTraceFILE ){
1514*76404edcSAsim Jamshed     fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
1515*76404edcSAsim Jamshed   }
1516*76404edcSAsim Jamshed #endif
1517*76404edcSAsim Jamshed 
1518*76404edcSAsim Jamshed   do{
1519*76404edcSAsim Jamshed     yyact = yy_find_shift_action(yypParser,yymajor);
1520*76404edcSAsim Jamshed     if( yyact<YYNSTATE ){
1521*76404edcSAsim Jamshed       yy_shift(yypParser,yyact,yymajor,&yyminorunion);
1522*76404edcSAsim Jamshed       yypParser->yyerrcnt--;
1523*76404edcSAsim Jamshed       if( yyendofinput && yypParser->yyidx>=0 ){
1524*76404edcSAsim Jamshed         yymajor = 0;
1525*76404edcSAsim Jamshed       }else{
1526*76404edcSAsim Jamshed         yymajor = YYNOCODE;
1527*76404edcSAsim Jamshed       }
1528*76404edcSAsim Jamshed     }else if( yyact < YYNSTATE + YYNRULE ){
1529*76404edcSAsim Jamshed       yy_reduce(yypParser,yyact-YYNSTATE);
1530*76404edcSAsim Jamshed     }else if( yyact == YY_ERROR_ACTION ){
1531*76404edcSAsim Jamshed       int yymx;
1532*76404edcSAsim Jamshed #ifndef NDEBUG
1533*76404edcSAsim Jamshed       if( yyTraceFILE ){
1534*76404edcSAsim Jamshed         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
1535*76404edcSAsim Jamshed       }
1536*76404edcSAsim Jamshed #endif
1537*76404edcSAsim Jamshed #ifdef YYERRORSYMBOL
1538*76404edcSAsim Jamshed       /* A syntax error has occurred.
1539*76404edcSAsim Jamshed       ** The response to an error depends upon whether or not the
1540*76404edcSAsim Jamshed       ** grammar defines an error token "ERROR".
1541*76404edcSAsim Jamshed       **
1542*76404edcSAsim Jamshed       ** This is what we do if the grammar does define ERROR:
1543*76404edcSAsim Jamshed       **
1544*76404edcSAsim Jamshed       **  * Call the %syntax_error function.
1545*76404edcSAsim Jamshed       **
1546*76404edcSAsim Jamshed       **  * Begin popping the stack until we enter a state where
1547*76404edcSAsim Jamshed       **    it is legal to shift the error symbol, then shift
1548*76404edcSAsim Jamshed       **    the error symbol.
1549*76404edcSAsim Jamshed       **
1550*76404edcSAsim Jamshed       **  * Set the error count to three.
1551*76404edcSAsim Jamshed       **
1552*76404edcSAsim Jamshed       **  * Begin accepting and shifting new tokens.  No new error
1553*76404edcSAsim Jamshed       **    processing will occur until three tokens have been
1554*76404edcSAsim Jamshed       **    shifted successfully.
1555*76404edcSAsim Jamshed       **
1556*76404edcSAsim Jamshed       */
1557*76404edcSAsim Jamshed       if( yypParser->yyerrcnt<0 ){
1558*76404edcSAsim Jamshed         yy_syntax_error(yypParser,yymajor,yyminorunion);
1559*76404edcSAsim Jamshed       }
1560*76404edcSAsim Jamshed       yymx = yypParser->yystack[yypParser->yyidx].major;
1561*76404edcSAsim Jamshed       if( yymx==YYERRORSYMBOL || yyerrorhit ){
1562*76404edcSAsim Jamshed #ifndef NDEBUG
1563*76404edcSAsim Jamshed         if( yyTraceFILE ){
1564*76404edcSAsim Jamshed           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
1565*76404edcSAsim Jamshed              yyTracePrompt,yyTokenName[yymajor]);
1566*76404edcSAsim Jamshed         }
1567*76404edcSAsim Jamshed #endif
1568*76404edcSAsim Jamshed         yy_destructor(yymajor,&yyminorunion);
1569*76404edcSAsim Jamshed         yymajor = YYNOCODE;
1570*76404edcSAsim Jamshed       }else{
1571*76404edcSAsim Jamshed          while(
1572*76404edcSAsim Jamshed           yypParser->yyidx >= 0 &&
1573*76404edcSAsim Jamshed           yymx != YYERRORSYMBOL &&
1574*76404edcSAsim Jamshed           (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
1575*76404edcSAsim Jamshed         ){
1576*76404edcSAsim Jamshed           yy_pop_parser_stack(yypParser);
1577*76404edcSAsim Jamshed         }
1578*76404edcSAsim Jamshed         if( yypParser->yyidx < 0 || yymajor==0 ){
1579*76404edcSAsim Jamshed           yy_destructor(yymajor,&yyminorunion);
1580*76404edcSAsim Jamshed           yy_parse_failed(yypParser);
1581*76404edcSAsim Jamshed           yymajor = YYNOCODE;
1582*76404edcSAsim Jamshed         }else if( yymx!=YYERRORSYMBOL ){
1583*76404edcSAsim Jamshed           YYMINORTYPE u2;
1584*76404edcSAsim Jamshed           u2.YYERRSYMDT = 0;
1585*76404edcSAsim Jamshed           yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
1586*76404edcSAsim Jamshed         }
1587*76404edcSAsim Jamshed       }
1588*76404edcSAsim Jamshed       yypParser->yyerrcnt = 3;
1589*76404edcSAsim Jamshed       yyerrorhit = 1;
1590*76404edcSAsim Jamshed #else  /* YYERRORSYMBOL is not defined */
1591*76404edcSAsim Jamshed       /* This is what we do if the grammar does not define ERROR:
1592*76404edcSAsim Jamshed       **
1593*76404edcSAsim Jamshed       **  * Report an error message, and throw away the input token.
1594*76404edcSAsim Jamshed       **
1595*76404edcSAsim Jamshed       **  * If the input token is $, then fail the parse.
1596*76404edcSAsim Jamshed       **
1597*76404edcSAsim Jamshed       ** As before, subsequent error messages are suppressed until
1598*76404edcSAsim Jamshed       ** three input tokens have been successfully shifted.
1599*76404edcSAsim Jamshed       */
1600*76404edcSAsim Jamshed       if( yypParser->yyerrcnt<=0 ){
1601*76404edcSAsim Jamshed         yy_syntax_error(yypParser,yymajor,yyminorunion);
1602*76404edcSAsim Jamshed       }
1603*76404edcSAsim Jamshed       yypParser->yyerrcnt = 3;
1604*76404edcSAsim Jamshed       yy_destructor(yymajor,&yyminorunion);
1605*76404edcSAsim Jamshed       if( yyendofinput ){
1606*76404edcSAsim Jamshed         yy_parse_failed(yypParser);
1607*76404edcSAsim Jamshed       }
1608*76404edcSAsim Jamshed       yymajor = YYNOCODE;
1609*76404edcSAsim Jamshed #endif
1610*76404edcSAsim Jamshed     }else{
1611*76404edcSAsim Jamshed       yy_accept(yypParser);
1612*76404edcSAsim Jamshed       yymajor = YYNOCODE;
1613*76404edcSAsim Jamshed     }
1614*76404edcSAsim Jamshed   }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
1615*76404edcSAsim Jamshed   return;
1616*76404edcSAsim Jamshed }
1617