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: style.C /main/6 1998/04/17 11:51:49 mgreess $
25 __attribute__((unused))
26 static const char stylesccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
35 #include "StyleSheetExceptions.h"
36 #include "VariableTable.h"
37 #include "FeatureValue.h"
38 #include "Expression.h"
40 #include "PathTable.h"
42 #include "PathQualifier.h"
44 #include "ParserConst.h"
45 #include "FeatureDefDictionary.h"
46 #include <utility/funcs.h>
48 #include "HardCopy/autoNumberFP.h"
49 extern autoNumberFP gAutoNumberFP;
55 #define alloca(x) (malloc(x))
57 extern void styleerror(char*);
58 extern int stylelex();
60 extern void enter_sgmlgi_context();
62 extern featureDefDictionary* g_FeatureDefDictionary;
63 extern unsigned g_validation_mode;
64 extern unsigned g_hasSemanticError;
66 static char localCharToCharPtrBuf[2];
70 const char* toUpperCase(unsigned char* string)
72 static char buffer[512];
74 for ( unsigned int i=0; i<strlen((const char*)string); i++ )
76 if (islower(string[i]))
77 buffer[j] = toupper(string[i]) ;
79 buffer[j] = (char)string[i] ;
88 unsigned char charData;
89 unsigned char* charPtrData;
90 unsigned int boolData;
93 Expression* expPtrData;
94 TermNode* termNodePtrData;
95 FeatureValue* FeatureValuePtrData;
96 FeatureSet* FeatureSetPtrData;
97 Feature* FeaturePtrData;
99 PathTerm* PathTermPtrData;
100 charPtrDlist* charPtrDlistData;
101 PathFeatureList* PathFeatureListPtrData;
102 CompositeVariableNode* CompositeVariableNodePtrData;
104 CC_TPtrSlist<FeatureValue>* FeatureValueSlistPtrData;
106 PQExpr* PQExprPtrData;
109 #define OPER_equality 258
110 #define OPER_relational 259
113 #define OPER_assign 262
114 #define ARRAYOPEN 263
115 #define ARRAYCLOSE 264
116 #define SEPARATOR 265
119 #define OPER_modify 268
120 #define OPER_parent 269
121 #define OPER_attr 270
122 #define OPER_oneof 271
123 #define OPER_star 272
127 #define OPER_parenopen 276
128 #define OPER_parenclose 277
129 #define OPER_logicalnegate 278
131 #define PMEMCLOSE 280
132 #define OPER_period 281
133 #define OPER_plus 282
134 #define OPER_minus 283
135 #define DIMENSION 284
136 #define NORMAL_STRING 285
137 #define UNIT_STRING 286
138 #define QUOTED_STRING 287
139 #define GI_CASE_SENSITIVE 288
140 #define SGMLGI_STRING 289
141 #define styleERRCODE 256
142 short stylelhs[] = { -1,
143 0, 37, 38, 38, 39, 13, 13, 13, 22, 22,
144 14, 15, 19, 19, 19, 11, 11, 10, 10, 7,
145 7, 6, 6, 12, 12, 12, 12, 12, 12, 12,
146 12, 12, 12, 20, 20, 4, 4, 23, 23, 21,
147 21, 17, 17, 18, 18, 40, 40, 24, 29, 29,
148 28, 28, 27, 27, 25, 25, 26, 26, 26, 9,
149 8, 8, 2, 41, 5, 5, 5, 16, 3, 3,
150 34, 30, 30, 31, 31, 32, 32, 1, 1, 35,
151 35, 36, 36, 42, 42, 33, 33,
153 short stylelen[] = { 2,
154 2, 3, 1, 1, 3, 1, 2, 1, 3, 1,
155 2, 2, 1, 1, 1, 3, 1, 3, 1, 1,
156 1, 1, 1, 1, 2, 1, 1, 1, 2, 2,
157 1, 1, 3, 4, 3, 1, 0, 3, 1, 1,
158 1, 4, 2, 3, 1, 1, 0, 3, 3, 1,
159 2, 4, 3, 1, 2, 1, 2, 1, 1, 1,
160 1, 1, 1, 0, 4, 2, 1, 1, 1, 1,
161 3, 1, 3, 1, 3, 4, 3, 1, 1, 1,
164 short styledefred[] = { 0,
165 0, 0, 0, 80, 0, 58, 59, 69, 70, 0,
166 0, 63, 0, 56, 4, 1, 85, 3, 0, 2,
167 0, 57, 86, 0, 0, 0, 0, 0, 51, 55,
168 84, 0, 0, 0, 0, 74, 0, 24, 0, 0,
169 0, 0, 68, 28, 0, 0, 0, 0, 19, 0,
170 0, 6, 27, 15, 5, 14, 0, 0, 43, 50,
171 0, 45, 0, 0, 54, 0, 0, 71, 0, 0,
172 29, 30, 11, 12, 10, 0, 0, 22, 23, 0,
173 61, 62, 0, 25, 0, 60, 0, 65, 0, 0,
174 0, 0, 0, 52, 0, 78, 79, 77, 0, 75,
175 33, 35, 0, 41, 0, 0, 18, 0, 9, 44,
176 42, 48, 49, 53, 76, 0, 34, 38,
178 short styledgoto[] = { 2,
179 98, 10, 28, 46, 12, 80, 0, 83, 87, 47,
180 48, 49, 50, 51, 52, 53, 54, 61, 55, 56,
181 105, 57, 106, 62, 13, 14, 64, 15, 63, 34,
182 35, 36, 22, 23, 3, 16, 4, 17, 18, 90,
185 short stylesindex[] = { -277,
186 -246, 0, -225, 0, -218, 0, 0, 0, 0, -231,
187 -228, 0, -259, 0, 0, 0, 0, 0, -225, 0,
188 -265, 0, 0, -221, 0, -234, -225, -222, 0, 0,
189 0, -229, -196, -206, -204, 0, -213, 0, -187, -229,
190 -229, -168, 0, 0, 0, -156, -251, -177, 0, -172,
191 -229, 0, 0, 0, 0, 0, -161, -167, 0, 0,
192 -141, 0, -237, -255, 0, -133, -249, 0, -265, -265,
193 0, 0, 0, 0, 0, -199, -189, 0, 0, -168,
194 0, 0, -168, 0, -161, 0, -229, 0, -229, -139,
195 -221, -229, -225, 0, -158, 0, 0, 0, -204, 0,
196 0, 0, -177, 0, -132, -130, 0, -251, 0, 0,
197 0, 0, 0, 0, 0, -168, 0, 0,
199 short stylerindex[] = { 37,
200 0, 0, 132, 0, 0, 0, 0, 0, 0, -145,
201 -257, 0, 0, 0, 0, 0, 0, 0, 135, 0,
202 0, 0, 0, -127, 1, 0, 0, 30, 0, 0,
203 0, 0, 0, 0, -179, 0, 169, 0, 178, 0,
204 0, 0, 0, 0, 54, 0, 123, 130, 0, 200,
205 0, 0, 0, 0, 0, 0, 77, 0, 0, 0,
206 -129, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, -127, 0, 0, 0,
208 0, 0, 0, 0, 100, 0, 0, 0, -128, 0,
209 -127, 0, 0, 0, 0, 0, 0, 0, -160, 0,
210 0, 0, -155, 0, -122, 0, 0, 146, 0, 0,
211 0, 0, 0, 0, 0, -127, 0, 0,
213 short stylegindex[] = { 0,
214 0, 71, -1, 0, 0, 0, 0, 0, 74, 60,
215 -42, 64, 0, 0, 0, 0, 134, 0, 57, -73,
216 0, 94, 33, 61, 0, 138, 0, -24, 0, 0,
217 83, 84, 0, 0, 0, 0, 0, 136, 0, 0,
220 #define styleTABLESIZE 485
221 short styletable[] = { 76,
222 66, 11, 65, 104, 32, 67, 26, 96, 67, 93,
223 1, 6, 7, 67, 67, 5, 27, 11, 67, 33,
224 78, 94, 45, 79, 60, 8, 9, 67, 67, 67,
225 91, 21, 59, 24, 103, 37, 81, 97, 38, 39,
226 75, 20, 104, 86, 26, 6, 7, 40, 41, 75,
227 8, 9, 25, 10, 42, 8, 9, 68, 25, 8,
228 9, 67, 43, 8, 9, 44, 69, 37, 114, 70,
229 38, 39, 71, 103, 102, 45, 8, 101, 75, 40,
230 41, 75, 81, 82, 72, 109, 42, 60, 37, 45,
231 113, 38, 39, 72, 43, 8, 9, 44, 72, 7,
232 40, 41, 66, 73, 81, 82, 77, 42, 40, 40,
233 73, 74, 73, 84, 45, 43, 8, 9, 44, 86,
234 87, 88, 17, 89, 95, 87, 87, 111, 115, 13,
235 87, 83, 116, 117, 82, 37, 92, 47, 46, 87,
236 87, 39, 108, 107, 85, 16, 29, 112, 118, 110,
237 30, 99, 0, 100, 31, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0, 31, 0,
239 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 26,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0, 0, 0, 0, 66, 0,
248 0, 0, 0, 66, 66, 66, 66, 66, 0, 0,
249 0, 66, 66, 0, 0, 66, 66, 66, 0, 0,
250 0, 0, 66, 66, 0, 66, 66, 67, 0, 64,
251 0, 0, 67, 67, 67, 67, 67, 0, 0, 0,
252 67, 67, 0, 0, 67, 67, 67, 81, 81, 0,
253 0, 67, 67, 0, 67, 67, 36, 10, 10, 0,
254 10, 81, 81, 0, 10, 10, 0, 0, 10, 0,
255 0, 0, 0, 0, 10, 10, 10, 0, 10, 10,
256 8, 8, 0, 8, 0, 0, 0, 8, 8, 0,
257 0, 8, 0, 8, 0, 0, 0, 0, 8, 8,
258 0, 8, 8, 7, 7, 0, 7, 0, 0, 0,
259 7, 7, 0, 0, 7, 0, 7, 0, 0, 0,
260 0, 7, 7, 0, 7, 7, 17, 17, 0, 17,
261 0, 0, 0, 17, 13, 0, 13, 0, 0, 17,
262 13, 13, 0, 0, 17, 17, 0, 17, 17, 16,
263 16, 0, 16, 0, 13, 13, 16, 0, 0, 0,
264 0, 0, 16, 0, 0, 0, 0, 16, 16, 0,
265 16, 16, 31, 31, 0, 31, 0, 0, 0, 31,
266 31, 32, 32, 31, 32, 31, 0, 0, 32, 32,
267 31, 31, 32, 31, 32, 0, 0, 0, 0, 32,
268 32, 0, 32, 26, 26, 0, 26, 0, 0, 0,
269 26, 26, 0, 0, 26, 0, 26, 0, 0, 0,
272 short stylecheck[] = { 42,
273 0, 3, 27, 77, 270, 263, 266, 257, 266, 265,
274 288, 271, 272, 271, 272, 262, 276, 19, 276, 285,
275 272, 277, 24, 275, 26, 285, 286, 285, 286, 0,
276 268, 263, 267, 262, 77, 257, 0, 287, 260, 261,
277 42, 260, 116, 281, 266, 271, 272, 269, 270, 51,
278 285, 286, 281, 0, 276, 285, 286, 264, 281, 285,
279 286, 258, 284, 285, 286, 287, 273, 257, 93, 274,
280 260, 261, 286, 116, 264, 77, 0, 277, 80, 269,
281 270, 83, 282, 283, 264, 87, 276, 89, 257, 91,
282 92, 260, 261, 273, 284, 285, 286, 287, 286, 0,
283 269, 270, 32, 264, 282, 283, 263, 276, 264, 265,
284 40, 41, 273, 286, 116, 284, 285, 286, 287, 281,
285 266, 289, 0, 265, 258, 271, 272, 267, 287, 0,
286 276, 0, 265, 264, 0, 263, 63, 267, 267, 285,
287 286, 264, 83, 80, 51, 0, 13, 91, 116, 89,
288 13, 69, -1, 70, 19, -1, -1, -1, -1, -1,
289 -1, -1, -1, -1, -1, -1, -1, -1, 0, -1,
290 -1, -1, -1, -1, -1, -1, -1, 0, -1, -1,
291 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
292 -1, -1, -1, -1, -1, -1, -1, -1, -1, 0,
293 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
294 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
295 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
296 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
297 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
298 -1, -1, -1, -1, -1, -1, -1, -1, 258, -1,
299 -1, -1, -1, 263, 264, 265, 266, 267, -1, -1,
300 -1, 271, 272, -1, -1, 275, 276, 277, -1, -1,
301 -1, -1, 282, 283, -1, 285, 286, 258, -1, 289,
302 -1, -1, 263, 264, 265, 266, 267, -1, -1, -1,
303 271, 272, -1, -1, 275, 276, 277, 271, 272, -1,
304 -1, 282, 283, -1, 285, 286, 263, 264, 265, -1,
305 267, 285, 286, -1, 271, 272, -1, -1, 275, -1,
306 -1, -1, -1, -1, 281, 282, 283, -1, 285, 286,
307 264, 265, -1, 267, -1, -1, -1, 271, 272, -1,
308 -1, 275, -1, 277, -1, -1, -1, -1, 282, 283,
309 -1, 285, 286, 264, 265, -1, 267, -1, -1, -1,
310 271, 272, -1, -1, 275, -1, 277, -1, -1, -1,
311 -1, 282, 283, -1, 285, 286, 264, 265, -1, 267,
312 -1, -1, -1, 271, 265, -1, 267, -1, -1, 277,
313 271, 272, -1, -1, 282, 283, -1, 285, 286, 264,
314 265, -1, 267, -1, 285, 286, 271, -1, -1, -1,
315 -1, -1, 277, -1, -1, -1, -1, 282, 283, -1,
316 285, 286, 264, 265, -1, 267, -1, -1, -1, 271,
317 272, 264, 265, 275, 267, 277, -1, -1, 271, 272,
318 282, 283, 275, 285, 277, -1, -1, -1, -1, 282,
319 283, -1, 285, 264, 265, -1, 267, -1, -1, -1,
320 271, 272, -1, -1, 275, -1, 277, -1, -1, -1,
321 -1, 282, 283, -1, 285,
327 #define styleMAXTOKEN 289
329 char *stylename[] = {
330 "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,
331 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
332 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
333 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
334 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
335 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
336 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"INTEGER","OPER_equality",
337 "OPER_relational","BOOLVAL","REAL","OPER_assign","ARRAYOPEN","ARRAYCLOSE",
338 "SEPARATOR","FSOPEN","FSCLOSE","OPER_modify","OPER_parent","OPER_attr",
339 "OPER_oneof","OPER_star","OPER_or","OPER_and","OPER_div","OPER_parenopen",
340 "OPER_parenclose","OPER_logicalnegate","PMEMOPEN","PMEMCLOSE","OPER_period",
341 "OPER_plus","OPER_minus","DIMENSION","NORMAL_STRING","UNIT_STRING",
342 "QUOTED_STRING","GI_CASE_SENSITIVE","SGMLGI_STRING",
344 char *stylerule[] = {
345 "$accept : stylesheet",
346 "stylesheet : sensitivityOPTL statement.gpOPTL",
347 "sensitivity : GI_CASE_SENSITIVE OPER_assign BOOLVAL",
348 "statement.gp : var_assignment",
349 "statement.gp : path_expr",
350 "var_assignment : STRING OPER_assign rhs.gp",
352 "symbol : parent string_list",
353 "symbol : string_list",
354 "string_list : string_list OPER_feature STRING",
355 "string_list : STRING",
356 "parent : OPER_parent SGMLGI",
357 "attr : OPER_attr SGMLGI",
358 "rhs.gp : simple_expr",
360 "rhs.gp : featureset",
361 "simple_expr : simple_expr OPER_add multi_expr",
362 "simple_expr : multi_expr",
363 "multi_expr : multi_expr OPER_mult term",
365 "OPER_binop : OPER_mult",
366 "OPER_binop : OPER_add",
367 "OPER_mult : OPER_star",
368 "OPER_mult : OPER_div",
370 "term : symbol UNIT_STRING",
373 "term : QUOTED_STRING",
374 "term : INTEGER UNIT_STRING",
375 "term : REAL UNIT_STRING",
378 "term : OPER_parenopen simple_expr OPER_parenclose",
379 "array : array_name ARRAYOPEN array_member_list ARRAYCLOSE",
380 "array : array_name ARRAYOPEN ARRAYCLOSE",
381 "array_name : STRING",
383 "array_member_list : array_member SEPARATOR array_member_list",
384 "array_member_list : array_member",
385 "array_member : simple_expr",
386 "array_member : array",
387 "featureset : FSOPEN feature_list SEPARATOR_OPTL FSCLOSE",
388 "featureset : FSOPEN FSCLOSE",
389 "feature_list : feature_list SEPARATOR feature",
390 "feature_list : feature",
391 "SEPARATOR_OPTL : SEPARATOR",
393 "feature : feature_name_list OPER_modify rhs.gp",
394 "feature_name_list : feature_name_list OPER_feature STRING",
395 "feature_name_list : STRING",
396 "path_expr : path_term_list featureset",
397 "path_expr : path_term_list OPER_parenopen path_expr_list OPER_parenclose",
398 "path_expr_list : path_expr_list SEPARATOR path_expr",
399 "path_expr_list : path_expr",
400 "path_term_list : path_term_list path_term",
401 "path_term_list : path_term",
402 "path_term : SGMLGI path_selectorOPTL",
403 "path_term : OPER_oneof",
404 "path_term : OPER_star",
405 "OPER_feature : OPER_period",
406 "OPER_add : OPER_plus",
407 "OPER_add : OPER_minus",
408 "SGMLGI : SGMLGI_CONTENT",
410 "SGMLGI_CONTENT : STRING OPER_period $$1 SGMLGI_STRING",
411 "SGMLGI_CONTENT : STRING OPER_period",
412 "SGMLGI_CONTENT : STRING",
413 "dimension : DIMENSION",
414 "STRING : NORMAL_STRING",
415 "STRING : UNIT_STRING",
416 "path_selector : ARRAYOPEN boolean_expr ARRAYCLOSE",
417 "boolean_expr : logical_and_expr",
418 "boolean_expr : boolean_expr OPER_or logical_and_expr",
419 "logical_and_expr : equality_expr",
420 "logical_and_expr : logical_and_expr OPER_and equality_expr",
421 "equality_expr : OPER_attr SGMLGI OPER_equality QUOTED_STRING",
422 "equality_expr : NORMAL_STRING OPER_equality POSITION_VALUE",
423 "POSITION_VALUE : INTEGER",
424 "POSITION_VALUE : QUOTED_STRING",
425 "sensitivityOPTL : sensitivity",
427 "statement.gpOPTL : statement.gpPLUS",
428 "statement.gpOPTL :",
429 "statement.gpPLUS : statement.gpPLUS statement.gp",
430 "statement.gpPLUS : statement.gp",
431 "path_selectorOPTL : path_selector",
432 "path_selectorOPTL :",
435 #define styleclearin (stylechar=(-1))
436 #define styleerrok (styleerrflag=0)
437 #ifdef styleSTACKSIZE
438 #ifndef styleMAXDEPTH
439 #define styleMAXDEPTH styleSTACKSIZE
443 #define styleSTACKSIZE styleMAXDEPTH
445 #define styleSTACKSIZE 500
446 #define styleMAXDEPTH 500
454 styleSTYPE *stylevsp;
456 styleSTYPE stylelval;
457 short styless[styleSTACKSIZE];
458 styleSTYPE stylevs[styleSTACKSIZE];
459 #define stylestacksize styleSTACKSIZE
460 #define styleABORT goto styleabort
461 #define styleACCEPT goto styleaccept
462 #define styleERROR goto styleerrlab
465 extern char *getenv(const char *);
471 register int stylem, stylen, stylestate;
473 register char *styles;
475 if (styles = getenv("styleDEBUG"))
478 if (stylen >= '0' && stylen <= '9')
479 styledebug = stylen - '0';
489 *stylessp = stylestate = 0;
492 if ((stylen = styledefred[stylestate])) goto stylereduce;
495 if ((stylechar = stylelex()) < 0) stylechar = 0;
500 if (stylechar <= styleMAXTOKEN) styles = stylename[stylechar];
501 if (!styles) styles = "illegal-symbol";
502 printf("styledebug: state %d, reading %d (%s)\n", stylestate,
507 if ((stylen = stylesindex[stylestate]) && (stylen += stylechar) >= 0 &&
508 stylen <= styleTABLESIZE && stylecheck[stylen] == stylechar)
512 printf("styledebug: state %d, shifting to state %d\n",
513 stylestate, styletable[stylen]);
515 if (stylessp >= styless + stylestacksize - 1)
519 *++stylessp = stylestate = styletable[stylen];
520 *++stylevsp = stylelval;
522 if (styleerrflag > 0) --styleerrflag;
525 if ((stylen = stylerindex[stylestate]) && (stylen += stylechar) >= 0 &&
526 stylen <= styleTABLESIZE && stylecheck[stylen] == stylechar)
528 stylen = styletable[stylen];
531 if (styleerrflag) goto styleinrecovery;
532 #if 0 /* remove if needed */
538 styleerror((char*)"syntax error");
539 #if 0 /* remove if needed */
547 if (styleerrflag < 3)
552 if ((stylen = stylesindex[*stylessp]) && (stylen += styleERRCODE) >= 0 &&
553 stylen <= styleTABLESIZE && stylecheck[stylen] == styleERRCODE)
557 printf("styledebug: state %d, error recovery shifting\
558 to state %d\n", *stylessp, styletable[stylen]);
560 if (stylessp >= styless + stylestacksize - 1)
564 *++stylessp = stylestate = styletable[stylen];
565 *++stylevsp = stylelval;
572 printf("styledebug: error recovery discarding state %d\n",
575 if (stylessp <= styless) goto styleabort;
583 if (stylechar == 0) goto styleabort;
588 if (stylechar <= styleMAXTOKEN) styles = stylename[stylechar];
589 if (!styles) styles = "illegal-symbol";
590 printf("styledebug: state %d, error recovery discards token %d (%s)\n",
591 stylestate, stylechar, styles);
600 printf("styledebug: state %d, reducing by rule %d (%s)\n",
601 stylestate, stylen, stylerule[stylen]);
603 stylem = stylelen[stylen];
604 styleval = stylevsp[1-stylem];
613 gGI_CASE_SENSITIVE = stylevsp[0].boolData;
622 /* copy items form the feature list into the path table */
623 PathFeatureListIterator l_Iter(*(stylevsp[0].PathFeatureListPtrData));
631 if ( g_validation_mode == true )
632 if ( g_FeatureDefDictionary -> checkSemantics(x -> featureSet()) == false )
633 g_hasSemanticError = true;
635 gPathTab -> addPathFeatureSet( x );
640 /* clear out the first list so the elements are not deleted
641 with the list because they are still referenced by the
644 stylevsp[0].PathFeatureListPtrData -> clear();
645 delete stylevsp[0].PathFeatureListPtrData;
651 Expression *x = new Expression(new ConstantNode(stylevsp[0].FeatureValuePtrData));
653 if ( gAutoNumberFP.accept((const char*)stylevsp[-2].charPtrData, x) ) {
654 delete stylevsp[-2].charPtrData;
659 gVariableTable -> enter( gSymTab -> intern((const char*)stylevsp[-2].charPtrData), x);
660 delete stylevsp[-2].charPtrData;
665 styleval.termNodePtrData=stylevsp[0].termNodePtrData;
670 styleval.termNodePtrData=stylevsp[-1].termNodePtrData;
675 const Symbol* x = stylevsp[0].CompositeVariableNodePtrData -> convertableToVariable();
677 styleval.termNodePtrData=new VariableNode(*x);
678 delete stylevsp[0].CompositeVariableNodePtrData;
680 styleval.termNodePtrData=stylevsp[0].CompositeVariableNodePtrData;
686 stylevsp[-2].CompositeVariableNodePtrData->appendItem(gSymTab->intern(toUpperCase(stylevsp[0].charPtrData)));
687 styleval.CompositeVariableNodePtrData=stylevsp[-2].CompositeVariableNodePtrData;
688 delete stylevsp[0].charPtrData ;
693 styleval.CompositeVariableNodePtrData=new CompositeVariableNode;
694 styleval.CompositeVariableNodePtrData -> appendItem(gSymTab->intern(toUpperCase(stylevsp[0].charPtrData)));
695 delete stylevsp[0].charPtrData;
702 ParentNode(gSymTab->intern((const char*)$1));
704 MESSAGE(cerr, "^ operator not supported.");
705 throw(CASTSSEXCEPT StyleSheetException());
710 styleval.termNodePtrData=new
711 SgmlAttributeNode(gSymTab->intern((const char*)stylevsp[0].charPtrData));
712 delete stylevsp[0].charPtrData;
717 styleval.FeatureValuePtrData=new FeatureValueExpression(stylevsp[0].expPtrData);
722 styleval.FeatureValuePtrData=stylevsp[0].FeatureValuePtrData;
727 styleval.FeatureValuePtrData=new FeatureValueFeatureSet(stylevsp[0].FeatureSetPtrData);
732 BinaryOperatorNode::operatorType opType;
733 switch (stylevsp[-1].charData) {
734 case '+': opType=BinaryOperatorNode::PLUS; break;
735 case '-': opType=BinaryOperatorNode::MINUS; break;
737 throw(CASTBEEXCEPT badEvaluationException());
740 FeatureValueExpression* FVexprL = new FeatureValueExpression(stylevsp[-2].expPtrData);
741 FeatureValueExpression* FVexprR = new FeatureValueExpression(stylevsp[0].expPtrData);
743 styleval.expPtrData = new Expression(
744 new BinaryOperatorNode(opType,
745 new ConstantNode(FVexprL),
746 new ConstantNode(FVexprR)
753 styleval.expPtrData=stylevsp[0].expPtrData;
758 BinaryOperatorNode::operatorType opType;
759 switch (stylevsp[-1].charData) {
760 case '*': opType=BinaryOperatorNode::TIMES; break;
761 case '/': opType=BinaryOperatorNode::DIVIDE; break;
763 throw(CASTBEEXCEPT badEvaluationException());
766 FeatureValueExpression* FVexpr = new FeatureValueExpression(stylevsp[-2].expPtrData);
768 styleval.expPtrData = new Expression(
769 new BinaryOperatorNode(opType, new ConstantNode(FVexpr), stylevsp[0].termNodePtrData)
775 styleval.expPtrData = new Expression(stylevsp[0].termNodePtrData);
780 styleval.charData=stylevsp[0].charData;
785 styleval.charData=stylevsp[0].charData;
790 styleval.charData=stylevsp[0].charData;
795 styleval.charData=stylevsp[0].charData;
800 styleval.termNodePtrData=new ConstantNode(new FeatureValueInt(int(stylevsp[0].boolData)));
805 FeatureValueExpression* fve =
806 new FeatureValueExpression(new Expression(stylevsp[-1].termNodePtrData));
807 FeatureValueDimension* x =
808 new FeatureValueDimension(fve, (const char*)stylevsp[0].charPtrData);
809 delete stylevsp[0].charPtrData ;
810 styleval.termNodePtrData=new ConstantNode(x);
815 styleval.termNodePtrData=stylevsp[0].termNodePtrData;
820 styleval.termNodePtrData=stylevsp[0].termNodePtrData;
825 styleval.termNodePtrData=new ConstantNode(new FeatureValueString((const char*)stylevsp[0].charPtrData));
826 delete stylevsp[0].charPtrData ;
831 styleval.termNodePtrData=new ConstantNode(new FeatureValueDimension(new FeatureValueInt(stylevsp[-1].intData), (const char*)stylevsp[0].charPtrData));
832 delete stylevsp[0].charPtrData ;
837 styleval.termNodePtrData=new ConstantNode(new FeatureValueDimension(new FeatureValueReal(stylevsp[-1].realData), (const char*)stylevsp[0].charPtrData));
838 delete stylevsp[0].charPtrData ;
843 styleval.termNodePtrData=new ConstantNode(new FeatureValueInt(stylevsp[0].intData));
848 styleval.termNodePtrData=new ConstantNode(new FeatureValueReal(stylevsp[0].realData));
853 styleval.termNodePtrData=new ConstantNode(new FeatureValueExpression(stylevsp[-1].expPtrData));
858 FeatureValueArray* x =
859 new FeatureValueArray((const char*)stylevsp[-3].charPtrData, stylevsp[-1].FeatureValueSlistPtrData -> entries());
860 CC_TPtrSlistIterator<FeatureValue> iter(*stylevsp[-1].FeatureValueSlistPtrData);
864 (*x)[i++] = iter.key();
867 delete stylevsp[-3].charPtrData;
868 delete stylevsp[-1].FeatureValueSlistPtrData;
870 styleval.FeatureValuePtrData = x;
875 styleval.FeatureValuePtrData = new FeatureValueArray((const char*)stylevsp[-2].charPtrData, 0);
876 delete stylevsp[-2].charPtrData;
881 styleval.charPtrData = stylevsp[0].charPtrData;
886 styleval.charPtrData = new unsigned char[1];
887 styleval.charPtrData[0] = 0;
892 stylevsp[0].FeatureValueSlistPtrData -> prepend(stylevsp[-2].FeatureValuePtrData);
893 styleval.FeatureValueSlistPtrData = stylevsp[0].FeatureValueSlistPtrData;
898 styleval.FeatureValueSlistPtrData=new CC_TPtrSlist<FeatureValue>;
899 styleval.FeatureValueSlistPtrData -> append(stylevsp[0].FeatureValuePtrData);
904 styleval.FeatureValuePtrData = new FeatureValueExpression(stylevsp[0].expPtrData);
909 styleval.FeatureValuePtrData=stylevsp[0].FeatureValuePtrData;
914 styleval.FeatureSetPtrData=stylevsp[-2].FeatureSetPtrData;
919 styleval.FeatureSetPtrData = new FeatureSet ();
924 if (stylevsp[0].FeaturePtrData -> name() == Symbol(gSymTab->intern("FAMILY"))) {
925 /* the evaluate() call clones $3 */
926 FeatureValueFeatureSet *fvfs =
927 (FeatureValueFeatureSet*) stylevsp[0].FeaturePtrData->evaluate();
928 const FeatureSet* fs = fvfs->value();
929 const Feature* charsetF =
930 fs->lookup(gSymTab->intern("CHARSET"));
931 /* charsetF is a mandatory entry in fontfamily*/
933 const FeatureValueString* fv_string =
934 (FeatureValueString*)charsetF->value();
935 const char* charset = *fv_string;
938 int entries = stylevsp[-2].FeatureSetPtrData -> entries();
939 for (int i=0; i<entries; i++) {
940 const Feature* entry = stylevsp[-2].FeatureSetPtrData->at(i);
941 if (! (entry->name() == Symbol(gSymTab->intern("FAMILY"))))
943 const FeatureSet* entry_fs =
944 ((FeatureValueFeatureSet*)(entry->evaluate()))->value();
945 const Feature* entry_charsetF =
946 entry_fs->lookup(gSymTab->intern("CHARSET"));
947 assert( entry_charsetF );
948 const char* entry_charset =
949 *((FeatureValueString*)(entry_charsetF->value()));
950 assert( entry_charset );
951 if (! strcmp(charset, entry_charset)) {
952 delete stylevsp[-2].FeatureSetPtrData -> removeAt(i);
953 break; /* escape from for-loop*/
958 styleval.FeatureSetPtrData = stylevsp[-2].FeatureSetPtrData;
959 styleval.FeatureSetPtrData -> add(stylevsp[0].FeaturePtrData);
962 if ( stylevsp[-2].FeatureSetPtrData -> find((Feature*)stylevsp[0].FeaturePtrData) ) {
963 FeatureSet* fs = new FeatureSet();
964 fs -> add(stylevsp[0].FeaturePtrData);
966 styleval.FeatureSetPtrData =new FeatureSet(*stylevsp[-2].FeatureSetPtrData, *fs);
967 delete stylevsp[-2].FeatureSetPtrData;
971 styleval.FeatureSetPtrData=stylevsp[-2].FeatureSetPtrData;
972 styleval.FeatureSetPtrData -> add(stylevsp[0].FeaturePtrData);
979 styleval.FeatureSetPtrData=new FeatureSet();
980 styleval.FeatureSetPtrData -> add(stylevsp[0].FeaturePtrData);
993 CC_TPtrDlistIterator<char> l_Iter(*(stylevsp[-2].charPtrDlistData));
997 FeatureValue *fv = stylevsp[0].FeatureValuePtrData;
998 const char* cptr = 0;
1001 cptr = l_Iter.key();
1003 const char *c = cptr ;
1007 buffer[index] = toupper(*c) ;
1009 buffer[index] = *c ;
1014 /* fprintf(stderr, "converted: %s to %s\n", cptr, buffer); */
1015 f = new Feature(gSymTab -> intern(buffer), fv);
1017 if ( stylevsp[-2].charPtrDlistData -> last() != cptr ) {
1018 fs = new FeatureSet();
1020 fv = new FeatureValueFeatureSet(fs);
1024 stylevsp[-2].charPtrDlistData->clearAndDestroy();
1025 delete stylevsp[-2].charPtrDlistData ;
1026 styleval.FeaturePtrData=f;
1031 stylevsp[-2].charPtrDlistData -> prepend((char *)stylevsp[0].charPtrData);
1032 styleval.charPtrDlistData=stylevsp[-2].charPtrDlistData;
1037 styleval.charPtrDlistData=new CC_TPtrDlist<char>;
1038 styleval.charPtrDlistData -> append((char *)stylevsp[0].charPtrData);
1043 styleval.PathFeatureListPtrData=new PathFeatureList;
1044 styleval.PathFeatureListPtrData -> append(new PathFeature(stylevsp[-1].PathPtrData, stylevsp[0].FeatureSetPtrData));
1050 PathFeatureListIterator l_Iter(*(stylevsp[-1].PathFeatureListPtrData));
1052 while ( ++l_Iter ) {
1053 (l_Iter.key()) -> path() -> prependPath(*stylevsp[-3].PathPtrData);
1055 delete stylevsp[-3].PathPtrData;
1056 styleval.PathFeatureListPtrData=stylevsp[-1].PathFeatureListPtrData;
1061 styleval.PathFeatureListPtrData=stylevsp[-2].PathFeatureListPtrData;
1062 styleval.PathFeatureListPtrData -> appendList(*stylevsp[0].PathFeatureListPtrData);
1063 delete stylevsp[0].PathFeatureListPtrData ;
1068 styleval.PathFeatureListPtrData=stylevsp[0].PathFeatureListPtrData;
1073 stylevsp[-1].PathPtrData -> appendPathTerm(stylevsp[0].PathTermPtrData);
1074 styleval.PathPtrData=stylevsp[-1].PathPtrData;
1079 styleval.PathPtrData = new SSPath;
1080 styleval.PathPtrData -> appendPathTerm(stylevsp[0].PathTermPtrData);
1085 styleval.PathTermPtrData=new PathTerm((const char*)stylevsp[-1].charPtrData, stylevsp[0].PQExprPtrData);
1086 delete stylevsp[-1].charPtrData;
1091 localCharToCharPtrBuf[0]=stylevsp[0].charData; localCharToCharPtrBuf[1]=0;
1092 styleval.PathTermPtrData=new PathTerm(localCharToCharPtrBuf, 0);
1097 localCharToCharPtrBuf[0]=stylevsp[0].charData; localCharToCharPtrBuf[1]=0;
1098 styleval.PathTermPtrData=new PathTerm(localCharToCharPtrBuf, 0);
1115 /* char % can start an OLIAS internal element which*/
1116 /* is used only by the browser.*/
1117 /* Example %BOGUS within HEAD1 in OLIAS book*/
1119 if ( stylevsp[0].charPtrData[0] != '%' && isalnum(stylevsp[0].charPtrData[0]) == 0 ) {
1120 MESSAGE(cerr, form("%s is not a SGMLGI", stylevsp[0].charPtrData));
1121 throw(CASTBEEXCEPT badEvaluationException());
1123 /* note, should probably be using RCStrings, would make wide */
1124 /* char handling better too? */
1125 if ( gGI_CASE_SENSITIVE == false )
1127 for (unsigned int i=0; i<strlen((const char*)stylevsp[0].charPtrData); i++)
1128 if ( islower(stylevsp[0].charPtrData[i]) )
1129 stylevsp[0].charPtrData[i] = toupper(stylevsp[0].charPtrData[i]);
1131 styleval.charPtrData=stylevsp[0].charPtrData;
1135 {enter_sgmlgi_context();}
1139 int l3 = strlen((char*)stylevsp[-3].charPtrData);
1140 int l0 = strlen((char*)stylevsp[0].charPtrData);
1141 int l = l3 + l0 + 2;
1142 styleval.charPtrData=new unsigned char[l];
1144 *((char *) memcpy((char*)styleval.charPtrData,
1145 (char*)stylevsp[-3].charPtrData, l3) + l3) = '\0';
1146 *((char *) memcpy((char*)(styleval.charPtrData + l3),
1147 ".", 1) + 1) = '\0';
1148 *((char *) memcpy((char*)(styleval.charPtrData + l3 + 1),
1149 (char*)stylevsp[0].charPtrData, l0) + l0) = '\0';
1151 delete stylevsp[-3].charPtrData;
1152 delete stylevsp[0].charPtrData;
1157 int l1 = strlen((char*)stylevsp[-1].charPtrData);
1159 styleval.charPtrData=new unsigned char[l];
1161 *((char *) memcpy((char*)styleval.charPtrData,
1162 (char*)stylevsp[-1].charPtrData, l1) + l1) = '\0';
1163 *((char *) memcpy((char*)styleval.charPtrData + l1,
1164 ".", 1) + 1) = '\0';
1166 delete stylevsp[-1].charPtrData;
1171 styleval.charPtrData=stylevsp[0].charPtrData;
1178 for (i=0; i<strlen((const char*)stylevsp[0].charPtrData); i++) {
1180 if ( isalpha(stylevsp[0].charPtrData[i]) )
1187 c = stylevsp[0].charPtrData[i]; stylevsp[0].charPtrData[i]=0;
1188 x = atof((const char*)stylevsp[0].charPtrData);
1189 stylevsp[0].charPtrData[i]=c;
1193 styleval.termNodePtrData=new ConstantNode(new FeatureValueDimension(new FeatureValueReal(x), (const char*)&stylevsp[0].charPtrData[i]));
1195 delete stylevsp[0].charPtrData;
1200 styleval.charPtrData=stylevsp[0].charPtrData;
1205 styleval.charPtrData=stylevsp[0].charPtrData;
1210 styleval.PQExprPtrData=stylevsp[-1].PQExprPtrData;
1215 /*////////////////////////////////////////////////////*/
1216 /* This portion of the code (up to equality_expr) is */
1217 /* hacked for V1.1 only. Due to the way */
1218 /* PathQualifier.h is written, this code is not */
1219 /* general at all. qfc 8/16/94*/
1220 /*////////////////////////////////////////////////////*/
1221 styleval.PQExprPtrData=stylevsp[0].PQExprPtrData;
1226 styleval.PQExprPtrData = new PQLogExpr(stylevsp[-2].PQExprPtrData, PQor, stylevsp[0].PQExprPtrData);
1231 styleval.PQExprPtrData=stylevsp[0].PQExprPtrData;
1236 styleval.PQExprPtrData = new PQLogExpr(stylevsp[-2].PQExprPtrData, PQand, stylevsp[0].PQExprPtrData);
1241 styleval.PQExprPtrData = new PQAttributeSelector(
1242 gSymTab->intern((const char*)stylevsp[-2].charPtrData),
1243 ( stylevsp[-1].intData == EQUAL ) ? PQEqual : PQNotEqual,
1244 (const char*)stylevsp[0].charPtrData
1246 delete stylevsp[-2].charPtrData;
1247 delete stylevsp[0].charPtrData;
1252 if ( strcasecmp((char*)stylevsp[-2].charPtrData, "position") == 0 ) {
1253 styleval.PQExprPtrData=new PQPosition(
1254 ( stylevsp[-1].intData == EQUAL ) ? PQEqual : PQNotEqual,
1258 if ( strcasecmp((char*)stylevsp[-2].charPtrData, "sibling") == 0 ) {
1259 styleval.PQExprPtrData=new PQSibling(
1260 ( stylevsp[-1].intData == EQUAL ) ? PQEqual : PQNotEqual,
1264 throw(CASTSSEXCEPT StyleSheetException());
1266 delete stylevsp[-2].charPtrData;
1271 styleval.intData = (int)stylevsp[0].intData;
1276 if ( strcasecmp((char*)stylevsp[0].charPtrData, "#LAST") != 0 )
1277 throw(CASTSSEXCEPT StyleSheetException());
1279 styleval.intData = -1;
1312 styleval.PQExprPtrData=stylevsp[0].PQExprPtrData;
1317 styleval.PQExprPtrData=0;
1322 stylestate = *stylessp;
1324 stylem = stylelhs[stylen];
1325 if (stylestate == 0 && stylem == 0)
1329 printf("styledebug: after reduction, shifting from state 0 to\
1330 state %d\n", styleFINAL);
1332 stylestate = styleFINAL;
1333 *++stylessp = styleFINAL;
1334 *++stylevsp = styleval;
1337 if ((stylechar = stylelex()) < 0) stylechar = 0;
1342 if (stylechar <= styleMAXTOKEN) styles = stylename[stylechar];
1343 if (!styles) styles = "illegal-symbol";
1344 printf("styledebug: state %d, reading %d (%s)\n",
1345 styleFINAL, stylechar, styles);
1349 if (stylechar == 0) goto styleaccept;
1352 if ((stylen = stylegindex[stylem]) && (stylen += stylestate) >= 0 &&
1353 stylen <= styleTABLESIZE && stylecheck[stylen] == stylestate)
1354 stylestate = styletable[stylen];
1356 stylestate = styledgoto[stylem];
1359 printf("styledebug: after reduction, shifting from state %d \
1360 to state %d\n", *stylessp, stylestate);
1362 if (stylessp >= styless + stylestacksize - 1)
1366 *++stylessp = stylestate;
1367 *++stylevsp = styleval;
1370 styleerror((char*)"yacc stack overflow");