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 librararies 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 static const char stylesccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
34 #include "StyleSheetExceptions.h"
35 #include "VariableTable.h"
36 #include "FeatureValue.h"
37 #include "Expression.h"
39 #include "PathTable.h"
41 #include "PathQualifier.h"
43 #include "ParserConst.h"
44 #include "FeatureDefDictionary.h"
45 #include <utility/funcs.h>
47 #include "HardCopy/autoNumberFP.h"
48 extern autoNumberFP gAutoNumberFP;
54 #define alloca(x) (malloc(x))
56 extern void styleerror(char*);
57 extern int stylelex();
59 extern void enter_sgmlgi_context();
61 extern featureDefDictionary* g_FeatureDefDictionary;
62 extern unsigned g_validation_mode;
63 extern unsigned g_hasSemanticError;
65 static char localCharToCharPtrBuf[2];
69 const char* toUpperCase(unsigned char* string)
71 static char buffer[512];
73 for ( unsigned int i=0; i<strlen((const char*)string); i++ )
75 if (islower(string[i]))
76 buffer[j] = toupper(string[i]) ;
78 buffer[j] = (char)string[i] ;
87 unsigned char charData;
88 unsigned char* charPtrData;
89 unsigned int boolData;
92 Expression* expPtrData;
93 TermNode* termNodePtrData;
94 FeatureValue* FeatureValuePtrData;
95 FeatureSet* FeatureSetPtrData;
96 Feature* FeaturePtrData;
98 PathTerm* PathTermPtrData;
99 charPtrDlist* charPtrDlistData;
100 PathFeatureList* PathFeatureListPtrData;
101 CompositeVariableNode* CompositeVariableNodePtrData;
103 CC_TPtrSlist<FeatureValue>* FeatureValueSlistPtrData;
105 PQExpr* PQExprPtrData;
108 #define OPER_equality 258
109 #define OPER_relational 259
112 #define OPER_assign 262
113 #define ARRAYOPEN 263
114 #define ARRAYCLOSE 264
115 #define SEPARATOR 265
118 #define OPER_modify 268
119 #define OPER_parent 269
120 #define OPER_attr 270
121 #define OPER_oneof 271
122 #define OPER_star 272
126 #define OPER_parenopen 276
127 #define OPER_parenclose 277
128 #define OPER_logicalnegate 278
130 #define PMEMCLOSE 280
131 #define OPER_period 281
132 #define OPER_plus 282
133 #define OPER_minus 283
134 #define DIMENSION 284
135 #define NORMAL_STRING 285
136 #define UNIT_STRING 286
137 #define QUOTED_STRING 287
138 #define GI_CASE_SENSITIVE 288
139 #define SGMLGI_STRING 289
140 #define styleERRCODE 256
141 short stylelhs[] = { -1,
142 0, 37, 38, 38, 39, 13, 13, 13, 22, 22,
143 14, 15, 19, 19, 19, 11, 11, 10, 10, 7,
144 7, 6, 6, 12, 12, 12, 12, 12, 12, 12,
145 12, 12, 12, 20, 20, 4, 4, 23, 23, 21,
146 21, 17, 17, 18, 18, 40, 40, 24, 29, 29,
147 28, 28, 27, 27, 25, 25, 26, 26, 26, 9,
148 8, 8, 2, 41, 5, 5, 5, 16, 3, 3,
149 34, 30, 30, 31, 31, 32, 32, 1, 1, 35,
150 35, 36, 36, 42, 42, 33, 33,
152 short stylelen[] = { 2,
153 2, 3, 1, 1, 3, 1, 2, 1, 3, 1,
154 2, 2, 1, 1, 1, 3, 1, 3, 1, 1,
155 1, 1, 1, 1, 2, 1, 1, 1, 2, 2,
156 1, 1, 3, 4, 3, 1, 0, 3, 1, 1,
157 1, 4, 2, 3, 1, 1, 0, 3, 3, 1,
158 2, 4, 3, 1, 2, 1, 2, 1, 1, 1,
159 1, 1, 1, 0, 4, 2, 1, 1, 1, 1,
160 3, 1, 3, 1, 3, 4, 3, 1, 1, 1,
163 short styledefred[] = { 0,
164 0, 0, 0, 80, 0, 58, 59, 69, 70, 0,
165 0, 63, 0, 56, 4, 1, 85, 3, 0, 2,
166 0, 57, 86, 0, 0, 0, 0, 0, 51, 55,
167 84, 0, 0, 0, 0, 74, 0, 24, 0, 0,
168 0, 0, 68, 28, 0, 0, 0, 0, 19, 0,
169 0, 6, 27, 15, 5, 14, 0, 0, 43, 50,
170 0, 45, 0, 0, 54, 0, 0, 71, 0, 0,
171 29, 30, 11, 12, 10, 0, 0, 22, 23, 0,
172 61, 62, 0, 25, 0, 60, 0, 65, 0, 0,
173 0, 0, 0, 52, 0, 78, 79, 77, 0, 75,
174 33, 35, 0, 41, 0, 0, 18, 0, 9, 44,
175 42, 48, 49, 53, 76, 0, 34, 38,
177 short styledgoto[] = { 2,
178 98, 10, 28, 46, 12, 80, 0, 83, 87, 47,
179 48, 49, 50, 51, 52, 53, 54, 61, 55, 56,
180 105, 57, 106, 62, 13, 14, 64, 15, 63, 34,
181 35, 36, 22, 23, 3, 16, 4, 17, 18, 90,
184 short stylesindex[] = { -277,
185 -246, 0, -225, 0, -218, 0, 0, 0, 0, -231,
186 -228, 0, -259, 0, 0, 0, 0, 0, -225, 0,
187 -265, 0, 0, -221, 0, -234, -225, -222, 0, 0,
188 0, -229, -196, -206, -204, 0, -213, 0, -187, -229,
189 -229, -168, 0, 0, 0, -156, -251, -177, 0, -172,
190 -229, 0, 0, 0, 0, 0, -161, -167, 0, 0,
191 -141, 0, -237, -255, 0, -133, -249, 0, -265, -265,
192 0, 0, 0, 0, 0, -199, -189, 0, 0, -168,
193 0, 0, -168, 0, -161, 0, -229, 0, -229, -139,
194 -221, -229, -225, 0, -158, 0, 0, 0, -204, 0,
195 0, 0, -177, 0, -132, -130, 0, -251, 0, 0,
196 0, 0, 0, 0, 0, -168, 0, 0,
198 short stylerindex[] = { 37,
199 0, 0, 132, 0, 0, 0, 0, 0, 0, -145,
200 -257, 0, 0, 0, 0, 0, 0, 0, 135, 0,
201 0, 0, 0, -127, 1, 0, 0, 30, 0, 0,
202 0, 0, 0, 0, -179, 0, 169, 0, 178, 0,
203 0, 0, 0, 0, 54, 0, 123, 130, 0, 200,
204 0, 0, 0, 0, 0, 0, 77, 0, 0, 0,
205 -129, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, -127, 0, 0, 0,
207 0, 0, 0, 0, 100, 0, 0, 0, -128, 0,
208 -127, 0, 0, 0, 0, 0, 0, 0, -160, 0,
209 0, 0, -155, 0, -122, 0, 0, 146, 0, 0,
210 0, 0, 0, 0, 0, -127, 0, 0,
212 short stylegindex[] = { 0,
213 0, 71, -1, 0, 0, 0, 0, 0, 74, 60,
214 -42, 64, 0, 0, 0, 0, 134, 0, 57, -73,
215 0, 94, 33, 61, 0, 138, 0, -24, 0, 0,
216 83, 84, 0, 0, 0, 0, 0, 136, 0, 0,
219 #define styleTABLESIZE 485
220 short styletable[] = { 76,
221 66, 11, 65, 104, 32, 67, 26, 96, 67, 93,
222 1, 6, 7, 67, 67, 5, 27, 11, 67, 33,
223 78, 94, 45, 79, 60, 8, 9, 67, 67, 67,
224 91, 21, 59, 24, 103, 37, 81, 97, 38, 39,
225 75, 20, 104, 86, 26, 6, 7, 40, 41, 75,
226 8, 9, 25, 10, 42, 8, 9, 68, 25, 8,
227 9, 67, 43, 8, 9, 44, 69, 37, 114, 70,
228 38, 39, 71, 103, 102, 45, 8, 101, 75, 40,
229 41, 75, 81, 82, 72, 109, 42, 60, 37, 45,
230 113, 38, 39, 72, 43, 8, 9, 44, 72, 7,
231 40, 41, 66, 73, 81, 82, 77, 42, 40, 40,
232 73, 74, 73, 84, 45, 43, 8, 9, 44, 86,
233 87, 88, 17, 89, 95, 87, 87, 111, 115, 13,
234 87, 83, 116, 117, 82, 37, 92, 47, 46, 87,
235 87, 39, 108, 107, 85, 16, 29, 112, 118, 110,
236 30, 99, 0, 100, 31, 0, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0, 31, 0,
238 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 26,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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, 66, 0,
247 0, 0, 0, 66, 66, 66, 66, 66, 0, 0,
248 0, 66, 66, 0, 0, 66, 66, 66, 0, 0,
249 0, 0, 66, 66, 0, 66, 66, 67, 0, 64,
250 0, 0, 67, 67, 67, 67, 67, 0, 0, 0,
251 67, 67, 0, 0, 67, 67, 67, 81, 81, 0,
252 0, 67, 67, 0, 67, 67, 36, 10, 10, 0,
253 10, 81, 81, 0, 10, 10, 0, 0, 10, 0,
254 0, 0, 0, 0, 10, 10, 10, 0, 10, 10,
255 8, 8, 0, 8, 0, 0, 0, 8, 8, 0,
256 0, 8, 0, 8, 0, 0, 0, 0, 8, 8,
257 0, 8, 8, 7, 7, 0, 7, 0, 0, 0,
258 7, 7, 0, 0, 7, 0, 7, 0, 0, 0,
259 0, 7, 7, 0, 7, 7, 17, 17, 0, 17,
260 0, 0, 0, 17, 13, 0, 13, 0, 0, 17,
261 13, 13, 0, 0, 17, 17, 0, 17, 17, 16,
262 16, 0, 16, 0, 13, 13, 16, 0, 0, 0,
263 0, 0, 16, 0, 0, 0, 0, 16, 16, 0,
264 16, 16, 31, 31, 0, 31, 0, 0, 0, 31,
265 31, 32, 32, 31, 32, 31, 0, 0, 32, 32,
266 31, 31, 32, 31, 32, 0, 0, 0, 0, 32,
267 32, 0, 32, 26, 26, 0, 26, 0, 0, 0,
268 26, 26, 0, 0, 26, 0, 26, 0, 0, 0,
271 short stylecheck[] = { 42,
272 0, 3, 27, 77, 270, 263, 266, 257, 266, 265,
273 288, 271, 272, 271, 272, 262, 276, 19, 276, 285,
274 272, 277, 24, 275, 26, 285, 286, 285, 286, 0,
275 268, 263, 267, 262, 77, 257, 0, 287, 260, 261,
276 42, 260, 116, 281, 266, 271, 272, 269, 270, 51,
277 285, 286, 281, 0, 276, 285, 286, 264, 281, 285,
278 286, 258, 284, 285, 286, 287, 273, 257, 93, 274,
279 260, 261, 286, 116, 264, 77, 0, 277, 80, 269,
280 270, 83, 282, 283, 264, 87, 276, 89, 257, 91,
281 92, 260, 261, 273, 284, 285, 286, 287, 286, 0,
282 269, 270, 32, 264, 282, 283, 263, 276, 264, 265,
283 40, 41, 273, 286, 116, 284, 285, 286, 287, 281,
284 266, 289, 0, 265, 258, 271, 272, 267, 287, 0,
285 276, 0, 265, 264, 0, 263, 63, 267, 267, 285,
286 286, 264, 83, 80, 51, 0, 13, 91, 116, 89,
287 13, 69, -1, 70, 19, -1, -1, -1, -1, -1,
288 -1, -1, -1, -1, -1, -1, -1, -1, 0, -1,
289 -1, -1, -1, -1, -1, -1, -1, 0, -1, -1,
290 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
291 -1, -1, -1, -1, -1, -1, -1, -1, -1, 0,
292 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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, 258, -1,
298 -1, -1, -1, 263, 264, 265, 266, 267, -1, -1,
299 -1, 271, 272, -1, -1, 275, 276, 277, -1, -1,
300 -1, -1, 282, 283, -1, 285, 286, 258, -1, 289,
301 -1, -1, 263, 264, 265, 266, 267, -1, -1, -1,
302 271, 272, -1, -1, 275, 276, 277, 271, 272, -1,
303 -1, 282, 283, -1, 285, 286, 263, 264, 265, -1,
304 267, 285, 286, -1, 271, 272, -1, -1, 275, -1,
305 -1, -1, -1, -1, 281, 282, 283, -1, 285, 286,
306 264, 265, -1, 267, -1, -1, -1, 271, 272, -1,
307 -1, 275, -1, 277, -1, -1, -1, -1, 282, 283,
308 -1, 285, 286, 264, 265, -1, 267, -1, -1, -1,
309 271, 272, -1, -1, 275, -1, 277, -1, -1, -1,
310 -1, 282, 283, -1, 285, 286, 264, 265, -1, 267,
311 -1, -1, -1, 271, 265, -1, 267, -1, -1, 277,
312 271, 272, -1, -1, 282, 283, -1, 285, 286, 264,
313 265, -1, 267, -1, 285, 286, 271, -1, -1, -1,
314 -1, -1, 277, -1, -1, -1, -1, 282, 283, -1,
315 285, 286, 264, 265, -1, 267, -1, -1, -1, 271,
316 272, 264, 265, 275, 267, 277, -1, -1, 271, 272,
317 282, 283, 275, 285, 277, -1, -1, -1, -1, 282,
318 283, -1, 285, 264, 265, -1, 267, -1, -1, -1,
319 271, 272, -1, -1, 275, -1, 277, -1, -1, -1,
320 -1, 282, 283, -1, 285,
326 #define styleMAXTOKEN 289
328 char *stylename[] = {
329 "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,
330 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,"INTEGER","OPER_equality",
336 "OPER_relational","BOOLVAL","REAL","OPER_assign","ARRAYOPEN","ARRAYCLOSE",
337 "SEPARATOR","FSOPEN","FSCLOSE","OPER_modify","OPER_parent","OPER_attr",
338 "OPER_oneof","OPER_star","OPER_or","OPER_and","OPER_div","OPER_parenopen",
339 "OPER_parenclose","OPER_logicalnegate","PMEMOPEN","PMEMCLOSE","OPER_period",
340 "OPER_plus","OPER_minus","DIMENSION","NORMAL_STRING","UNIT_STRING",
341 "QUOTED_STRING","GI_CASE_SENSITIVE","SGMLGI_STRING",
343 char *stylerule[] = {
344 "$accept : stylesheet",
345 "stylesheet : sensitivityOPTL statement.gpOPTL",
346 "sensitivity : GI_CASE_SENSITIVE OPER_assign BOOLVAL",
347 "statement.gp : var_assignment",
348 "statement.gp : path_expr",
349 "var_assignment : STRING OPER_assign rhs.gp",
351 "symbol : parent string_list",
352 "symbol : string_list",
353 "string_list : string_list OPER_feature STRING",
354 "string_list : STRING",
355 "parent : OPER_parent SGMLGI",
356 "attr : OPER_attr SGMLGI",
357 "rhs.gp : simple_expr",
359 "rhs.gp : featureset",
360 "simple_expr : simple_expr OPER_add multi_expr",
361 "simple_expr : multi_expr",
362 "multi_expr : multi_expr OPER_mult term",
364 "OPER_binop : OPER_mult",
365 "OPER_binop : OPER_add",
366 "OPER_mult : OPER_star",
367 "OPER_mult : OPER_div",
369 "term : symbol UNIT_STRING",
372 "term : QUOTED_STRING",
373 "term : INTEGER UNIT_STRING",
374 "term : REAL UNIT_STRING",
377 "term : OPER_parenopen simple_expr OPER_parenclose",
378 "array : array_name ARRAYOPEN array_member_list ARRAYCLOSE",
379 "array : array_name ARRAYOPEN ARRAYCLOSE",
380 "array_name : STRING",
382 "array_member_list : array_member SEPARATOR array_member_list",
383 "array_member_list : array_member",
384 "array_member : simple_expr",
385 "array_member : array",
386 "featureset : FSOPEN feature_list SEPARATOR_OPTL FSCLOSE",
387 "featureset : FSOPEN FSCLOSE",
388 "feature_list : feature_list SEPARATOR feature",
389 "feature_list : feature",
390 "SEPARATOR_OPTL : SEPARATOR",
392 "feature : feature_name_list OPER_modify rhs.gp",
393 "feature_name_list : feature_name_list OPER_feature STRING",
394 "feature_name_list : STRING",
395 "path_expr : path_term_list featureset",
396 "path_expr : path_term_list OPER_parenopen path_expr_list OPER_parenclose",
397 "path_expr_list : path_expr_list SEPARATOR path_expr",
398 "path_expr_list : path_expr",
399 "path_term_list : path_term_list path_term",
400 "path_term_list : path_term",
401 "path_term : SGMLGI path_selectorOPTL",
402 "path_term : OPER_oneof",
403 "path_term : OPER_star",
404 "OPER_feature : OPER_period",
405 "OPER_add : OPER_plus",
406 "OPER_add : OPER_minus",
407 "SGMLGI : SGMLGI_CONTENT",
409 "SGMLGI_CONTENT : STRING OPER_period $$1 SGMLGI_STRING",
410 "SGMLGI_CONTENT : STRING OPER_period",
411 "SGMLGI_CONTENT : STRING",
412 "dimension : DIMENSION",
413 "STRING : NORMAL_STRING",
414 "STRING : UNIT_STRING",
415 "path_selector : ARRAYOPEN boolean_expr ARRAYCLOSE",
416 "boolean_expr : logical_and_expr",
417 "boolean_expr : boolean_expr OPER_or logical_and_expr",
418 "logical_and_expr : equality_expr",
419 "logical_and_expr : logical_and_expr OPER_and equality_expr",
420 "equality_expr : OPER_attr SGMLGI OPER_equality QUOTED_STRING",
421 "equality_expr : NORMAL_STRING OPER_equality POSITION_VALUE",
422 "POSITION_VALUE : INTEGER",
423 "POSITION_VALUE : QUOTED_STRING",
424 "sensitivityOPTL : sensitivity",
426 "statement.gpOPTL : statement.gpPLUS",
427 "statement.gpOPTL :",
428 "statement.gpPLUS : statement.gpPLUS statement.gp",
429 "statement.gpPLUS : statement.gp",
430 "path_selectorOPTL : path_selector",
431 "path_selectorOPTL :",
434 #define styleclearin (stylechar=(-1))
435 #define styleerrok (styleerrflag=0)
436 #ifdef styleSTACKSIZE
437 #ifndef styleMAXDEPTH
438 #define styleMAXDEPTH styleSTACKSIZE
442 #define styleSTACKSIZE styleMAXDEPTH
444 #define styleSTACKSIZE 500
445 #define styleMAXDEPTH 500
453 styleSTYPE *stylevsp;
455 styleSTYPE stylelval;
456 short styless[styleSTACKSIZE];
457 styleSTYPE stylevs[styleSTACKSIZE];
458 #define stylestacksize styleSTACKSIZE
459 #define styleABORT goto styleabort
460 #define styleACCEPT goto styleaccept
461 #define styleERROR goto styleerrlab
464 extern char *getenv(const char *);
470 register int stylem, stylen, stylestate;
472 register char *styles;
474 if (styles = getenv("styleDEBUG"))
477 if (stylen >= '0' && stylen <= '9')
478 styledebug = stylen - '0';
488 *stylessp = stylestate = 0;
491 if ((stylen = styledefred[stylestate])) goto stylereduce;
494 if ((stylechar = stylelex()) < 0) stylechar = 0;
499 if (stylechar <= styleMAXTOKEN) styles = stylename[stylechar];
500 if (!styles) styles = "illegal-symbol";
501 printf("styledebug: state %d, reading %d (%s)\n", stylestate,
506 if ((stylen = stylesindex[stylestate]) && (stylen += stylechar) >= 0 &&
507 stylen <= styleTABLESIZE && stylecheck[stylen] == stylechar)
511 printf("styledebug: state %d, shifting to state %d\n",
512 stylestate, styletable[stylen]);
514 if (stylessp >= styless + stylestacksize - 1)
518 *++stylessp = stylestate = styletable[stylen];
519 *++stylevsp = stylelval;
521 if (styleerrflag > 0) --styleerrflag;
524 if ((stylen = stylerindex[stylestate]) && (stylen += stylechar) >= 0 &&
525 stylen <= styleTABLESIZE && stylecheck[stylen] == stylechar)
527 stylen = styletable[stylen];
530 if (styleerrflag) goto styleinrecovery;
531 #if 0 /* remove if needed */
537 styleerror((char*)"syntax error");
538 #if 0 /* remove if needed */
546 if (styleerrflag < 3)
551 if ((stylen = stylesindex[*stylessp]) && (stylen += styleERRCODE) >= 0 &&
552 stylen <= styleTABLESIZE && stylecheck[stylen] == styleERRCODE)
556 printf("styledebug: state %d, error recovery shifting\
557 to state %d\n", *stylessp, styletable[stylen]);
559 if (stylessp >= styless + stylestacksize - 1)
563 *++stylessp = stylestate = styletable[stylen];
564 *++stylevsp = stylelval;
571 printf("styledebug: error recovery discarding state %d\n",
574 if (stylessp <= styless) goto styleabort;
582 if (stylechar == 0) goto styleabort;
587 if (stylechar <= styleMAXTOKEN) styles = stylename[stylechar];
588 if (!styles) styles = "illegal-symbol";
589 printf("styledebug: state %d, error recovery discards token %d (%s)\n",
590 stylestate, stylechar, styles);
599 printf("styledebug: state %d, reducing by rule %d (%s)\n",
600 stylestate, stylen, stylerule[stylen]);
602 stylem = stylelen[stylen];
603 styleval = stylevsp[1-stylem];
612 gGI_CASE_SENSITIVE = stylevsp[0].boolData;
621 /* copy items form the feature list into the path table */
622 PathFeatureListIterator l_Iter(*(stylevsp[0].PathFeatureListPtrData));
630 if ( g_validation_mode == true )
631 if ( g_FeatureDefDictionary -> checkSemantics(x -> featureSet()) == false )
632 g_hasSemanticError = true;
634 gPathTab -> addPathFeatureSet( x );
639 /* clear out the first list so the elements are not deleted
640 with the list because they are still referenced by the
643 stylevsp[0].PathFeatureListPtrData -> clear();
644 delete stylevsp[0].PathFeatureListPtrData;
650 Expression *x = new Expression(new ConstantNode(stylevsp[0].FeatureValuePtrData));
652 if ( gAutoNumberFP.accept((const char*)stylevsp[-2].charPtrData, x) ) {
653 delete stylevsp[-2].charPtrData;
658 gVariableTable -> enter( gSymTab -> intern((const char*)stylevsp[-2].charPtrData), x);
659 delete stylevsp[-2].charPtrData;
664 styleval.termNodePtrData=stylevsp[0].termNodePtrData;
669 styleval.termNodePtrData=stylevsp[-1].termNodePtrData;
674 const Symbol* x = stylevsp[0].CompositeVariableNodePtrData -> convertableToVariable();
676 styleval.termNodePtrData=new VariableNode(*x);
677 delete stylevsp[0].CompositeVariableNodePtrData;
679 styleval.termNodePtrData=stylevsp[0].CompositeVariableNodePtrData;
685 stylevsp[-2].CompositeVariableNodePtrData->appendItem(gSymTab->intern(toUpperCase(stylevsp[0].charPtrData)));
686 styleval.CompositeVariableNodePtrData=stylevsp[-2].CompositeVariableNodePtrData;
687 delete stylevsp[0].charPtrData ;
692 styleval.CompositeVariableNodePtrData=new CompositeVariableNode;
693 styleval.CompositeVariableNodePtrData -> appendItem(gSymTab->intern(toUpperCase(stylevsp[0].charPtrData)));
694 delete stylevsp[0].charPtrData;
701 ParentNode(gSymTab->intern((const char*)$1));
703 MESSAGE(cerr, "^ operator not supported.");
704 throw(CASTSSEXCEPT StyleSheetException());
709 styleval.termNodePtrData=new
710 SgmlAttributeNode(gSymTab->intern((const char*)stylevsp[0].charPtrData));
711 delete stylevsp[0].charPtrData;
716 styleval.FeatureValuePtrData=new FeatureValueExpression(stylevsp[0].expPtrData);
721 styleval.FeatureValuePtrData=stylevsp[0].FeatureValuePtrData;
726 styleval.FeatureValuePtrData=new FeatureValueFeatureSet(stylevsp[0].FeatureSetPtrData);
731 BinaryOperatorNode::operatorType opType;
732 switch (stylevsp[-1].charData) {
733 case '+': opType=BinaryOperatorNode::PLUS; break;
734 case '-': opType=BinaryOperatorNode::MINUS; break;
736 throw(CASTBEEXCEPT badEvaluationException());
739 FeatureValueExpression* FVexprL = new FeatureValueExpression(stylevsp[-2].expPtrData);
740 FeatureValueExpression* FVexprR = new FeatureValueExpression(stylevsp[0].expPtrData);
742 styleval.expPtrData = new Expression(
743 new BinaryOperatorNode(opType,
744 new ConstantNode(FVexprL),
745 new ConstantNode(FVexprR)
752 styleval.expPtrData=stylevsp[0].expPtrData;
757 BinaryOperatorNode::operatorType opType;
758 switch (stylevsp[-1].charData) {
759 case '*': opType=BinaryOperatorNode::TIMES; break;
760 case '/': opType=BinaryOperatorNode::DIVIDE; break;
762 throw(CASTBEEXCEPT badEvaluationException());
765 FeatureValueExpression* FVexpr = new FeatureValueExpression(stylevsp[-2].expPtrData);
767 styleval.expPtrData = new Expression(
768 new BinaryOperatorNode(opType, new ConstantNode(FVexpr), stylevsp[0].termNodePtrData)
774 styleval.expPtrData = new Expression(stylevsp[0].termNodePtrData);
779 styleval.charData=stylevsp[0].charData;
784 styleval.charData=stylevsp[0].charData;
789 styleval.charData=stylevsp[0].charData;
794 styleval.charData=stylevsp[0].charData;
799 styleval.termNodePtrData=new ConstantNode(new FeatureValueInt(int(stylevsp[0].boolData)));
804 FeatureValueExpression* fve =
805 new FeatureValueExpression(new Expression(stylevsp[-1].termNodePtrData));
806 FeatureValueDimension* x =
807 new FeatureValueDimension(fve, (const char*)stylevsp[0].charPtrData);
808 delete stylevsp[0].charPtrData ;
809 styleval.termNodePtrData=new ConstantNode(x);
814 styleval.termNodePtrData=stylevsp[0].termNodePtrData;
819 styleval.termNodePtrData=stylevsp[0].termNodePtrData;
824 styleval.termNodePtrData=new ConstantNode(new FeatureValueString((const char*)stylevsp[0].charPtrData));
825 delete stylevsp[0].charPtrData ;
830 styleval.termNodePtrData=new ConstantNode(new FeatureValueDimension(new FeatureValueInt(stylevsp[-1].intData), (const char*)stylevsp[0].charPtrData));
831 delete stylevsp[0].charPtrData ;
836 styleval.termNodePtrData=new ConstantNode(new FeatureValueDimension(new FeatureValueReal(stylevsp[-1].realData), (const char*)stylevsp[0].charPtrData));
837 delete stylevsp[0].charPtrData ;
842 styleval.termNodePtrData=new ConstantNode(new FeatureValueInt(stylevsp[0].intData));
847 styleval.termNodePtrData=new ConstantNode(new FeatureValueReal(stylevsp[0].realData));
852 styleval.termNodePtrData=new ConstantNode(new FeatureValueExpression(stylevsp[-1].expPtrData));
857 FeatureValueArray* x =
858 new FeatureValueArray((const char*)stylevsp[-3].charPtrData, stylevsp[-1].FeatureValueSlistPtrData -> entries());
859 CC_TPtrSlistIterator<FeatureValue> iter(*stylevsp[-1].FeatureValueSlistPtrData);
863 (*x)[i++] = iter.key();
866 delete stylevsp[-3].charPtrData;
867 delete stylevsp[-1].FeatureValueSlistPtrData;
869 styleval.FeatureValuePtrData = x;
874 styleval.FeatureValuePtrData = new FeatureValueArray((const char*)stylevsp[-2].charPtrData, 0);
875 delete stylevsp[-2].charPtrData;
880 styleval.charPtrData = stylevsp[0].charPtrData;
885 styleval.charPtrData = new unsigned char[1];
886 styleval.charPtrData[0] = 0;
891 stylevsp[0].FeatureValueSlistPtrData -> prepend(stylevsp[-2].FeatureValuePtrData);
892 styleval.FeatureValueSlistPtrData = stylevsp[0].FeatureValueSlistPtrData;
897 styleval.FeatureValueSlistPtrData=new CC_TPtrSlist<FeatureValue>;
898 styleval.FeatureValueSlistPtrData -> append(stylevsp[0].FeatureValuePtrData);
903 styleval.FeatureValuePtrData = new FeatureValueExpression(stylevsp[0].expPtrData);
908 styleval.FeatureValuePtrData=stylevsp[0].FeatureValuePtrData;
913 styleval.FeatureSetPtrData=stylevsp[-2].FeatureSetPtrData;
918 styleval.FeatureSetPtrData = new FeatureSet ();
923 if (stylevsp[0].FeaturePtrData -> name() == Symbol(gSymTab->intern("FAMILY"))) {
924 /* the evaluate() call clones $3 */
925 FeatureValueFeatureSet *fvfs =
926 (FeatureValueFeatureSet*) stylevsp[0].FeaturePtrData->evaluate();
927 const FeatureSet* fs = fvfs->value();
928 const Feature* charsetF =
929 fs->lookup(gSymTab->intern("CHARSET"));
930 /* charsetF is a mandatory entry in fontfamily*/
932 const FeatureValueString* fv_string =
933 (FeatureValueString*)charsetF->value();
934 const char* charset = *fv_string;
937 int entries = stylevsp[-2].FeatureSetPtrData -> entries();
938 for (int i=0; i<entries; i++) {
939 const Feature* entry = stylevsp[-2].FeatureSetPtrData->at(i);
940 if (! (entry->name() == Symbol(gSymTab->intern("FAMILY"))))
942 const FeatureSet* entry_fs =
943 ((FeatureValueFeatureSet*)(entry->evaluate()))->value();
944 const Feature* entry_charsetF =
945 entry_fs->lookup(gSymTab->intern("CHARSET"));
946 assert( entry_charsetF );
947 const char* entry_charset =
948 *((FeatureValueString*)(entry_charsetF->value()));
949 assert( entry_charset );
950 if (! strcmp(charset, entry_charset)) {
951 delete stylevsp[-2].FeatureSetPtrData -> removeAt(i);
952 break; /* escape from for-loop*/
957 styleval.FeatureSetPtrData = stylevsp[-2].FeatureSetPtrData;
958 styleval.FeatureSetPtrData -> add(stylevsp[0].FeaturePtrData);
961 if ( stylevsp[-2].FeatureSetPtrData -> find((Feature*)stylevsp[0].FeaturePtrData) ) {
962 FeatureSet* fs = new FeatureSet();
963 fs -> add(stylevsp[0].FeaturePtrData);
965 styleval.FeatureSetPtrData =new FeatureSet(*stylevsp[-2].FeatureSetPtrData, *fs);
966 delete stylevsp[-2].FeatureSetPtrData;
970 styleval.FeatureSetPtrData=stylevsp[-2].FeatureSetPtrData;
971 styleval.FeatureSetPtrData -> add(stylevsp[0].FeaturePtrData);
978 styleval.FeatureSetPtrData=new FeatureSet();
979 styleval.FeatureSetPtrData -> add(stylevsp[0].FeaturePtrData);
992 CC_TPtrDlistIterator<char> l_Iter(*(stylevsp[-2].charPtrDlistData));
996 FeatureValue *fv = stylevsp[0].FeatureValuePtrData;
997 const char* cptr = 0;
1000 cptr = l_Iter.key();
1002 const char *c = cptr ;
1006 buffer[index] = toupper(*c) ;
1008 buffer[index] = *c ;
1013 /* fprintf(stderr, "converted: %s to %s\n", cptr, buffer); */
1014 f = new Feature(gSymTab -> intern(buffer), fv);
1016 if ( stylevsp[-2].charPtrDlistData -> last() != cptr ) {
1017 fs = new FeatureSet();
1019 fv = new FeatureValueFeatureSet(fs);
1023 stylevsp[-2].charPtrDlistData->clearAndDestroy();
1024 delete stylevsp[-2].charPtrDlistData ;
1025 styleval.FeaturePtrData=f;
1030 stylevsp[-2].charPtrDlistData -> prepend((char *)stylevsp[0].charPtrData);
1031 styleval.charPtrDlistData=stylevsp[-2].charPtrDlistData;
1036 styleval.charPtrDlistData=new CC_TPtrDlist<char>;
1037 styleval.charPtrDlistData -> append((char *)stylevsp[0].charPtrData);
1042 styleval.PathFeatureListPtrData=new PathFeatureList;
1043 styleval.PathFeatureListPtrData -> append(new PathFeature(stylevsp[-1].PathPtrData, stylevsp[0].FeatureSetPtrData));
1049 PathFeatureListIterator l_Iter(*(stylevsp[-1].PathFeatureListPtrData));
1051 while ( ++l_Iter ) {
1052 (l_Iter.key()) -> path() -> prependPath(*stylevsp[-3].PathPtrData);
1054 delete stylevsp[-3].PathPtrData;
1055 styleval.PathFeatureListPtrData=stylevsp[-1].PathFeatureListPtrData;
1060 styleval.PathFeatureListPtrData=stylevsp[-2].PathFeatureListPtrData;
1061 styleval.PathFeatureListPtrData -> appendList(*stylevsp[0].PathFeatureListPtrData);
1062 delete stylevsp[0].PathFeatureListPtrData ;
1067 styleval.PathFeatureListPtrData=stylevsp[0].PathFeatureListPtrData;
1072 stylevsp[-1].PathPtrData -> appendPathTerm(stylevsp[0].PathTermPtrData);
1073 styleval.PathPtrData=stylevsp[-1].PathPtrData;
1078 styleval.PathPtrData = new SSPath;
1079 styleval.PathPtrData -> appendPathTerm(stylevsp[0].PathTermPtrData);
1084 styleval.PathTermPtrData=new PathTerm((const char*)stylevsp[-1].charPtrData, stylevsp[0].PQExprPtrData);
1085 delete stylevsp[-1].charPtrData;
1090 localCharToCharPtrBuf[0]=stylevsp[0].charData; localCharToCharPtrBuf[1]=0;
1091 styleval.PathTermPtrData=new PathTerm(localCharToCharPtrBuf, 0);
1096 localCharToCharPtrBuf[0]=stylevsp[0].charData; localCharToCharPtrBuf[1]=0;
1097 styleval.PathTermPtrData=new PathTerm(localCharToCharPtrBuf, 0);
1114 /* char % can start an OLIAS internal element which*/
1115 /* is used only by the browser.*/
1116 /* Example %BOGUS within HEAD1 in OLIAS book*/
1118 if ( stylevsp[0].charPtrData[0] != '%' && isalnum(stylevsp[0].charPtrData[0]) == 0 ) {
1119 MESSAGE(cerr, form("%s is not a SGMLGI", stylevsp[0].charPtrData));
1120 throw(CASTBEEXCEPT badEvaluationException());
1122 /* note, should probably be using RCStrings, would make wide */
1123 /* char handling better too? */
1124 if ( gGI_CASE_SENSITIVE == false )
1126 for (unsigned int i=0; i<strlen((const char*)stylevsp[0].charPtrData); i++)
1127 if ( islower(stylevsp[0].charPtrData[i]) )
1128 stylevsp[0].charPtrData[i] = toupper(stylevsp[0].charPtrData[i]);
1130 styleval.charPtrData=stylevsp[0].charPtrData;
1134 {enter_sgmlgi_context();}
1138 int l3 = strlen((char*)stylevsp[-3].charPtrData);
1139 int l0 = strlen((char*)stylevsp[0].charPtrData);
1140 int l = l3 + l0 + 2;
1141 styleval.charPtrData=new unsigned char[l];
1143 *((char *) memcpy((char*)styleval.charPtrData,
1144 (char*)stylevsp[-3].charPtrData, l3) + l3) = '\0';
1145 *((char *) memcpy((char*)(styleval.charPtrData + l3),
1146 ".", 1) + 1) = '\0';
1147 *((char *) memcpy((char*)(styleval.charPtrData + l3 + 1),
1148 (char*)stylevsp[0].charPtrData, l0) + l0) = '\0';
1150 delete stylevsp[-3].charPtrData;
1151 delete stylevsp[0].charPtrData;
1156 int l1 = strlen((char*)stylevsp[-1].charPtrData);
1158 styleval.charPtrData=new unsigned char[l];
1160 *((char *) memcpy((char*)styleval.charPtrData,
1161 (char*)stylevsp[-1].charPtrData, l1) + l1) = '\0';
1162 *((char *) memcpy((char*)styleval.charPtrData + l1,
1163 ".", 1) + 1) = '\0';
1165 delete stylevsp[-1].charPtrData;
1170 styleval.charPtrData=stylevsp[0].charPtrData;
1177 for (i=0; i<strlen((const char*)stylevsp[0].charPtrData); i++) {
1179 if ( isalpha(stylevsp[0].charPtrData[i]) )
1186 c = stylevsp[0].charPtrData[i]; stylevsp[0].charPtrData[i]=0;
1187 x = atof((const char*)stylevsp[0].charPtrData);
1188 stylevsp[0].charPtrData[i]=c;
1192 styleval.termNodePtrData=new ConstantNode(new FeatureValueDimension(new FeatureValueReal(x), (const char*)&stylevsp[0].charPtrData[i]));
1194 delete stylevsp[0].charPtrData;
1199 styleval.charPtrData=stylevsp[0].charPtrData;
1204 styleval.charPtrData=stylevsp[0].charPtrData;
1209 styleval.PQExprPtrData=stylevsp[-1].PQExprPtrData;
1214 /*////////////////////////////////////////////////////*/
1215 /* This portion of the code (up to equality_expr) is */
1216 /* hacked for V1.1 only. Due to the way */
1217 /* PathQualifier.h is written, this code is not */
1218 /* general at all. qfc 8/16/94*/
1219 /*////////////////////////////////////////////////////*/
1220 styleval.PQExprPtrData=stylevsp[0].PQExprPtrData;
1225 styleval.PQExprPtrData = new PQLogExpr(stylevsp[-2].PQExprPtrData, PQor, stylevsp[0].PQExprPtrData);
1230 styleval.PQExprPtrData=stylevsp[0].PQExprPtrData;
1235 styleval.PQExprPtrData = new PQLogExpr(stylevsp[-2].PQExprPtrData, PQand, stylevsp[0].PQExprPtrData);
1240 styleval.PQExprPtrData = new PQAttributeSelector(
1241 gSymTab->intern((const char*)stylevsp[-2].charPtrData),
1242 ( stylevsp[-1].intData == EQUAL ) ? PQEqual : PQNotEqual,
1243 (const char*)stylevsp[0].charPtrData
1245 delete stylevsp[-2].charPtrData;
1246 delete stylevsp[0].charPtrData;
1251 if ( strcasecmp((char*)stylevsp[-2].charPtrData, "position") == 0 ) {
1252 styleval.PQExprPtrData=new PQPosition(
1253 ( stylevsp[-1].intData == EQUAL ) ? PQEqual : PQNotEqual,
1257 if ( strcasecmp((char*)stylevsp[-2].charPtrData, "sibling") == 0 ) {
1258 styleval.PQExprPtrData=new PQSibling(
1259 ( stylevsp[-1].intData == EQUAL ) ? PQEqual : PQNotEqual,
1263 throw(CASTSSEXCEPT StyleSheetException());
1265 delete stylevsp[-2].charPtrData;
1270 styleval.intData = (int)stylevsp[0].intData;
1275 if ( strcasecmp((char*)stylevsp[0].charPtrData, "#LAST") != 0 )
1276 throw(CASTSSEXCEPT StyleSheetException());
1278 styleval.intData = -1;
1311 styleval.PQExprPtrData=stylevsp[0].PQExprPtrData;
1316 styleval.PQExprPtrData=0;
1321 stylestate = *stylessp;
1323 stylem = stylelhs[stylen];
1324 if (stylestate == 0 && stylem == 0)
1328 printf("styledebug: after reduction, shifting from state 0 to\
1329 state %d\n", styleFINAL);
1331 stylestate = styleFINAL;
1332 *++stylessp = styleFINAL;
1333 *++stylevsp = styleval;
1336 if ((stylechar = stylelex()) < 0) stylechar = 0;
1341 if (stylechar <= styleMAXTOKEN) styles = stylename[stylechar];
1342 if (!styles) styles = "illegal-symbol";
1343 printf("styledebug: state %d, reading %d (%s)\n",
1344 styleFINAL, stylechar, styles);
1348 if (stylechar == 0) goto styleaccept;
1351 if ((stylen = stylegindex[stylem]) && (stylen += stylestate) >= 0 &&
1352 stylen <= styleTABLESIZE && stylecheck[stylen] == stylestate)
1353 stylestate = styletable[stylen];
1355 stylestate = styledgoto[stylem];
1358 printf("styledebug: after reduction, shifting from state %d \
1359 to state %d\n", *stylessp, stylestate);
1361 if (stylessp >= styless + stylestacksize - 1)
1365 *++stylessp = stylestate;
1366 *++stylevsp = styleval;
1369 styleerror((char*)"yacc stack overflow");