a4266133035483c524c5f9d3553c0ad044e03729
[kai/samba.git] / source4 / heimdal / lib / com_err / parse.c
1 #ifndef lint
2 static const char yysccsid[] = "@(#)yaccpar     1.9 (Berkeley) 02/21/93";
3 #endif
4
5 #include <stdlib.h>
6 #include <string.h>
7
8 #define YYBYACC 1
9 #define YYMAJOR 1
10 #define YYMINOR 9
11 #define YYPATCH 20070509
12
13 #define YYEMPTY (-1)
14 #define yyclearin    (yychar = YYEMPTY)
15 #define yyerrok      (yyerrflag = 0)
16 #define YYRECOVERING (yyerrflag != 0)
17
18 extern int yyparse(void);
19
20 static int yygrowstack(void);
21 #define YYPREFIX "yy"
22 #line 2 ""
23 /*
24  * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
25  * (Royal Institute of Technology, Stockholm, Sweden).
26  * All rights reserved.
27  *
28  * Redistribution and use in source and binary forms, with or without
29  * modification, are permitted provided that the following conditions
30  * are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright
33  *    notice, this list of conditions and the following disclaimer.
34  *
35  * 2. Redistributions in binary form must reproduce the above copyright
36  *    notice, this list of conditions and the following disclaimer in the
37  *    documentation and/or other materials provided with the distribution.
38  *
39  * 3. Neither the name of the Institute nor the names of its contributors
40  *    may be used to endorse or promote products derived from this software
41  *    without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
44  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
47  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53  * SUCH DAMAGE.
54  */
55
56 #include "compile_et.h"
57 #include "lex.h"
58
59 void yyerror (char *s);
60 static long name2number(const char *str);
61
62 extern char *yytext;
63
64 /* This is for bison */
65
66 #if !defined(alloca) && !defined(HAVE_ALLOCA)
67 #define alloca(x) malloc(x)
68 #endif
69
70 #line 51 ""
71 typedef union {
72   char *string;
73   int number;
74 } YYSTYPE;
75 #line 76 ""
76 #define ET 257
77 #define INDEX 258
78 #define PREFIX 259
79 #define EC 260
80 #define ID 261
81 #define END 262
82 #define STRING 263
83 #define NUMBER 264
84 #define YYERRCODE 256
85 short yylhs[] = {                                        -1,
86     0,    0,    1,    1,    3,    4,    4,    2,    2,    5,
87     5,    5,    5,    5,
88 };
89 short yylen[] = {                                         2,
90     0,    2,    2,    1,    2,    2,    3,    1,    2,    2,
91     2,    1,    4,    1,
92 };
93 short yydefred[] = {                                      0,
94     0,    0,    0,    0,    0,    4,    0,    5,    0,    0,
95     0,   14,    0,    8,    3,    7,   10,   11,    0,    9,
96     0,   13,
97 };
98 short yydgoto[] = {                                       3,
99     4,   13,    5,    6,   14,
100 };
101 short yysindex[] = {                                   -247,
102  -263, -258,    0, -256, -245,    0, -250,    0, -249, -246,
103  -244,    0, -256,    0,    0,    0,    0,    0,  -28,    0,
104  -243,    0,
105 };
106 short yyrindex[] = {                                     18,
107     0,    0,    0,    0,    0,    0, -251,    0,    0,    1,
108     0,    0,   21,    0,    0,    0,    0,    0,    0,    0,
109     0,    0,
110 };
111 short yygindex[] = {                                      0,
112     0,    0,    0,   17,   10,
113 };
114 #define YYTABLESIZE 263
115 short yytable[] = {                                       7,
116    12,    9,   10,   11,    8,   12,    6,    6,    6,    1,
117     6,    1,   16,    2,   17,   21,   18,    1,   19,   22,
118     2,   15,   20,    0,    0,    0,    0,    0,    0,    0,
119     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
120     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
121     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
122     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
123     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
124     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
125     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
126     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
127     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
128     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
129     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
130     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
131     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
132     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
133     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
134     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
135     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
136     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
137     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
138     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
139     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
140     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
141     0,    0,    0,    0,    0,    0,    0,    0,   12,   12,
142    12,    0,   12,
143 };
144 short yycheck[] = {                                     263,
145     0,  258,  259,  260,  263,  262,  258,  259,  260,  257,
146   262,  257,  263,  261,  264,   44,  263,    0,  263,  263,
147     0,    5,   13,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
148    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
149    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
150    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
151    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
152    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
153    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
154    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
155    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
156    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
157    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
158    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
159    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
160    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
161    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
162    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
163    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
164    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
165    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
166    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
167    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
168    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
169    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
170    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,  259,
171   260,   -1,  262,
172 };
173 #define YYFINAL 3
174 #ifndef YYDEBUG
175 #define YYDEBUG 0
176 #endif
177 #define YYMAXTOKEN 264
178 #if YYDEBUG
179 char *yyname[] = {
180 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
181 0,0,0,0,0,0,0,0,0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
182 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
183 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
184 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
185 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
186 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"ET","INDEX","PREFIX","EC",
187 "ID","END","STRING","NUMBER",
188 };
189 char *yyrule[] = {
190 "$accept : file",
191 "file :",
192 "file : header statements",
193 "header : id et",
194 "header : et",
195 "id : ID STRING",
196 "et : ET STRING",
197 "et : ET STRING STRING",
198 "statements : statement",
199 "statements : statements statement",
200 "statement : INDEX NUMBER",
201 "statement : PREFIX STRING",
202 "statement : PREFIX",
203 "statement : EC STRING ',' STRING",
204 "statement : END",
205 };
206 #endif
207 #if YYDEBUG
208 #include <stdio.h>
209 #endif
210
211 /* define the initial stack-sizes */
212 #ifdef YYSTACKSIZE
213 #undef YYMAXDEPTH
214 #define YYMAXDEPTH  YYSTACKSIZE
215 #else
216 #ifdef YYMAXDEPTH
217 #define YYSTACKSIZE YYMAXDEPTH
218 #else
219 #define YYSTACKSIZE 500
220 #define YYMAXDEPTH  500
221 #endif
222 #endif
223
224 #define YYINITSTACKSIZE 500
225
226 int      yydebug;
227 int      yynerrs;
228 int      yyerrflag;
229 int      yychar;
230 short   *yyssp;
231 YYSTYPE *yyvsp;
232 YYSTYPE  yyval;
233 YYSTYPE  yylval;
234
235 /* variables for the parser stack */
236 static short   *yyss;
237 static short   *yysslim;
238 static YYSTYPE *yyvs;
239 static int      yystacksize;
240 #line 141 ""
241
242 static long
243 name2number(const char *str)
244 {
245     const char *p;
246     long num = 0;
247     const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
248         "abcdefghijklmnopqrstuvwxyz0123456789_";
249     if(strlen(str) > 4) {
250         yyerror("table name too long");
251         return 0;
252     }
253     for(p = str; *p; p++){
254         char *q = strchr(x, *p);
255         if(q == NULL) {
256             yyerror("invalid character in table name");
257             return 0;
258         }
259         num = (num << 6) + (q - x) + 1;
260     }
261     num <<= 8;
262     if(num > 0x7fffffff)
263         num = -(0xffffffff - num + 1);
264     return num;
265 }
266
267 void
268 yyerror (char *s)
269 {
270      error_message ("%s\n", s);
271 }
272 #line 273 ""
273 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
274 static int yygrowstack(void)
275 {
276     int newsize, i;
277     short *newss;
278     YYSTYPE *newvs;
279
280     if ((newsize = yystacksize) == 0)
281         newsize = YYINITSTACKSIZE;
282     else if (newsize >= YYMAXDEPTH)
283         return -1;
284     else if ((newsize *= 2) > YYMAXDEPTH)
285         newsize = YYMAXDEPTH;
286
287     i = yyssp - yyss;
288     newss = (yyss != 0)
289           ? (short *)realloc(yyss, newsize * sizeof(*newss))
290           : (short *)malloc(newsize * sizeof(*newss));
291     if (newss == 0)
292         return -1;
293
294     yyss  = newss;
295     yyssp = newss + i;
296     newvs = (yyvs != 0)
297           ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
298           : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
299     if (newvs == 0)
300         return -1;
301
302     yyvs = newvs;
303     yyvsp = newvs + i;
304     yystacksize = newsize;
305     yysslim = yyss + newsize - 1;
306     return 0;
307 }
308
309 #define YYABORT goto yyabort
310 #define YYREJECT goto yyabort
311 #define YYACCEPT goto yyaccept
312 #define YYERROR goto yyerrlab
313 int
314 yyparse(void)
315 {
316     register int yym, yyn, yystate;
317 #if YYDEBUG
318     register const char *yys;
319
320     if ((yys = getenv("YYDEBUG")) != 0)
321     {
322         yyn = *yys;
323         if (yyn >= '0' && yyn <= '9')
324             yydebug = yyn - '0';
325     }
326 #endif
327
328     yynerrs = 0;
329     yyerrflag = 0;
330     yychar = YYEMPTY;
331
332     if (yyss == NULL && yygrowstack()) goto yyoverflow;
333     yyssp = yyss;
334     yyvsp = yyvs;
335     *yyssp = yystate = 0;
336
337 yyloop:
338     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
339     if (yychar < 0)
340     {
341         if ((yychar = yylex()) < 0) yychar = 0;
342 #if YYDEBUG
343         if (yydebug)
344         {
345             yys = 0;
346             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
347             if (!yys) yys = "illegal-symbol";
348             printf("%sdebug: state %d, reading %d (%s)\n",
349                     YYPREFIX, yystate, yychar, yys);
350         }
351 #endif
352     }
353     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
354             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
355     {
356 #if YYDEBUG
357         if (yydebug)
358             printf("%sdebug: state %d, shifting to state %d\n",
359                     YYPREFIX, yystate, yytable[yyn]);
360 #endif
361         if (yyssp >= yysslim && yygrowstack())
362         {
363             goto yyoverflow;
364         }
365         *++yyssp = yystate = yytable[yyn];
366         *++yyvsp = yylval;
367         yychar = YYEMPTY;
368         if (yyerrflag > 0)  --yyerrflag;
369         goto yyloop;
370     }
371     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
372             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
373     {
374         yyn = yytable[yyn];
375         goto yyreduce;
376     }
377     if (yyerrflag) goto yyinrecovery;
378
379     yyerror("syntax error");
380
381 #ifdef lint
382     goto yyerrlab;
383 #endif
384
385 yyerrlab:
386     ++yynerrs;
387
388 yyinrecovery:
389     if (yyerrflag < 3)
390     {
391         yyerrflag = 3;
392         for (;;)
393         {
394             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
395                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
396             {
397 #if YYDEBUG
398                 if (yydebug)
399                     printf("%sdebug: state %d, error recovery shifting\
400  to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
401 #endif
402                 if (yyssp >= yysslim && yygrowstack())
403                 {
404                     goto yyoverflow;
405                 }
406                 *++yyssp = yystate = yytable[yyn];
407                 *++yyvsp = yylval;
408                 goto yyloop;
409             }
410             else
411             {
412 #if YYDEBUG
413                 if (yydebug)
414                     printf("%sdebug: error recovery discarding state %d\n",
415                             YYPREFIX, *yyssp);
416 #endif
417                 if (yyssp <= yyss) goto yyabort;
418                 --yyssp;
419                 --yyvsp;
420             }
421         }
422     }
423     else
424     {
425         if (yychar == 0) goto yyabort;
426 #if YYDEBUG
427         if (yydebug)
428         {
429             yys = 0;
430             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
431             if (!yys) yys = "illegal-symbol";
432             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
433                     YYPREFIX, yystate, yychar, yys);
434         }
435 #endif
436         yychar = YYEMPTY;
437         goto yyloop;
438     }
439
440 yyreduce:
441 #if YYDEBUG
442     if (yydebug)
443         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
444                 YYPREFIX, yystate, yyn, yyrule[yyn]);
445 #endif
446     yym = yylen[yyn];
447     if (yym)
448         yyval = yyvsp[1-yym];
449     else
450         memset(&yyval, 0, sizeof yyval);
451     switch (yyn)
452     {
453 case 5:
454 #line 71 ""
455 {
456                     id_str = yyvsp[0].string;
457                 }
458 break;
459 case 6:
460 #line 77 ""
461 {
462                     base_id = name2number(yyvsp[0].string);
463                     strlcpy(name, yyvsp[0].string, sizeof(name));
464                     free(yyvsp[0].string);
465                 }
466 break;
467 case 7:
468 #line 83 ""
469 {
470                     base_id = name2number(yyvsp[-1].string);
471                     strlcpy(name, yyvsp[0].string, sizeof(name));
472                     free(yyvsp[-1].string);
473                     free(yyvsp[0].string);
474                 }
475 break;
476 case 10:
477 #line 96 ""
478 {
479                         number = yyvsp[0].number;
480                 }
481 break;
482 case 11:
483 #line 100 ""
484 {
485                     free(prefix);
486                     asprintf (&prefix, "%s_", yyvsp[0].string);
487                     if (prefix == NULL)
488                         errx(1, "malloc");
489                     free(yyvsp[0].string);
490                 }
491 break;
492 case 12:
493 #line 108 ""
494 {
495                     prefix = realloc(prefix, 1);
496                     if (prefix == NULL)
497                         errx(1, "malloc");
498                     *prefix = '\0';
499                 }
500 break;
501 case 13:
502 #line 115 ""
503 {
504                     struct error_code *ec = malloc(sizeof(*ec));
505                 
506                     if (ec == NULL)
507                         errx(1, "malloc");
508
509                     ec->next = NULL;
510                     ec->number = number;
511                     if(prefix && *prefix != '\0') {
512                         asprintf (&ec->name, "%s%s", prefix, yyvsp[-2].string);
513                         if (ec->name == NULL)
514                             errx(1, "malloc");
515                         free(yyvsp[-2].string);
516                     } else
517                         ec->name = yyvsp[-2].string;
518                     ec->string = yyvsp[0].string;
519                     APPEND(codes, ec);
520                     number++;
521                 }
522 break;
523 case 14:
524 #line 135 ""
525 {
526                         YYACCEPT;
527                 }
528 break;
529 #line 530 ""
530     }
531     yyssp -= yym;
532     yystate = *yyssp;
533     yyvsp -= yym;
534     yym = yylhs[yyn];
535     if (yystate == 0 && yym == 0)
536     {
537 #if YYDEBUG
538         if (yydebug)
539             printf("%sdebug: after reduction, shifting from state 0 to\
540  state %d\n", YYPREFIX, YYFINAL);
541 #endif
542         yystate = YYFINAL;
543         *++yyssp = YYFINAL;
544         *++yyvsp = yyval;
545         if (yychar < 0)
546         {
547             if ((yychar = yylex()) < 0) yychar = 0;
548 #if YYDEBUG
549             if (yydebug)
550             {
551                 yys = 0;
552                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
553                 if (!yys) yys = "illegal-symbol";
554                 printf("%sdebug: state %d, reading %d (%s)\n",
555                         YYPREFIX, YYFINAL, yychar, yys);
556             }
557 #endif
558         }
559         if (yychar == 0) goto yyaccept;
560         goto yyloop;
561     }
562     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
563             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
564         yystate = yytable[yyn];
565     else
566         yystate = yydgoto[yym];
567 #if YYDEBUG
568     if (yydebug)
569         printf("%sdebug: after reduction, shifting from state %d \
570 to state %d\n", YYPREFIX, *yyssp, yystate);
571 #endif
572     if (yyssp >= yysslim && yygrowstack())
573     {
574         goto yyoverflow;
575     }
576     *++yyssp = yystate;
577     *++yyvsp = yyval;
578     goto yyloop;
579
580 yyoverflow:
581     yyerror("yacc stack overflow");
582
583 yyabort:
584     return (1);
585
586 yyaccept:
587     return (0);
588 }