heimdal_build omit #line statments to allow valgrind to work again
[Samba.git] / source4 / heimdal / lib / com_err / parse.c
blob15e9f656f25632eb547f8ff5a30e173d2acd40ba
1 #ifndef lint
2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
3 #endif
5 #include <stdlib.h>
6 #include <string.h>
8 #define YYBYACC 1
9 #define YYMAJOR 1
10 #define YYMINOR 9
11 #define YYPATCH 20100216
13 #define YYEMPTY (-1)
14 #define yyclearin (yychar = YYEMPTY)
15 #define yyerrok (yyerrflag = 0)
16 #define YYRECOVERING() (yyerrflag != 0)
18 #define YYPREFIX "yy"
20 /* compatibility with bison */
21 #ifdef YYPARSE_PARAM
22 /* compatibility with FreeBSD */
23 #ifdef YYPARSE_PARAM_TYPE
24 #define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
25 #else
26 #define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
27 #endif
28 #else
29 #define YYPARSE_DECL() yyparse(void)
30 #endif /* YYPARSE_PARAM */
32 extern int YYPARSE_DECL();
35 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
36 * (Royal Institute of Technology, Stockholm, Sweden).
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the Institute nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
67 #include "compile_et.h"
68 #include "lex.h"
70 void yyerror (char *s);
71 static long name2number(const char *str);
73 extern char *yytext;
75 /* This is for bison */
77 #if !defined(alloca) && !defined(HAVE_ALLOCA)
78 #define alloca(x) malloc(x)
79 #endif
81 #define YYMALLOC malloc
82 #define YYFREE free
84 typedef union {
85 char *string;
86 int number;
87 } YYSTYPE;
88 #define ET 257
89 #define INDEX 258
90 #define PREFIX 259
91 #define EC 260
92 #define ID 261
93 #define END 262
94 #define STRING 263
95 #define NUMBER 264
96 #define YYERRCODE 256
97 static const short yylhs[] = { -1,
98 0, 0, 1, 1, 3, 4, 4, 2, 2, 5,
99 5, 5, 5, 5,
101 static const short yylen[] = { 2,
102 0, 2, 2, 1, 2, 2, 3, 1, 2, 2,
103 2, 1, 4, 1,
105 static const short yydefred[] = { 0,
106 0, 0, 0, 0, 0, 4, 0, 5, 0, 0,
107 0, 14, 0, 8, 3, 7, 10, 11, 0, 9,
108 0, 13,
110 static const short yydgoto[] = { 3,
111 4, 13, 5, 6, 14,
113 static const short yysindex[] = { -247,
114 -263, -258, 0, -256, -245, 0, -250, 0, -249, -246,
115 -244, 0, -256, 0, 0, 0, 0, 0, -28, 0,
116 -243, 0,
118 static const short yyrindex[] = { 18,
119 0, 0, 0, 0, 0, 0, -251, 0, 0, 1,
120 0, 0, 21, 0, 0, 0, 0, 0, 0, 0,
121 0, 0,
123 static const short yygindex[] = { 0,
124 0, 0, 0, 17, 10,
126 #define YYTABLESIZE 263
127 static const short yytable[] = { 7,
128 12, 9, 10, 11, 8, 12, 6, 6, 6, 1,
129 6, 1, 16, 2, 17, 21, 18, 1, 19, 22,
130 2, 15, 20, 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, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0, 12, 12,
154 12, 0, 12,
156 static const short yycheck[] = { 263,
157 0, 258, 259, 260, 263, 262, 258, 259, 260, 257,
158 262, 257, 263, 261, 264, 44, 263, 0, 263, 263,
159 0, 5, 13, -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, -1, -1,
171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
174 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
175 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
176 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
177 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
178 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
179 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
180 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
181 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
182 -1, -1, -1, -1, -1, -1, -1, -1, 258, 259,
183 260, -1, 262,
185 #define YYFINAL 3
186 #ifndef YYDEBUG
187 #define YYDEBUG 0
188 #endif
189 #define YYMAXTOKEN 264
190 #if YYDEBUG
191 static const char *yyname[] = {
193 "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,
194 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,
195 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,
196 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,
197 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,
198 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,
199 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",
200 "ID","END","STRING","NUMBER",
202 static const char *yyrule[] = {
203 "$accept : file",
204 "file :",
205 "file : header statements",
206 "header : id et",
207 "header : et",
208 "id : ID STRING",
209 "et : ET STRING",
210 "et : ET STRING STRING",
211 "statements : statement",
212 "statements : statements statement",
213 "statement : INDEX NUMBER",
214 "statement : PREFIX STRING",
215 "statement : PREFIX",
216 "statement : EC STRING ',' STRING",
217 "statement : END",
220 #endif
221 #if YYDEBUG
222 #include <stdio.h>
223 #endif
225 /* define the initial stack-sizes */
226 #ifdef YYSTACKSIZE
227 #undef YYMAXDEPTH
228 #define YYMAXDEPTH YYSTACKSIZE
229 #else
230 #ifdef YYMAXDEPTH
231 #define YYSTACKSIZE YYMAXDEPTH
232 #else
233 #define YYSTACKSIZE 500
234 #define YYMAXDEPTH 500
235 #endif
236 #endif
238 #define YYINITSTACKSIZE 500
240 int yydebug;
241 int yynerrs;
243 typedef struct {
244 unsigned stacksize;
245 short *s_base;
246 short *s_mark;
247 short *s_last;
248 YYSTYPE *l_base;
249 YYSTYPE *l_mark;
250 } YYSTACKDATA;
252 #define YYPURE 0
254 int yyerrflag;
255 int yychar;
256 YYSTYPE yyval;
257 YYSTYPE yylval;
259 /* variables for the parser stack */
260 static YYSTACKDATA yystack;
262 static long
263 name2number(const char *str)
265 const char *p;
266 long num = 0;
267 const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
268 "abcdefghijklmnopqrstuvwxyz0123456789_";
269 if(strlen(str) > 4) {
270 yyerror("table name too long");
271 return 0;
273 for(p = str; *p; p++){
274 char *q = strchr(x, *p);
275 if(q == NULL) {
276 yyerror("invalid character in table name");
277 return 0;
279 num = (num << 6) + (q - x) + 1;
281 num <<= 8;
282 if(num > 0x7fffffff)
283 num = -(0xffffffff - num + 1);
284 return num;
287 void
288 yyerror (char *s)
290 _lex_error_message ("%s\n", s);
292 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
293 static int yygrowstack(YYSTACKDATA *data)
295 int i;
296 unsigned newsize;
297 short *newss;
298 YYSTYPE *newvs;
300 if ((newsize = data->stacksize) == 0)
301 newsize = YYINITSTACKSIZE;
302 else if (newsize >= YYMAXDEPTH)
303 return -1;
304 else if ((newsize *= 2) > YYMAXDEPTH)
305 newsize = YYMAXDEPTH;
307 i = data->s_mark - data->s_base;
308 newss = (data->s_base != 0)
309 ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
310 : (short *)malloc(newsize * sizeof(*newss));
311 if (newss == 0)
312 return -1;
314 data->s_base = newss;
315 data->s_mark = newss + i;
317 newvs = (data->l_base != 0)
318 ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
319 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
320 if (newvs == 0)
321 return -1;
323 data->l_base = newvs;
324 data->l_mark = newvs + i;
326 data->stacksize = newsize;
327 data->s_last = data->s_base + newsize - 1;
328 return 0;
331 #if YYPURE || defined(YY_NO_LEAKS)
332 static void yyfreestack(YYSTACKDATA *data)
334 free(data->s_base);
335 free(data->l_base);
336 memset(data, 0, sizeof(*data));
338 #else
339 #define yyfreestack(data) /* nothing */
340 #endif
342 #define YYABORT goto yyabort
343 #define YYREJECT goto yyabort
344 #define YYACCEPT goto yyaccept
345 #define YYERROR goto yyerrlab
348 YYPARSE_DECL()
350 int yym, yyn, yystate;
351 #if YYDEBUG
352 const char *yys;
354 if ((yys = getenv("YYDEBUG")) != 0)
356 yyn = *yys;
357 if (yyn >= '0' && yyn <= '9')
358 yydebug = yyn - '0';
360 #endif
362 yynerrs = 0;
363 yyerrflag = 0;
364 yychar = YYEMPTY;
365 yystate = 0;
367 #if YYPURE
368 memset(&yystack, 0, sizeof(yystack));
369 #endif
371 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
372 yystack.s_mark = yystack.s_base;
373 yystack.l_mark = yystack.l_base;
374 yystate = 0;
375 *yystack.s_mark = 0;
377 yyloop:
378 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
379 if (yychar < 0)
381 if ((yychar = yylex()) < 0) yychar = 0;
382 #if YYDEBUG
383 if (yydebug)
385 yys = 0;
386 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
387 if (!yys) yys = "illegal-symbol";
388 printf("%sdebug: state %d, reading %d (%s)\n",
389 YYPREFIX, yystate, yychar, yys);
391 #endif
393 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
394 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
396 #if YYDEBUG
397 if (yydebug)
398 printf("%sdebug: state %d, shifting to state %d\n",
399 YYPREFIX, yystate, yytable[yyn]);
400 #endif
401 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
403 goto yyoverflow;
405 yystate = yytable[yyn];
406 *++yystack.s_mark = yytable[yyn];
407 *++yystack.l_mark = yylval;
408 yychar = YYEMPTY;
409 if (yyerrflag > 0) --yyerrflag;
410 goto yyloop;
412 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
413 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
415 yyn = yytable[yyn];
416 goto yyreduce;
418 if (yyerrflag) goto yyinrecovery;
420 yyerror("syntax error");
422 goto yyerrlab;
424 yyerrlab:
425 ++yynerrs;
427 yyinrecovery:
428 if (yyerrflag < 3)
430 yyerrflag = 3;
431 for (;;)
433 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
434 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
436 #if YYDEBUG
437 if (yydebug)
438 printf("%sdebug: state %d, error recovery shifting\
439 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
440 #endif
441 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
443 goto yyoverflow;
445 yystate = yytable[yyn];
446 *++yystack.s_mark = yytable[yyn];
447 *++yystack.l_mark = yylval;
448 goto yyloop;
450 else
452 #if YYDEBUG
453 if (yydebug)
454 printf("%sdebug: error recovery discarding state %d\n",
455 YYPREFIX, *yystack.s_mark);
456 #endif
457 if (yystack.s_mark <= yystack.s_base) goto yyabort;
458 --yystack.s_mark;
459 --yystack.l_mark;
463 else
465 if (yychar == 0) goto yyabort;
466 #if YYDEBUG
467 if (yydebug)
469 yys = 0;
470 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
471 if (!yys) yys = "illegal-symbol";
472 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
473 YYPREFIX, yystate, yychar, yys);
475 #endif
476 yychar = YYEMPTY;
477 goto yyloop;
480 yyreduce:
481 #if YYDEBUG
482 if (yydebug)
483 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
484 YYPREFIX, yystate, yyn, yyrule[yyn]);
485 #endif
486 yym = yylen[yyn];
487 if (yym)
488 yyval = yystack.l_mark[1-yym];
489 else
490 memset(&yyval, 0, sizeof yyval);
491 switch (yyn)
493 case 5:
495 id_str = yystack.l_mark[0].string;
497 break;
498 case 6:
500 base_id = name2number(yystack.l_mark[0].string);
501 strlcpy(name, yystack.l_mark[0].string, sizeof(name));
502 free(yystack.l_mark[0].string);
504 break;
505 case 7:
507 base_id = name2number(yystack.l_mark[-1].string);
508 strlcpy(name, yystack.l_mark[0].string, sizeof(name));
509 free(yystack.l_mark[-1].string);
510 free(yystack.l_mark[0].string);
512 break;
513 case 10:
515 number = yystack.l_mark[0].number;
517 break;
518 case 11:
520 free(prefix);
521 asprintf (&prefix, "%s_", yystack.l_mark[0].string);
522 if (prefix == NULL)
523 errx(1, "malloc");
524 free(yystack.l_mark[0].string);
526 break;
527 case 12:
529 prefix = realloc(prefix, 1);
530 if (prefix == NULL)
531 errx(1, "malloc");
532 *prefix = '\0';
534 break;
535 case 13:
537 struct error_code *ec = malloc(sizeof(*ec));
539 if (ec == NULL)
540 errx(1, "malloc");
542 ec->next = NULL;
543 ec->number = number;
544 if(prefix && *prefix != '\0') {
545 asprintf (&ec->name, "%s%s", prefix, yystack.l_mark[-2].string);
546 if (ec->name == NULL)
547 errx(1, "malloc");
548 free(yystack.l_mark[-2].string);
549 } else
550 ec->name = yystack.l_mark[-2].string;
551 ec->string = yystack.l_mark[0].string;
552 APPEND(codes, ec);
553 number++;
555 break;
556 case 14:
558 YYACCEPT;
560 break;
562 yystack.s_mark -= yym;
563 yystate = *yystack.s_mark;
564 yystack.l_mark -= yym;
565 yym = yylhs[yyn];
566 if (yystate == 0 && yym == 0)
568 #if YYDEBUG
569 if (yydebug)
570 printf("%sdebug: after reduction, shifting from state 0 to\
571 state %d\n", YYPREFIX, YYFINAL);
572 #endif
573 yystate = YYFINAL;
574 *++yystack.s_mark = YYFINAL;
575 *++yystack.l_mark = yyval;
576 if (yychar < 0)
578 if ((yychar = yylex()) < 0) yychar = 0;
579 #if YYDEBUG
580 if (yydebug)
582 yys = 0;
583 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
584 if (!yys) yys = "illegal-symbol";
585 printf("%sdebug: state %d, reading %d (%s)\n",
586 YYPREFIX, YYFINAL, yychar, yys);
588 #endif
590 if (yychar == 0) goto yyaccept;
591 goto yyloop;
593 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
594 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
595 yystate = yytable[yyn];
596 else
597 yystate = yydgoto[yym];
598 #if YYDEBUG
599 if (yydebug)
600 printf("%sdebug: after reduction, shifting from state %d \
601 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
602 #endif
603 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
605 goto yyoverflow;
607 *++yystack.s_mark = (short) yystate;
608 *++yystack.l_mark = yyval;
609 goto yyloop;
611 yyoverflow:
612 yyerror("yacc stack overflow");
614 yyabort:
615 yyfreestack(&yystack);
616 return (1);
618 yyaccept:
619 yyfreestack(&yystack);
620 return (0);