Fixes for OpenBSD
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / OL_DataExpr.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: OL_DataExpr.C /main/4 1997/12/23 11:38:27 bill $ */
24 #ifndef lint
25 static const char ol_datasccsid[] = "@(#)yaccpar        1.8 (Berkeley) 01/20/90";
26 #endif
27 #define ol_dataBYACC 1
28 #line 2 "OL_DataExpr.y"
29 #include <stdio.h>
30 #include "ExprList.h"
31 #include "Expression.h"
32 #include "ContentType.h"
33
34 extern int ol_datalex();
35 extern void ol_dataerror( char *str );
36
37 extern ContentType *CurrentContentPtr;
38
39 #line 14 "OL_DataExpr.y"
40 typedef union {
41   int        name;
42   char       *string;
43   OL_Expression *eptr;
44 } ol_dataSTYPE;
45 #line 23 "y.tab.c"
46 #define Reference 257
47 #define Id 258
48 #define Literal 259
49 #define Content 260
50 #define Concat 261
51 #define Attr 262
52 #define FirstOf 263
53 #define ol_dataERRCODE 256
54 short ol_datalhs[] = {                                        -1,
55     0,    2,    2,    1,    1,    1,    1,    1,    1,    1,
56 };
57 short ol_datalen[] = {                                         2,
58     1,    1,    3,    1,    1,    4,    4,    4,    1,    1,
59 };
60 short ol_datadefred[] = {                                      0,
61    10,    4,    9,    5,    0,    0,    0,    0,    0,    1,
62     0,    0,    0,    0,    0,    0,    0,    3,    6,    7,
63     8,
64 };
65 short ol_datadgoto[] = {                                       8,
66     9,   10,
67 };
68 short ol_datasindex[] = {                                   -255,
69     0,    0,    0,    0,  -40,  -30,  -27,    0,  -29,    0,
70  -255, -244, -255, -255,  -25,  -24,  -23,    0,    0,    0,
71     0,
72 };
73 short ol_datarindex[] = {                                      0,
74     0,    0,    0,    0,    0,    0,    0,    0,    1,    0,
75     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
76     0,
77 };
78 short ol_datagindex[] = {                                      0,
79     0,   -2,
80 };
81 #define ol_dataTABLESIZE 42
82 short ol_datatable[] = {                                      11,
83     2,    1,    2,    3,    4,    5,    6,    7,   15,   12,
84    17,   18,   13,   16,   14,   19,   20,   21,    0,    0,
85     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
86     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
87     0,    2,
88 };
89 short ol_datacheck[] = {                                      40,
90     0,  257,  258,  259,  260,  261,  262,  263,   11,   40,
91    13,   14,   40,  258,   44,   41,   41,   41,   -1,   -1,
92    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
93    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
94    -1,   41,
95 };
96 #define ol_dataFINAL 8
97 #ifndef ol_dataDEBUG
98 #define ol_dataDEBUG 0
99 #endif
100 #define ol_dataMAXTOKEN 263
101 #if ol_dataDEBUG
102 char *ol_dataname[] = {
103 "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,
104 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,
105 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,
106 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,
107 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,
108 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,
109 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,"Reference","Id",
110 "Literal","Content","Concat","Attr","FirstOf",
111 };
112 char *ol_datarule[] = {
113 "$accept : ValList",
114 "ValList : ExprList",
115 "ExprList : Expr",
116 "ExprList : Expr ',' ExprList",
117 "Expr : Id",
118 "Expr : Content",
119 "Expr : Concat '(' ExprList ')'",
120 "Expr : Attr '(' Id ')'",
121 "Expr : FirstOf '(' ExprList ')'",
122 "Expr : Literal",
123 "Expr : Reference",
124 };
125 #endif
126 #define ol_dataclearin (ol_datachar=(-1))
127 #define ol_dataerrok (ol_dataerrflag=0)
128 #ifdef ol_dataSTACKSIZE
129 #ifndef ol_dataMAXDEPTH
130 #define ol_dataMAXDEPTH ol_dataSTACKSIZE
131 #endif
132 #else
133 #ifdef ol_dataMAXDEPTH
134 #define ol_dataSTACKSIZE ol_dataMAXDEPTH
135 #else
136 #define ol_dataSTACKSIZE 500
137 #define ol_dataMAXDEPTH 500
138 #endif
139 #endif
140 int ol_datadebug;
141 int ol_datanerrs;
142 int ol_dataerrflag;
143 int ol_datachar;
144 short *ol_datassp;
145 ol_dataSTYPE *ol_datavsp;
146 ol_dataSTYPE ol_dataval;
147 ol_dataSTYPE ol_datalval;
148 short ol_datass[ol_dataSTACKSIZE];
149 ol_dataSTYPE ol_datavs[ol_dataSTACKSIZE];
150 #define ol_datastacksize ol_dataSTACKSIZE
151 #line 97 "OL_DataExpr.y"
152         
153
154
155   
156
157
158 #line 136 "y.tab.c"
159 #define ol_dataABORT goto ol_dataabort
160 #define ol_dataACCEPT goto ol_dataaccept
161 #define ol_dataERROR goto ol_dataerrlab
162 #if ol_dataDEBUG
163 #ifndef __cplusplus
164 extern char *getenv(const char *);
165 #endif
166 #endif
167 int
168 ol_dataparse()
169 {
170     register int ol_datam, ol_datan, ol_datastate;
171 #if ol_dataDEBUG
172     register char *ol_datas;
173
174     if ((ol_datas = getenv("ol_dataDEBUG")))
175     {
176         ol_datan = *ol_datas;
177         if (ol_datan >= '0' && ol_datan <= '9')
178             ol_datadebug = ol_datan - '0';
179     }
180 #endif
181
182     ol_datanerrs = 0;
183     ol_dataerrflag = 0;
184     ol_datachar = (-1);
185
186     ol_datassp = ol_datass;
187     ol_datavsp = ol_datavs;
188     *ol_datassp = ol_datastate = 0;
189
190 ol_dataloop:
191     if ((ol_datan = ol_datadefred[ol_datastate])) goto ol_datareduce;
192     if (ol_datachar < 0)
193     {
194         if ((ol_datachar = ol_datalex()) < 0) ol_datachar = 0;
195 #if ol_dataDEBUG
196         if (ol_datadebug)
197         {
198             ol_datas = 0;
199             if (ol_datachar <= ol_dataMAXTOKEN) ol_datas = ol_dataname[ol_datachar];
200             if (!ol_datas) ol_datas = "illegal-symbol";
201             printf("ol_datadebug: state %d, reading %d (%s)\n", ol_datastate,
202                     ol_datachar, ol_datas);
203         }
204 #endif
205     }
206     if ((ol_datan = ol_datasindex[ol_datastate]) && (ol_datan += ol_datachar) >= 0 &&
207             ol_datan <= ol_dataTABLESIZE && ol_datacheck[ol_datan] == ol_datachar)
208     {
209 #if ol_dataDEBUG
210         if (ol_datadebug)
211             printf("ol_datadebug: state %d, shifting to state %d\n",
212                     ol_datastate, ol_datatable[ol_datan]);
213 #endif
214         if (ol_datassp >= ol_datass + ol_datastacksize - 1)
215         {
216             goto ol_dataoverflow;
217         }
218         *++ol_datassp = ol_datastate = ol_datatable[ol_datan];
219         *++ol_datavsp = ol_datalval;
220         ol_datachar = (-1);
221         if (ol_dataerrflag > 0)  --ol_dataerrflag;
222         goto ol_dataloop;
223     }
224     if ((ol_datan = ol_datarindex[ol_datastate]) && (ol_datan += ol_datachar) >= 0 &&
225             ol_datan <= ol_dataTABLESIZE && ol_datacheck[ol_datan] == ol_datachar)
226     {
227         ol_datan = ol_datatable[ol_datan];
228         goto ol_datareduce;
229     }
230     if (ol_dataerrflag) goto ol_datainrecovery;
231 // Disable for now
232 #if 0
233 #ifdef lint
234     goto ol_datanewerror;
235 #endif
236 ol_datanewerror:
237 #endif /* 0 */
238     ol_dataerror((char*)"syntax error");
239 // Disable for now
240 #if 0
241 #ifdef lint
242     goto ol_dataerrlab;
243 #endif
244 ol_dataerrlab:
245 #endif /* 0 */
246     ++ol_datanerrs;
247 ol_datainrecovery:
248     if (ol_dataerrflag < 3)
249     {
250         ol_dataerrflag = 3;
251         for (;;)
252         {
253             if ((ol_datan = ol_datasindex[*ol_datassp]) && (ol_datan += ol_dataERRCODE) >= 0 &&
254                     ol_datan <= ol_dataTABLESIZE && ol_datacheck[ol_datan] == ol_dataERRCODE)
255             {
256 #if ol_dataDEBUG
257                 if (ol_datadebug)
258                     printf("ol_datadebug: state %d, error recovery shifting\
259  to state %d\n", *ol_datassp, ol_datatable[ol_datan]);
260 #endif
261                 if (ol_datassp >= ol_datass + ol_datastacksize - 1)
262                 {
263                     goto ol_dataoverflow;
264                 }
265                 *++ol_datassp = ol_datastate = ol_datatable[ol_datan];
266                 *++ol_datavsp = ol_datalval;
267                 goto ol_dataloop;
268             }
269             else
270             {
271 #if ol_dataDEBUG
272                 if (ol_datadebug)
273                     printf("ol_datadebug: error recovery discarding state %d\n",
274                             *ol_datassp);
275 #endif
276                 if (ol_datassp <= ol_datass) goto ol_dataabort;
277                 --ol_datassp;
278                 --ol_datavsp;
279             }
280         }
281     }
282     else
283     {
284         if (ol_datachar == 0) goto ol_dataabort;
285 #if ol_dataDEBUG
286         if (ol_datadebug)
287         {
288             ol_datas = 0;
289             if (ol_datachar <= ol_dataMAXTOKEN) ol_datas = ol_dataname[ol_datachar];
290             if (!ol_datas) ol_datas = "illegal-symbol";
291             printf("ol_datadebug: state %d, error recovery discards token %d (%s)\n",
292                     ol_datastate, ol_datachar, ol_datas);
293         }
294 #endif
295         ol_datachar = (-1);
296         goto ol_dataloop;
297     }
298 ol_datareduce:
299 #if ol_dataDEBUG
300     if (ol_datadebug)
301         printf("ol_datadebug: state %d, reducing by rule %d (%s)\n",
302                 ol_datastate, ol_datan, ol_datarule[ol_datan]);
303 #endif
304     ol_datam = ol_datalen[ol_datan];
305     ol_dataval = ol_datavsp[1-ol_datam];
306     switch (ol_datan)
307     {
308 case 1:
309 #line 36 "OL_DataExpr.y"
310 {
311                 CurrentContentPtr->init(ol_datavsp[0].eptr);
312               }
313 break;
314 case 2:
315 #line 42 "OL_DataExpr.y"
316 {
317                 ol_dataval.eptr = ol_datavsp[0].eptr;
318               }
319 break;
320 case 3:
321 #line 46 "OL_DataExpr.y"
322 {
323                 ol_datavsp[-2].eptr->next = ol_datavsp[0].eptr;
324                 ol_dataval.eptr = ol_datavsp[-2].eptr;
325               }
326 break;
327 case 4:
328 #line 53 "OL_DataExpr.y"
329 {
330            OL_Expression *expr = new OL_Expression( GENERIC_ID, ol_datavsp[0].name);
331            ol_dataval.eptr = expr;
332          }
333 break;
334 case 5:
335 #line 59 "OL_DataExpr.y"
336 {
337            OL_Expression *expr = new OL_Expression( CONTENT );
338            ol_dataval.eptr = expr;
339          }
340 break;
341 case 6:
342 #line 65 "OL_DataExpr.y"
343 {
344            ExprList   *elist = new ExprList( ol_datavsp[-1].eptr );
345            OL_Expression *expr = new OL_Expression( CONCAT, -1, elist);
346            ol_dataval.eptr = expr;
347          }
348 break;
349 case 7:
350 #line 71 "OL_DataExpr.y"
351 {
352            OL_Expression *expr = new OL_Expression( REFERENCE, ol_datavsp[-1].name);
353            ol_dataval.eptr = expr;
354          }
355 break;
356 case 8:
357 #line 76 "OL_DataExpr.y"
358 {
359            ExprList *elist = new ExprList ( ol_datavsp[-1].eptr );
360            OL_Expression *expr = new OL_Expression( FIRSTOF, -1, elist );
361            ol_dataval.eptr = expr;
362          }
363 break;
364 case 9:
365 #line 83 "OL_DataExpr.y"
366 {
367            OL_Expression *expr = new OL_Expression( LITERAL, -1, ol_datavsp[0].string );
368            ol_dataval.eptr = expr;
369          }
370 break;
371 case 10:
372 #line 89 "OL_DataExpr.y"
373 {
374            OL_Expression *expr = new OL_Expression( REFERENCE, ol_datavsp[0].name );
375            ol_dataval.eptr = expr;
376          }
377 break;
378 #line 350 "y.tab.c"
379     }
380     ol_datassp -= ol_datam;
381     ol_datastate = *ol_datassp;
382     ol_datavsp -= ol_datam;
383     ol_datam = ol_datalhs[ol_datan];
384     if (ol_datastate == 0 && ol_datam == 0)
385     {
386 #if ol_dataDEBUG
387         if (ol_datadebug)
388             printf("ol_datadebug: after reduction, shifting from state 0 to\
389  state %d\n", ol_dataFINAL);
390 #endif
391         ol_datastate = ol_dataFINAL;
392         *++ol_datassp = ol_dataFINAL;
393         *++ol_datavsp = ol_dataval;
394         if (ol_datachar < 0)
395         {
396             if ((ol_datachar = ol_datalex()) < 0) ol_datachar = 0;
397 #if ol_dataDEBUG
398             if (ol_datadebug)
399             {
400                 ol_datas = 0;
401                 if (ol_datachar <= ol_dataMAXTOKEN) ol_datas = ol_dataname[ol_datachar];
402                 if (!ol_datas) ol_datas = "illegal-symbol";
403                 printf("ol_datadebug: state %d, reading %d (%s)\n",
404                         ol_dataFINAL, ol_datachar, ol_datas);
405             }
406 #endif
407         }
408         if (ol_datachar == 0) goto ol_dataaccept;
409         goto ol_dataloop;
410     }
411     if ((ol_datan = ol_datagindex[ol_datam]) && (ol_datan += ol_datastate) >= 0 &&
412             ol_datan <= ol_dataTABLESIZE && ol_datacheck[ol_datan] == ol_datastate)
413         ol_datastate = ol_datatable[ol_datan];
414     else
415         ol_datastate = ol_datadgoto[ol_datam];
416 #if ol_dataDEBUG
417     if (ol_datadebug)
418         printf("ol_datadebug: after reduction, shifting from state %d \
419 to state %d\n", *ol_datassp, ol_datastate);
420 #endif
421     if (ol_datassp >= ol_datass + ol_datastacksize - 1)
422     {
423         goto ol_dataoverflow;
424     }
425     *++ol_datassp = ol_datastate;
426     *++ol_datavsp = ol_dataval;
427     goto ol_dataloop;
428 ol_dataoverflow:
429     ol_dataerror((char*)"yacc stack overflow");
430 ol_dataabort:
431     return (1);
432 ol_dataaccept:
433     return (0);
434 }