2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 // $TOG: sheet.C /main/4 1997/12/23 11:20:35 bill $
25 static const char schemasccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
31 #include "utility/funcs.h"
32 #include "schema/store_desc.h"
33 #include "schema/index_desc.h"
34 #include "schema/inv_desc.h"
35 #include "schema/agent_desc.h"
36 #include "schema/container_desc.h"
38 extern desc* desc_ptr;
39 extern desc* last_desc_ptr;
41 #define CAST_TO_STORED_OBJECT(x) ((stored_object_desc*)x)
42 #define CAST_TO_PAGE_STORE(x) ((page_store_desc*)x)
44 #define CAST_TO_INDEX(x) ((index_desc*)x)
45 #define CAST_TO_MPHF_INDEX(x) ((index_desc*)x)
46 #define CAST_TO_SMPHF_INDEX(x) ((smphf_index_desc*)x)
48 #define CAST_TO_INV(x) ((inv_desc*)x)
50 #define CAST_TO_MPHF(x) ((mphf_desc*)x)
51 #define CAST_TO_SMPHF(x) ((smphf_desc*)x)
52 #define CAST_TO_BTREE(x) ((btree_desc*)x)
54 #define CAST_TO_CONTAINER(x) ((container_desc*)x)
57 #define alloca(x) (malloc(x))
59 extern void schemaerror(char*);
60 extern int schemalex();
69 page_store_desc* ps_trans;
75 #define INDEX_NAME 261
79 #define AGENT_NAME 265
80 #define STORE_NAME 266
83 #define MPHF_INDEX 269
84 #define SMPHF_INDEX 270
85 #define BTREE_INDEX 271
86 #define INDEX_AGENT 272
95 #define PAGE_STORE 281
100 #define CACHED_PAGES 286
102 #define BYTE_ORDER 287
103 #define SEPARATOR 288
104 #define schemaERRCODE 256
105 short schemalhs[] = { -1,
106 0, 1, 1, 2, 2, 2, 2, 2, 2, 3,
107 4, 6, 7, 5, 8, 15, 16, 16, 16, 17,
108 18, 18, 19, 19, 19, 20, 20, 9, 9, 10,
109 10, 12, 12, 13, 13, 11, 11, 14, 14, 21,
110 21, 21, 21, 25, 25, 26, 26, 22, 22, 27,
111 27, 27, 23, 23, 24, 24,
113 short schemalen[] = { 2,
114 1, 2, 1, 2, 2, 2, 2, 2, 2, 3,
115 3, 3, 3, 3, 3, 1, 1, 1, 1, 1,
116 1, 1, 1, 1, 1, 1, 1, 3, 1, 3,
117 1, 3, 1, 3, 1, 3, 1, 3, 1, 1,
118 3, 3, 3, 1, 3, 3, 3, 3, 1, 3,
121 short schemadefred[] = { 0,
122 0, 0, 0, 0, 0, 0, 0, 1, 0, 26,
123 27, 9, 0, 20, 6, 0, 21, 22, 7, 0,
124 17, 18, 19, 5, 0, 23, 25, 24, 8, 0,
125 16, 4, 0, 2, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 15, 56, 0, 54, 12, 0,
127 13, 0, 0, 0, 0, 11, 0, 52, 49, 14,
128 0, 0, 0, 0, 0, 10, 0, 40, 44, 0,
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 55, 53, 46, 47,
131 38, 32, 34, 50, 51, 48, 30, 36, 45, 43,
134 short schemadgoto[] = { 7,
135 8, 9, 32, 24, 29, 15, 19, 12, 66, 56,
136 60, 49, 51, 45, 33, 25, 16, 20, 30, 13,
137 67, 57, 46, 47, 68, 48, 59,
139 short schemasindex[] = { -250,
140 -206, -260, -221, -219, -254, -272, 0, 0, -250, 0,
141 0, 0, -277, 0, 0, -243, 0, 0, 0, -231,
142 0, 0, 0, 0, -230, 0, 0, 0, 0, -229,
143 0, 0, -228, 0, -251, -249, -249, -241, -249, -247,
144 -217, -216, -215, -214, 0, 0, -223, 0, 0, -222,
145 0, -220, -211, -209, -208, 0, -213, 0, 0, 0,
146 -212, -207, -205, -204, -201, 0, -210, 0, 0, -185,
147 -178, -177, -176, -251, -249, -249, -175, -174, -232, -241,
148 -249, -173, -194, -193, -170, -247, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152 short schemarindex[] = { 0,
153 0, 0, 0, 0, 0, 0, 0, 0, 28, 0,
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
157 0, 0, 0, 0, 0, 0, 1, 0, 0, 3,
158 0, 14, 0, 0, 0, 0, 16, 0, 0, 0,
159 27, 0, 0, 0, 0, 0, 29, 0, 0, 0,
160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
165 short schemagindex[] = { 0,
166 79, 0, 0, 0, 0, 0, 0, 0, 4, 9,
167 10, 17, 18, 19, 0, 0, 0, 0, 0, 0,
168 0, 0, -32, 0, 0, -40, 0,
170 #define schemaTABLESIZE 309
171 short schematable[] = { 69,
172 39, 14, 33, 50, 52, 58, 61, 1, 31, 41,
173 35, 2, 3, 35, 42, 31, 42, 4, 26, 27,
174 28, 5, 53, 54, 42, 55, 37, 3, 29, 6,
175 43, 44, 43, 44, 43, 44, 62, 63, 64, 65,
176 43, 44, 50, 52, 36, 69, 96, 58, 61, 21,
177 22, 23, 10, 11, 17, 18, 37, 38, 39, 40,
178 70, 71, 72, 73, 74, 75, 77, 76, 78, 79,
179 82, 87, 83, 84, 80, 81, 85, 86, 88, 89,
180 90, 94, 95, 99, 100, 101, 102, 34, 97, 103,
181 98, 92, 91, 93, 0, 0, 0, 0, 0, 0,
182 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
183 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
184 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
185 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
186 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
187 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
188 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
189 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
191 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
192 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
193 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
194 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
196 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
197 0, 0, 0, 0, 0, 0, 0, 0, 39, 0,
198 33, 0, 39, 39, 33, 33, 0, 0, 39, 0,
199 33, 35, 39, 31, 33, 35, 35, 31, 31, 0,
200 39, 35, 33, 31, 37, 35, 29, 31, 37, 37,
201 29, 29, 0, 35, 37, 31, 29, 0, 37, 0,
202 29, 0, 0, 0, 0, 0, 37, 0, 29,
204 short schemacheck[] = { 40,
205 0, 262, 0, 36, 37, 38, 39, 258, 281, 261,
206 288, 262, 263, 0, 266, 0, 266, 268, 273, 274,
207 275, 272, 264, 265, 266, 267, 0, 0, 0, 280,
208 282, 283, 282, 283, 282, 283, 284, 285, 286, 287,
209 282, 283, 75, 76, 288, 86, 279, 80, 81, 269,
210 270, 271, 259, 260, 276, 277, 288, 288, 288, 288,
211 278, 278, 278, 278, 288, 288, 278, 288, 278, 278,
212 278, 257, 278, 278, 288, 288, 278, 288, 257, 257,
213 257, 257, 257, 257, 279, 279, 257, 9, 80, 86,
214 81, 75, 74, 76, -1, -1, -1, -1, -1, -1,
215 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
216 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
217 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
218 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
219 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
220 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
221 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
222 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
223 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
224 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
227 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
228 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
229 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, -1, -1, -1, -1, -1, 258, -1,
231 258, -1, 262, 263, 262, 263, -1, -1, 268, -1,
232 268, 258, 272, 258, 272, 262, 263, 262, 263, -1,
233 280, 268, 280, 268, 258, 272, 258, 272, 262, 263,
234 262, 263, -1, 280, 268, 280, 268, -1, 272, -1,
235 272, -1, -1, -1, -1, -1, 280, -1, 280,
237 #define schemaFINAL 7
239 #define schemaDEBUG 0
241 #define schemaMAXTOKEN 288
243 char * schemaname[] = {
244 "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,
245 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
246 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
247 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
248 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
249 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
250 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"TOKEN","CONTAINER","SET","LIST",
251 "INDEX_NAME","INV","COMPRESS","INV_NAME","AGENT_NAME","STORE_NAME","POSITION",
252 "INDEX","MPHF_INDEX","SMPHF_INDEX","BTREE_INDEX","INDEX_AGENT","MPHF","SMPHF",
253 "BTREE","HUFFMAN","DICT","EQUAL","NUMBER","STORE","PAGE_STORE","NM","V_OID",
254 "MODE","PAGE_SZ","CACHED_PAGES","BYTE_ORDER","SEPARATOR",
256 char * schemarule[] = {
258 "Sheet : DescriptionList",
259 "DescriptionList : Description DescriptionList",
260 "DescriptionList : Description",
261 "Description : STORE Store_description",
262 "Description : INDEX Index_description",
263 "Description : INV Inv_description",
264 "Description : COMPRESS Compress_description",
265 "Description : INDEX_AGENT Index_Agent_description",
266 "Description : CONTAINER Container_description",
267 "Store_description : Page_Store_Head SEPARATOR Page_store_descriptions",
268 "Index_description : Index_Head SEPARATOR MPHF_index_descriptions",
269 "Inv_description : Inv_Head SEPARATOR Inv_descriptions",
270 "Compress_description : Compress_Head SEPARATOR Compress_descriptions",
271 "Index_Agent_description : Index_Agent_Head SEPARATOR Hash_descriptions",
272 "Container_description : Container_Head SEPARATOR Container_descriptions",
273 "Page_Store_Head : PAGE_STORE",
274 "Index_Head : MPHF_INDEX",
275 "Index_Head : SMPHF_INDEX",
276 "Index_Head : BTREE_INDEX",
278 "Compress_Head : HUFFMAN",
279 "Compress_Head : DICT",
280 "Index_Agent_Head : MPHF",
281 "Index_Agent_Head : BTREE",
282 "Index_Agent_Head : SMPHF",
283 "Container_Head : SET",
284 "Container_Head : LIST",
285 "Page_store_descriptions : Page_Store_Term SEPARATOR Page_store_descriptions",
286 "Page_store_descriptions : Page_Store_Term",
287 "MPHF_index_descriptions : MPHF_Index_Term SEPARATOR MPHF_index_descriptions",
288 "MPHF_index_descriptions : MPHF_Index_Term",
289 "Inv_descriptions : Stored_Object_Term SEPARATOR Inv_descriptions",
290 "Inv_descriptions : Stored_Object_Term",
291 "Compress_descriptions : Stored_Object_Term SEPARATOR Compress_descriptions",
292 "Compress_descriptions : Stored_Object_Term",
293 "Hash_descriptions : Stored_Object_Term SEPARATOR Hash_descriptions",
294 "Hash_descriptions : Stored_Object_Term",
295 "Container_descriptions : Container_Term SEPARATOR Container_descriptions",
296 "Container_descriptions : Container_Term",
297 "Page_Store_Term : Store_Term",
298 "Page_Store_Term : CACHED_PAGES EQUAL NUMBER",
299 "Page_Store_Term : BYTE_ORDER EQUAL TOKEN",
300 "Page_Store_Term : PAGE_SZ EQUAL NUMBER",
302 "Store_Term : MODE EQUAL TOKEN",
303 "Term : NM EQUAL TOKEN",
304 "Term : V_OID EQUAL TOKEN",
305 "MPHF_Index_Term : POSITION EQUAL NUMBER",
306 "MPHF_Index_Term : Index_Term",
307 "Index_Term : INV_NAME EQUAL TOKEN",
308 "Index_Term : AGENT_NAME EQUAL TOKEN",
309 "Index_Term : Stored_Object_Term",
310 "Stored_Object_Term : STORE_NAME EQUAL TOKEN",
311 "Stored_Object_Term : Term",
312 "Container_Term : INDEX_NAME EQUAL TOKEN",
313 "Container_Term : Stored_Object_Term",
316 #define schemaclearin ( schemachar=(-1))
317 #define schemaerrok ( schemaerrflag=0)
318 #ifdef schemaSTACKSIZE
319 #ifndef schemaMAXDEPTH
320 #define schemaMAXDEPTH schemaSTACKSIZE
323 #ifdef schemaMAXDEPTH
324 #define schemaSTACKSIZE schemaMAXDEPTH
326 #define schemaSTACKSIZE 500
327 #define schemaMAXDEPTH 500
335 schemaSTYPE * schemavsp;
336 schemaSTYPE schemaval;
337 schemaSTYPE schemalval;
338 short schemass[ schemaSTACKSIZE];
339 schemaSTYPE schemavs[ schemaSTACKSIZE];
340 #define schemastacksize schemaSTACKSIZE
341 #define schemaABORT goto schemaabort
342 #define schemaACCEPT goto schemaaccept
343 #define schemaERROR goto schemaerrlab
346 extern char *getenv(const char *);
352 register int schemam, scheman, schemastate;
354 register char * schemas;
356 if ( schemas = getenv(" schemaDEBUG"))
359 if ( scheman >= '0' && scheman <= '9')
360 schemadebug = scheman - '0';
368 schemassp = schemass;
369 schemavsp = schemavs;
370 * schemassp = schemastate = 0;
373 if ( (scheman = schemadefred[ schemastate])) goto schemareduce;
376 if (( schemachar = schemalex()) < 0) schemachar = 0;
381 if ( schemachar <= schemaMAXTOKEN) schemas = schemaname[ schemachar];
382 if (! schemas) schemas = "illegal-symbol";
383 printf(" schemadebug: state %d, reading %d (%s)\n", schemastate,
384 schemachar, schemas);
388 if (( scheman = schemasindex[ schemastate]) && ( scheman += schemachar) >= 0 &&
389 scheman <= schemaTABLESIZE && schemacheck[ scheman] == schemachar)
393 printf(" schemadebug: state %d, shifting to state %d\n",
394 schemastate, schematable[ scheman]);
396 if ( schemassp >= schemass + schemastacksize - 1)
400 *++ schemassp = schemastate = schematable[ scheman];
401 *++ schemavsp = schemalval;
403 if ( schemaerrflag > 0) -- schemaerrflag;
406 if (( scheman = schemarindex[ schemastate]) && ( scheman += schemachar) >= 0 &&
407 scheman <= schemaTABLESIZE && schemacheck[ scheman] == schemachar)
409 scheman = schematable[ scheman];
412 if ( schemaerrflag) goto schemainrecovery;
413 #if 0 /* remove if needed */
419 schemaerror((char*)"syntax error");
420 #if 0 /* remove if needed */
428 if ( schemaerrflag < 3)
433 if (( scheman = schemasindex[* schemassp]) && ( scheman += schemaERRCODE) >= 0 &&
434 scheman <= schemaTABLESIZE && schemacheck[ scheman] == schemaERRCODE)
438 printf(" schemadebug: state %d, error recovery shifting\
439 to state %d\n", * schemassp, schematable[ scheman]);
441 if ( schemassp >= schemass + schemastacksize - 1)
445 *++ schemassp = schemastate = schematable[ scheman];
446 *++ schemavsp = schemalval;
453 printf(" schemadebug: error recovery discarding state %d\n",
456 if ( schemassp <= schemass) goto schemaabort;
464 if ( schemachar == 0) goto schemaabort;
469 if ( schemachar <= schemaMAXTOKEN) schemas = schemaname[ schemachar];
470 if (! schemas) schemas = "illegal-symbol";
471 printf(" schemadebug: state %d, error recovery discards token %d (%s)\n",
472 schemastate, schemachar, schemas);
481 printf(" schemadebug: state %d, reducing by rule %d (%s)\n",
482 schemastate, scheman, schemarule[ scheman]);
484 schemam = schemalen[ scheman];
485 schemaval = schemavsp[1- schemam];
490 /*$1 -> asciiOutList(cerr);*/
491 desc_ptr = schemavsp[0].trans;
496 schemavsp[-1].trans -> set_next_desc( schemavsp[0].trans);
497 schemaval.trans = schemavsp[-1].trans;
502 schemavsp[0].trans -> set_next_desc(0);
503 last_desc_ptr = schemavsp[0].trans;
504 schemaval.trans = schemavsp[0].trans;
509 schemaval.trans = schemavsp[0].trans;
514 schemaval.trans = schemavsp[0].trans;
519 schemaval.trans = schemavsp[0].trans;
524 schemaval.trans = schemavsp[0].trans;
529 schemaval.trans = schemavsp[0].trans;
534 schemaval.trans = schemavsp[0].trans;
539 schemaval.trans = desc_ptr;
544 schemaval.trans = desc_ptr;
549 schemaval.trans = desc_ptr;
554 schemaval.trans = desc_ptr;
559 schemaval.trans = desc_ptr;
564 schemaval.trans = desc_ptr;
569 desc_ptr = new page_store_desc;
574 desc_ptr= new mphf_index_desc;
579 desc_ptr= new smphf_index_desc;
584 desc_ptr= new btree_index_desc;
589 desc_ptr= new inv_desc;
594 desc_ptr= new huffman_desc;
599 desc_ptr= new dict_desc;
604 desc_ptr= new mphf_desc;
609 desc_ptr= new btree_desc;
614 desc_ptr= new smphf_desc;
619 desc_ptr= new set_desc;
624 desc_ptr= new list_desc;
681 CAST_TO_PAGE_STORE(desc_ptr) -> set_cached_pages( schemavsp[0].integer);
686 CAST_TO_PAGE_STORE(desc_ptr) -> set_order( schemavsp[0].string);
691 CAST_TO_PAGE_STORE(desc_ptr) -> set_page_sz( schemavsp[0].integer);
700 CAST_TO_PAGE_STORE(desc_ptr) -> set_mode( schemavsp[0].string);
705 desc_ptr -> set_nm( schemavsp[0].string);
710 desc_ptr -> set_oid( schemavsp[0].string);
715 CAST_TO_MPHF_INDEX(desc_ptr) -> set_position( schemavsp[0].integer);
724 CAST_TO_INDEX(desc_ptr) -> set_inv_nm( schemavsp[0].string);
729 CAST_TO_INDEX(desc_ptr) -> set_agent_nm( schemavsp[0].string);
738 CAST_TO_STORED_OBJECT(desc_ptr) -> set_store_nm( schemavsp[0].string);
747 CAST_TO_CONTAINER(desc_ptr) -> set_index_nm( schemavsp[0].string);
755 schemassp -= schemam;
756 schemastate = * schemassp;
757 schemavsp -= schemam;
758 schemam = schemalhs[ scheman];
759 if ( schemastate == 0 && schemam == 0)
763 printf(" schemadebug: after reduction, shifting from state 0 to\
764 state %d\n", schemaFINAL);
766 schemastate = schemaFINAL;
767 *++ schemassp = schemaFINAL;
768 *++ schemavsp = schemaval;
771 if (( schemachar = schemalex()) < 0) schemachar = 0;
776 if ( schemachar <= schemaMAXTOKEN) schemas = schemaname[ schemachar];
777 if (! schemas) schemas = "illegal-symbol";
778 printf(" schemadebug: state %d, reading %d (%s)\n",
779 schemaFINAL, schemachar, schemas);
783 if ( schemachar == 0) goto schemaaccept;
786 if (( scheman = schemagindex[ schemam]) && ( scheman += schemastate) >= 0 &&
787 scheman <= schemaTABLESIZE && schemacheck[ scheman] == schemastate)
788 schemastate = schematable[ scheman];
790 schemastate = schemadgoto[ schemam];
793 printf(" schemadebug: after reduction, shifting from state %d \
794 to state %d\n", * schemassp, schemastate);
796 if ( schemassp >= schemass + schemastacksize - 1)
800 *++ schemassp = schemastate;
801 *++ schemavsp = schemaval;
804 schemaerror((char*)"yacc stack overflow");