1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-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 librararies 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 #ifdef REV_INFO
24 #ifndef lint
25 static char rcsid[] = "$XConsortium: wmlsynbld.c /main/9 1995/08/29 11:11:12 drk $"
26 #endif
27 #endif
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32
33 /*
34 * This module contains the programs which construct the syntactic
35 * representation of the WML input. All the routines are called as
36 * actions of the grammar productions.
37 *
38 * Since WML is so simple, no stack frame technology is used. Instead,
39 * context is maintained by global pointers and vectors which contain
40 * the intermediate results of parsing a statement. At most, these
41 * contain an object being constructed (for instance a class descriptor)
42 * and a subobject (for instance a resource reference in a class).
43 *
44 * Results are communicated back using the global error count
45 * wml_err_count, and the ordered handle list wml_synobj_ptr.
46 */
47
48
49 #include "wml.h"
50 #include "wmlparse.h"
51
52 #if defined(__STDC__)
53 #include <stdlib.h>
54 #endif
55 #include <stdio.h>
56
57
58 /*
59 * Globals used during WML parsing.
60 */
61
62 /*
63 * Character arrays and other variables to hold lexemes
64 * are defined in wmllex.l
65 */
66
67 /*
68 * Current principal object being constructed
69 * Current subobject
70 */
71 ObjectPtr wml_cur_obj;
72 ObjectPtr wml_cur_subobj;
73
74
75
76 /*
77 * Routine to create a class descriptor. The result is placed in both
78 * wml_cur_obj and wml_synobj.
79 *
80 * name the class name
81 * ctype class type, one of METACLASS | WIDGET | GADGET
82 */
83
wmlCreateClass(name,ctype)84 void wmlCreateClass (name, ctype)
85 char *name;
86 int ctype;
87
88 {
89
90 WmlSynClassDefPtr cdesc; /* new class descriptor */
91
92
93 /*
94 * Initialize the new class descriptor. Enter it in the object list.
95 * Set the current object global to the descriptor.
96 */
97 cdesc = (WmlSynClassDefPtr) malloc (sizeof(WmlSynClassDef));
98 cdesc->validation = WmlClassDefValid;
99 cdesc->rslvdef = NULL;
100 switch ( ctype )
101 {
102 case METACLASS:
103 cdesc->type = WmlClassTypeMetaclass;
104 break;
105 case WIDGET:
106 cdesc->type = WmlClassTypeWidget;
107 break;
108 case GADGET:
109 cdesc->type = WmlClassTypeGadget;
110 break;
111 default:
112 printf ("\nwmlCreateClass: unknown class type %d", ctype);
113 return;
114 break;
115 }
116 cdesc->dialog = FALSE;
117 cdesc->name = wmlAllocateString (name);
118 cdesc->superclass = NULL;
119 cdesc->parentclass = NULL;
120 cdesc->widgetclass = NULL;
121 cdesc->int_lit = NULL;
122 cdesc->convfunc = NULL;
123 cdesc->docname = NULL;
124 cdesc->ctrlmapto = NULL;
125 cdesc->alias_cnt = 0;
126 cdesc->alias_list = NULL;
127 cdesc->controls = NULL;
128 cdesc->resources = NULL;
129 cdesc->children = NULL;
130
131 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
132 {
133 printf ("\nDuplicate name %s found", name);
134 return;
135 }
136 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)cdesc);
137 wml_cur_obj = (ObjectPtr) cdesc;
138 wml_cur_subobj = NULL;
139
140 return;
141
142 }
143
144
145
146 /*
147 * Routine to create a resource descriptor. The result is placed in both
148 * wml_cur_obj and wml_synobj.
149 *
150 * name the resource name
151 * rtype resource type, one of
152 * ARGUMENT | REASON | CONSTRAINT | SUBRESOURCE
153 */
154
wmlCreateResource(name,rtype)155 void wmlCreateResource (name, rtype)
156 char *name;
157 int rtype;
158
159 {
160
161 WmlSynResourceDefPtr rdesc; /* new resource descriptor */
162
163
164 /*
165 * Initialize the new resource descriptor. Enter it in the object list.
166 * Set the current object global to the descriptor.
167 */
168 rdesc = (WmlSynResourceDefPtr) malloc (sizeof(WmlSynResourceDef));
169 rdesc->validation = WmlResourceDefValid;
170 rdesc->rslvdef = NULL;
171 switch ( rtype )
172 {
173 case ARGUMENT:
174 rdesc->type = WmlResourceTypeArgument;
175 rdesc->xrm_support = WmlAttributeTrue;
176 break;
177 case REASON:
178 rdesc->type = WmlResourceTypeReason;
179 rdesc->xrm_support = WmlAttributeFalse;
180 break;
181 case CONSTRAINT:
182 rdesc->type = WmlResourceTypeConstraint;
183 rdesc->xrm_support = WmlAttributeTrue;
184 break;
185 case SUBRESOURCE:
186 rdesc->type = WmlResourceTypeSubResource;
187 rdesc->xrm_support = WmlAttributeTrue;
188 break;
189 default:
190 printf ("\nwmlCreateResource: unknown resource type %d", rtype);
191 return;
192 break;
193 }
194 rdesc->name = wmlAllocateString (name);
195 rdesc->datatype = NULL;
196 rdesc->int_lit = NULL;
197 rdesc->resliteral = wmlAllocateString (name); /* default to name */
198 rdesc->enumset = NULL;
199 rdesc->docname = NULL;
200 rdesc->related = NULL;
201 rdesc->dflt = NULL;
202 rdesc->alias_cnt = 0;
203 rdesc->alias_list = NULL;
204
205 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
206 {
207 printf ("\nDuplicate name %s found", name);
208 return;
209 }
210 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)rdesc);
211 wml_cur_obj = (ObjectPtr) rdesc;
212 wml_cur_subobj = NULL;
213
214 return;
215
216 }
217
218
219
220 /*
221 * Routine to create a datatype descriptor. The result is placed in both
222 * wml_cur_obj and wml_synobj.
223 *
224 * name the datatype name
225 */
226
wmlCreateDatatype(name)227 void wmlCreateDatatype (name)
228 char *name;
229
230 {
231
232 WmlSynDataTypeDefPtr ddesc; /* new datatype descriptor */
233
234
235 /*
236 * Initialize the new datatype descriptor. Enter it in the object list.
237 * Set the current object global to the descriptor.
238 */
239 ddesc = (WmlSynDataTypeDefPtr) malloc (sizeof(WmlSynDataTypeDef));
240 ddesc->validation = WmlDataTypeDefValid;
241 ddesc->rslvdef = NULL;
242 ddesc->name = wmlAllocateString (name);
243 ddesc->int_lit = NULL;
244 ddesc->docname = NULL;
245 ddesc->xrm_support = WmlAttributeTrue;
246
247 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
248 {
249 printf ("\nDuplicate name %s found", name);
250 return;
251 }
252 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)ddesc);
253 wml_cur_obj = (ObjectPtr) ddesc;
254 wml_cur_subobj = NULL;
255
256 return;
257
258 }
259
260
261 /*
262 * Routine to create a child descriptor. The result is placed in both
263 * wml_cur_obj and wml_synobj.
264 *
265 * name the child name
266 * class the class name
267 */
268
wmlCreateChild(name,class)269 void wmlCreateChild (name, class)
270 char *name;
271 char *class;
272 {
273
274 WmlSynChildDefPtr chdesc; /* new child descriptor */
275
276
277 /*
278 * Initialize the new child descriptor. Enter it in the object list.
279 * Set the current object global to the descriptor.
280 */
281 chdesc = (WmlSynChildDefPtr) malloc (sizeof(WmlSynChildDef));
282 chdesc->validation = WmlChildDefValid;
283 chdesc->rslvdef = NULL;
284 chdesc->name = wmlAllocateString (name);
285 chdesc->class = wmlAllocateString (class);
286
287 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
288 {
289 printf ("\nDuplicate name %s found", name);
290 return;
291 }
292 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)chdesc);
293 wml_cur_obj = (ObjectPtr) chdesc;
294 wml_cur_subobj = NULL;
295
296 return;
297
298 }
299
300
301
302 /*
303 * Routine to create a controls list descriptor. The result is placed in both
304 * wml_cur_obj and wml_synobj.
305 *
306 * name the controls list name
307 */
308
wmlCreateOrAppendCtrlList(name)309 void wmlCreateOrAppendCtrlList (name)
310 char *name;
311
312 {
313 int idx;
314 WmlSynCtrlListDefPtr cdesc; /* new CtrlList descriptor */
315
316 idx = wmlFindInHList(wml_synobj_ptr,name);
317
318 if (idx < 0 ) {
319 /* Didn't find list */
320
321 /*
322 * Initialize the new CtrlList descriptor. Enter it in the object list.
323 * Set the current object global to the descriptor.
324 */
325 cdesc = (WmlSynCtrlListDefPtr) malloc (sizeof(WmlSynCtrlListDef));
326 cdesc->validation = WmlCtrlListDefValid;
327 cdesc->rslvdef = NULL;
328 cdesc->name = wmlAllocateString (name);
329 cdesc->controls = NULL;
330
331 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)cdesc);
332 } else {
333 cdesc = (WmlSynCtrlListDefPtr) wml_synobj_ptr -> hvec[idx].objptr;
334 printf ("\nAppending to list name %s", name);
335 }
336
337 wml_cur_obj = (ObjectPtr) cdesc;
338 wml_cur_subobj = NULL;
339
340 return;
341
342 }
343
344
345
346 /*
347 * Routine to create an enumeration set descriptor. The result is placed in both
348 * wml_cur_obj and wml_synobj.
349 *
350 * name the enumeration set name
351 * type data type, must match a data type name
352 */
353
wmlCreateEnumSet(name,dtype)354 void wmlCreateEnumSet (name, dtype)
355 char *name;
356 char *dtype;
357
358 {
359
360 WmlSynEnumSetDefPtr esdesc; /* new enumeration set descriptor */
361
362
363 /*
364 * Initialize the new resource descriptor. Enter it in the object list.
365 * Set the current object global to the descriptor.
366 */
367 esdesc = (WmlSynEnumSetDefPtr) malloc (sizeof(WmlSynEnumSetDef));
368 esdesc->validation = WmlEnumSetDefValid;
369 esdesc->rslvdef = NULL;
370 esdesc->name = wmlAllocateString (name);
371 esdesc->datatype = wmlAllocateString (dtype);
372 esdesc->values = NULL;
373
374 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
375 {
376 printf ("\nDuplicate name %s found", name);
377 return;
378 }
379 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)esdesc);
380 wml_cur_obj = (ObjectPtr) esdesc;
381 wml_cur_subobj = NULL;
382
383 return;
384
385 }
386
387
388
389 /*
390 * Routine to create an enumeration value descriptor. The result is placed in both
391 * wml_cur_obj and wml_synobj.
392 *
393 * name the enumeration value name
394 */
395
wmlCreateEnumValue(name)396 void wmlCreateEnumValue (name)
397 char *name;
398
399 {
400
401 WmlSynEnumValueDefPtr evdesc; /* new enumeration value descriptor */
402
403
404 /*
405 * Initialize the new resource descriptor. Enter it in the object list.
406 * Set the current object global to the descriptor.
407 */
408 evdesc = (WmlSynEnumValueDefPtr) malloc (sizeof(WmlSynEnumValueDef));
409 evdesc->validation = WmlEnumValueDefValid;
410 evdesc->rslvdef = NULL;
411 evdesc->name = wmlAllocateString (name);
412 evdesc->enumlit = wmlAllocateString (name); /* defaults to name */
413
414 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
415 {
416 printf ("\nDuplicate name %s found", name);
417 return;
418 }
419 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)evdesc);
420 wml_cur_obj = (ObjectPtr) evdesc;
421 wml_cur_subobj = NULL;
422
423 return;
424
425 }
426
427
428
429 /*
430 * Routine to create a charset descriptor. The result is placed in both
431 * wml_cur_obj and wml_synobj.
432 *
433 * name the charset name
434 */
435
wmlCreateCharset(name)436 void wmlCreateCharset (name)
437 char *name;
438
439 {
440
441 WmlSynCharSetDefPtr ddesc; /* new charset descriptor */
442
443
444 /*
445 * Initialize the new charset descriptor. Enter it in the object list.
446 * Set the current object global to the descriptor.
447 */
448 ddesc = (WmlSynCharSetDefPtr) malloc (sizeof(WmlSynCharSetDef));
449 ddesc->validation = WmlCharSetDefValid;
450 ddesc->rslvdef = NULL;
451 ddesc->name = wmlAllocateString (name);
452 ddesc->int_lit = NULL;
453 ddesc->xms_name = NULL;
454 ddesc->direction = WmlCharSetDirectionLtoR;
455 ddesc->parsedirection = WmlAttributeUnspecified;
456 ddesc->charsize = WmlCharSizeOneByte;
457 ddesc->alias_cnt = 0;
458 ddesc->alias_list = NULL;
459
460 if ( wmlFindInHList(wml_synobj_ptr,name) >= 0 )
461 {
462 printf ("\nDuplicate name %s found", name);
463 return;
464 }
465 wmlInsertInHList (wml_synobj_ptr, name, (ObjectPtr)ddesc);
466 wml_cur_obj = (ObjectPtr) ddesc;
467 wml_cur_subobj = NULL;
468
469 return;
470
471 }
472
473
474
475 /*
476 * Routine to set an attribute in a class descriptor.
477 *
478 * This routine sets the given attribute in the current object, which
479 * must be a class descriptor. The current object and subobject do not
480 * change.
481 *
482 * attrid oneof SUPERCLASS | INTERNALLITERAL | DOCNAME |
483 * CONVFUNC | WIDGETCLASS | DIALOGCLASS |
484 * CTRLMAPSRESOURCE
485 * val value of the attribute, usually a string
486 */
487
wmlAddClassAttribute(attrid,val)488 void wmlAddClassAttribute (attrid, val)
489 int attrid;
490 char *val;
491
492 {
493
494 WmlSynClassDefPtr cdesc; /* the class descriptor */
495 char **synlist; /* ALIAS pointer list */
496
497
498 /*
499 * Acquire the current class descriptor
500 */
501 if ( wml_cur_obj == NULL )
502 {
503 printf ("\nwmlAddClassAttribute: NULL current object");
504 return;
505 }
506 cdesc = (WmlSynClassDefPtr) wml_cur_obj;
507 if ( cdesc->validation != WmlClassDefValid )
508 {
509 printf ("\nwmlAddClassAttribute: %d not a class descriptor",
510 cdesc->validation);
511 return;
512 }
513
514 /*
515 * Set the appropriate resource
516 */
517 switch ( attrid )
518 {
519 case SUPERCLASS:
520 cdesc->superclass = wmlAllocateString (val);
521 break;
522 case PARENTCLASS:
523 cdesc->parentclass = wmlAllocateString (val);
524 break;
525 case INTERNALLITERAL:
526 cdesc->int_lit = wmlAllocateString (val);
527 break;
528 case CONVFUNC:
529 cdesc->convfunc = wmlAllocateString (val);
530 break;
531 case DOCNAME:
532 cdesc->docname = wmlAllocateString (val);
533 break;
534 case WIDGETCLASS:
535 cdesc->widgetclass = wmlAllocateString (val);
536 break;
537 case DIALOGCLASS:
538 switch ( (long)val )
539 {
540 case ATTRTRUE:
541 cdesc->dialog = TRUE;
542 break;
543 }
544 break;
545 case CTRLMAPSRESOURCE:
546 cdesc->ctrlmapto = wmlAllocateString (val);
547 break;
548 case ALIAS:
549 if ( cdesc->alias_cnt == 0 )
550 synlist = (char **) malloc (sizeof(char *));
551 else
552 synlist = (char **)
553 realloc (cdesc->alias_list,
554 (cdesc->alias_cnt+1)*sizeof(char **));
555 synlist[cdesc->alias_cnt] = wmlAllocateString (val);
556 cdesc->alias_cnt += 1;
557 cdesc->alias_list = synlist;
558 break;
559 }
560
561 return;
562 }
563
564
565
566 /*
567 * Routine to add a control specification to the current class.
568 * The current object must be a class descriptor. The entry name
569 * is added to the controls list. The control specification becomes the
570 * current subobject.
571 *
572 * name the name of the controlled class
573 */
574
wmlAddClassControl(name)575 void wmlAddClassControl (name)
576 char *name;
577
578 {
579
580 WmlSynClassDefPtr cdesc; /* the class descriptor */
581 WmlSynClassCtrlDefPtr ctrlelm; /* controls element */
582
583
584 /*
585 * Acquire the current class descriptor
586 */
587 if ( wml_cur_obj == NULL )
588 {
589 printf ("\nwmlAddClassControl: NULL current object");
590 return;
591 }
592 cdesc = (WmlSynClassDefPtr) wml_cur_obj;
593 if ( cdesc->validation != WmlClassDefValid )
594 {
595 printf ("\nwmlAddClassControl: %d not a class descriptor",
596 cdesc->validation);
597 return;
598 }
599
600 /*
601 * Add the control to the control list
602 */
603 ctrlelm = (WmlSynClassCtrlDefPtr) malloc (sizeof(WmlSynClassCtrlDef));
604 ctrlelm->validation = WmlClassCtrlDefValid;
605 ctrlelm->next = cdesc->controls;
606 cdesc->controls = ctrlelm;
607 ctrlelm->name = wmlAllocateString (name);
608
609 /*
610 * This becomes the current subobject
611 */
612 wml_cur_subobj = (ObjectPtr) ctrlelm;
613
614 return;
615
616 }
617
618
619
620 /*
621 * Add a resource descriptor to a class.
622 * The current object must be a class descriptor. Create and add a
623 * resource descriptor, which becomes the current subobject. It is not
624 * entered in the named object list.
625 *
626 * name the resource name
627 */
628
wmlAddClassResource(name)629 void wmlAddClassResource (name)
630 char *name;
631
632 {
633
634 WmlSynClassDefPtr cdesc; /* the class descriptor */
635 WmlSynClassResDefPtr rdesc; /* the resource reference descriptor */
636
637
638 /*
639 * Acquire the current class descriptor
640 */
641 if ( wml_cur_obj == NULL )
642 {
643 printf ("\nwmlAddClassResource: NULL current object");
644 return;
645 }
646 cdesc = (WmlSynClassDefPtr) wml_cur_obj;
647 if ( cdesc->validation != WmlClassDefValid )
648 {
649 printf ("\nwmlAddClassResource: %d not a class descriptor",
650 cdesc->validation);
651 return;
652 }
653
654 /*
655 * Add the resource to the resource list
656 */
657 rdesc = (WmlSynClassResDefPtr) malloc (sizeof(WmlSynClassResDef));
658 rdesc->validation = WmlClassResDefValid;
659 rdesc->name = wmlAllocateString (name);
660 rdesc->type = NULL;
661 rdesc->dflt = NULL;
662 rdesc->exclude = WmlAttributeUnspecified;
663
664 rdesc->next = cdesc->resources;
665 cdesc->resources = rdesc;
666
667 /*
668 * This becomes the current subobject
669 */
670 wml_cur_subobj = (ObjectPtr) rdesc;
671
672 return;
673
674 }
675
676
677 /*
678 * Add a child descriptor to a class.
679 * The current object must be a class descriptor. Create and add a
680 * child descriptor, which becomes the current subobject. It is not
681 * entered in the named object list.
682 *
683 * name the resource name
684 */
685
wmlAddClassChild(name)686 void wmlAddClassChild (name)
687 char *name;
688
689 {
690
691 WmlSynClassDefPtr cdesc; /* the class descriptor */
692 WmlSynClassChildDefPtr chdesc; /* the child reference descriptor */
693
694
695 /*
696 * Acquire the current class descriptor
697 */
698 if ( wml_cur_obj == NULL )
699 {
700 printf ("\nwmlAddClassResource: NULL current object");
701 return;
702 }
703 cdesc = (WmlSynClassDefPtr) wml_cur_obj;
704 if ( cdesc->validation != WmlClassDefValid )
705 {
706 printf ("\nwmlAddClassResource: %d not a class descriptor",
707 cdesc->validation);
708 return;
709 }
710
711 /*
712 * Add the child to the child list
713 */
714 chdesc = (WmlSynClassChildDefPtr) malloc (sizeof(WmlSynClassChildDef));
715 chdesc->validation = WmlClassChildDefValid;
716 chdesc->name = wmlAllocateString (name);
717
718 chdesc->next = cdesc->children;
719 cdesc->children = chdesc;
720
721 /*
722 * This becomes the current subobject
723 */
724 wml_cur_subobj = (ObjectPtr) chdesc;
725
726 return;
727
728 }
729
730
731
732 /*
733 * This routine sets an attribute in the current class resource descriptor.
734 * The current subobject must be a class resource descriptor. The
735 * named attribute is set.
736 *
737 * attrid one of TYPE | DEFAULT | EXCLUDE
738 * val attribute value, usually a string. Must be
739 * ATTRTRUE | ATTRFALSE for EXCLUDE.
740 */
wmlAddClassResourceAttribute(attrid,val)741 void wmlAddClassResourceAttribute (attrid, val)
742 int attrid;
743 char *val;
744
745 {
746
747 WmlSynClassResDefPtr rdesc; /* current class resource descriptor */
748 long excval; /* EXCLUDE value */
749
750
751 /*
752 * Acquire the descriptor from the current subobject.
753 */
754 if ( wml_cur_subobj == NULL )
755 {
756 printf ("\nwmlAddClassResourceAttribute: NULL current subobject");
757 return;
758 }
759 rdesc = (WmlSynClassResDefPtr) wml_cur_subobj;
760 if ( rdesc->validation != WmlClassResDefValid )
761 {
762 printf
763 ("\nwmlAddClassResourceAttribute: %d not a class resource descriptor",
764 rdesc->validation);
765 return;
766 }
767
768 switch ( attrid )
769 {
770 case TYPE:
771 rdesc->type = wmlAllocateString (val);
772 break;
773 case DEFAULT:
774 rdesc->dflt = wmlAllocateString (val);
775 break;
776 case EXCLUDE:
777 excval = (long) val;
778 switch ( excval )
779 {
780 case ATTRTRUE:
781 rdesc->exclude = WmlAttributeTrue;
782 break;
783 case ATTRFALSE:
784 rdesc->exclude = WmlAttributeFalse;
785 break;
786 default:
787 printf ("\nwmlAddClassResourceAttribute: bad EXCLUDE value %ld",
788 excval);
789 return;
790 break;
791 }
792 break;
793 default:
794 printf ("\nwmlAddClassResourceAttribute: unknown attrid %d", attrid);
795 return;
796 break;
797 }
798
799 return;
800
801 }
802
803
804
805
806 /*
807 * Routine to set an attribute in a resource descriptor.
808 *
809 * This routine sets the given attribute in the current object, which
810 * must be a resource descriptor. The current object and subobject do not
811 * change.
812 *
813 * attrid oneof TYPE | RESOURCELITERAL | INTERNALLITERAL |
814 * RELATED | DOCNAME | DEFAULT | XRMRESOURCE | ALIAS |
815 * ENUMERATIONSET
816 * val value of the attribute, usually a string
817 */
818
wmlAddResourceAttribute(attrid,val)819 void wmlAddResourceAttribute (attrid, val)
820 int attrid;
821 char *val;
822
823 {
824
825 WmlSynResourceDefPtr rdesc; /* the resource descriptor */
826 long xrmval; /* XRMRESOURCE value */
827 char **synlist; /* ALIAS pointer list */
828
829
830 /*
831 * Acquire the current resource descriptor
832 */
833 if ( wml_cur_obj == NULL )
834 {
835 printf ("\nwmlAddResourceAttribute: NULL current object");
836 return;
837 }
838 rdesc = (WmlSynResourceDefPtr) wml_cur_obj;
839 if ( rdesc->validation != WmlResourceDefValid )
840 {
841 printf ("\nwmlAddResourceAttribute: %d not a resource descriptor",
842 rdesc->validation);
843 return;
844 }
845
846 /*
847 * Set the appropriate resource
848 */
849 switch ( attrid )
850 {
851 case TYPE:
852 rdesc->datatype = wmlAllocateString (val);
853 break;
854 case INTERNALLITERAL:
855 rdesc->int_lit = wmlAllocateString (val);
856 break;
857 case RESOURCELITERAL:
858 rdesc->resliteral = wmlAllocateString (val);
859 break;
860 case ENUMERATIONSET:
861 rdesc->enumset = wmlAllocateString (val);
862 break;
863 case DOCNAME:
864 rdesc->docname = wmlAllocateString (val);
865 break;
866 case RELATED:
867 rdesc->related = wmlAllocateString (val);
868 break;
869 case DEFAULT:
870 rdesc->dflt = wmlAllocateString (val);
871 break;
872 case XRMRESOURCE:
873 xrmval = (long) val;
874 switch ( xrmval )
875 {
876 case ATTRTRUE:
877 rdesc->xrm_support = WmlAttributeTrue;
878 break;
879 case ATTRFALSE:
880 rdesc->xrm_support = WmlAttributeFalse;
881 break;
882 default:
883 printf
884 ("\nwmlAddResourceAttribute: bad XRMRESOURCE value %ld",
885 xrmval);
886 return;
887 break;
888 }
889 break;
890 case ALIAS:
891 if ( rdesc->alias_cnt == 0 )
892 synlist = (char **) malloc (sizeof(char *));
893 else
894 synlist = (char **)
895 realloc (rdesc->alias_list,
896 (rdesc->alias_cnt+1)*sizeof(char **));
897 synlist[rdesc->alias_cnt] = wmlAllocateString (val);
898 rdesc->alias_cnt += 1;
899 rdesc->alias_list = synlist;
900 break;
901 default:
902 printf ("\nwmlAddResourceAttribute: unknown attrid %d", attrid);
903 return;
904 break;
905 }
906
907 return;
908 }
909
910
911
912 /*
913 * Routine to set an attribute in a datatype descriptor.
914 *
915 * This routine sets the given attribute in the current object, which
916 * must be a datatype descriptor. The current object and subobject do not
917 * change.
918 *
919 * attrid oneof INTERNALLITERAL | DOCNAME | XRMRESOURCE
920 * val value of the attribute, usually a string
921 */
922
wmlAddDatatypeAttribute(attrid,val)923 void wmlAddDatatypeAttribute (attrid, val)
924 int attrid;
925 char *val;
926
927 {
928
929 WmlSynDataTypeDefPtr ddesc; /* the datatype descriptor */
930 long xrmval; /* XRMRESOURCE value */
931
932
933 /*
934 * Acquire the current datatype descriptor
935 */
936 if ( wml_cur_obj == NULL )
937 {
938 printf ("\nwmlAddDatatypeAttribute: NULL current object");
939 return;
940 }
941 ddesc = (WmlSynDataTypeDefPtr) wml_cur_obj;
942 if ( ddesc->validation != WmlDataTypeDefValid )
943 {
944 printf ("\nwmlAddDatatypeAttribute: %d not a datatype descriptor",
945 ddesc->validation);
946 return;
947 }
948
949 /*
950 * Set the appropriate slot
951 */
952 switch ( attrid )
953 {
954 case INTERNALLITERAL:
955 ddesc->int_lit = wmlAllocateString (val);
956 break;
957 case DOCNAME:
958 ddesc->docname = wmlAllocateString (val);
959 break;
960 case XRMRESOURCE:
961 xrmval = (long) val;
962 switch ( xrmval )
963 {
964 case ATTRTRUE:
965 ddesc->xrm_support = WmlAttributeTrue;
966 break;
967 case ATTRFALSE:
968 ddesc->xrm_support = WmlAttributeFalse;
969 break;
970 default:
971 printf
972 ("\nwmlAddDatatypeAttribute: bad XRMRESOURCE value %ld",
973 xrmval);
974 return;
975 break;
976 }
977 break;
978 default:
979 printf ("\nwmlAddDatatypeAttribute: unknown attrid %d", attrid);
980 return;
981 break;
982 }
983
984 return;
985 }
986
987
988
989 /*
990 * Routine to add a control specification to the current controls list.
991 * The current object must be a controls list descriptor. The entry name
992 * is added to the controls list. The new element becomes the current
993 * subobject.
994 *
995 * name the name of the controlled class
996 */
997
wmlAddCtrlListControl(name)998 void wmlAddCtrlListControl (name)
999 char *name;
1000
1001 {
1002
1003 WmlSynCtrlListDefPtr cdesc; /* the controls list descriptor */
1004 WmlSynClassCtrlDefPtr ctrlelm; /* controls element */
1005
1006
1007 /*
1008 * Acquire the current controls list descriptor
1009 */
1010 if ( wml_cur_obj == NULL )
1011 {
1012 printf ("\nwmlAddCtrlListControl: NULL current object");
1013 return;
1014 }
1015 cdesc = (WmlSynCtrlListDefPtr) wml_cur_obj;
1016 if ( cdesc->validation != WmlCtrlListDefValid )
1017 {
1018 printf ("\nwmlAddCtrlListControl: %d not a controls list descriptor",
1019 cdesc->validation);
1020 return;
1021 }
1022
1023 /*
1024 * Add the control to the control list
1025 */
1026 ctrlelm = (WmlSynClassCtrlDefPtr) malloc (sizeof(WmlSynClassCtrlDef));
1027 ctrlelm->validation = WmlClassCtrlDefValid;
1028 ctrlelm->next = cdesc->controls;
1029 cdesc->controls = ctrlelm;
1030 ctrlelm->name = wmlAllocateString (name);
1031
1032 /*
1033 * This becomes the current subobject
1034 */
1035 wml_cur_subobj = (ObjectPtr) ctrlelm;
1036
1037 return;
1038
1039 }
1040
1041
1042
1043 /*
1044 * Routine to add an enumeration value to the current enumeration set
1045 * The current object must be an enumeration set descriptor. The entry name
1046 * is added to the the enumeration value list.
1047 *
1048 * name the name of the enumeration value
1049 */
wmlAddEnumSetValue(name)1050 void wmlAddEnumSetValue (name)
1051 char *name;
1052
1053 {
1054
1055 WmlSynEnumSetDefPtr esdesc; /* the enumeration set descriptor */
1056 WmlSynEnumSetValDefPtr evelm; /* EnumSet EnumValue element */
1057
1058 /*
1059 * Acquire the current enumeration set descriptor
1060 */
1061 if ( wml_cur_obj == NULL )
1062 {
1063 printf ("\nwmlAddEnumSetValue: NULL current object");
1064 return;
1065 }
1066 esdesc = (WmlSynEnumSetDefPtr) wml_cur_obj;
1067 if ( esdesc->validation != WmlEnumSetDefValid )
1068 {
1069 printf ("\nwmlAddEnumSetValue: %d not an enumeration set descriptor",
1070 esdesc->validation);
1071 return;
1072 }
1073
1074 /*
1075 * Add the value to the set
1076 */
1077 evelm = (WmlSynEnumSetValDefPtr) malloc (sizeof(WmlSynEnumSetValDef));
1078 evelm->validation = WmlEnumValueDefValid;
1079 evelm->next = esdesc->values;
1080 esdesc->values = evelm;
1081 evelm->name = wmlAllocateString (name);
1082
1083 /*
1084 * Becomes current subobject
1085 */
1086 wml_cur_subobj = (ObjectPtr) evelm;
1087
1088 }
1089
1090
1091
1092 /*
1093 * Routine to set an attribute in an enumeration value
1094 *
1095 * This routine sets the given attribute in the current object, which must
1096 * be an enumeration value descriptor. The current object does not change.
1097 *
1098 * attrid oneof ENUMLITERAL
1099 * val value of the attribute, usually a string
1100 */
wmlAddEnumValueAttribute(attrid,val)1101 void wmlAddEnumValueAttribute (attrid, val)
1102 int attrid;
1103 char *val;
1104
1105 {
1106
1107 WmlSynEnumValueDefPtr evdesc; /* the enumeration value descriptor */
1108
1109
1110 /*
1111 * Acquire the current enumeration value descriptor
1112 */
1113 if ( wml_cur_obj == NULL )
1114 {
1115 printf ("\nwmlAddEnumValueAttribute: NULL current object");
1116 return;
1117 }
1118 evdesc = (WmlSynEnumValueDefPtr) wml_cur_obj;
1119 if ( evdesc->validation != WmlEnumValueDefValid )
1120 {
1121 printf ("\nwmlAddEnumValueAttribute: %d not an enumeration value descriptor",
1122 evdesc->validation);
1123 return;
1124 }
1125
1126 /*
1127 * Set the appropriate slot
1128 */
1129 switch ( attrid )
1130 {
1131 case ENUMLITERAL:
1132 evdesc->enumlit = wmlAllocateString (val);
1133 break;
1134 default:
1135 printf ("\nwmlAddEnumValueAttribute: unknown attrid %d", attrid);
1136 return;
1137 break;
1138 }
1139
1140 return;
1141
1142 }
1143
1144
1145
1146 /*
1147 * Routine to set an attribute in a charset descriptor.
1148 *
1149 * This routine sets the given attribute in the current object, which
1150 * must be a charset descriptor. The current object and subobject do not
1151 * change.
1152 *
1153 * attrid oneof INTERNALLITERAL | ALIAS | XMSTRINGCHARSETNAME |
1154 * DIRECTION | PARSEDIRECTION | CHARACTERSIZE
1155 * val value of the attribute, usually a string
1156 */
1157
wmlAddCharsetAttribute(attrid,val)1158 void wmlAddCharsetAttribute (attrid, val)
1159 int attrid;
1160 char *val;
1161
1162 {
1163
1164 WmlSynCharSetDefPtr ddesc; /* the charset descriptor */
1165 char **synlist; /* ALIAS pointer list */
1166 long atrval; /* attribute value */
1167
1168
1169 /*
1170 * Acquire the current charset descriptor
1171 */
1172 if ( wml_cur_obj == NULL )
1173 {
1174 printf ("\nwmlAddCharSetAttribute: NULL current object");
1175 return;
1176 }
1177 ddesc = (WmlSynCharSetDefPtr) wml_cur_obj;
1178 if ( ddesc->validation != WmlCharSetDefValid )
1179 {
1180 printf ("\nwmlAddCharsetAttribute: %d not a CharSet descriptor",
1181 ddesc->validation);
1182 return;
1183 }
1184
1185 /*
1186 * Set the appropriate slot
1187 */
1188 switch ( attrid )
1189 {
1190 case INTERNALLITERAL:
1191 ddesc->int_lit = wmlAllocateString (val);
1192 break;
1193 case ALIAS:
1194 if ( ddesc->alias_cnt == 0 )
1195 synlist = (char **) malloc (sizeof(char *));
1196 else
1197 synlist = (char **)
1198 realloc (ddesc->alias_list,
1199 (ddesc->alias_cnt+1)*sizeof(char **));
1200 synlist[ddesc->alias_cnt] = wmlAllocateString (val);
1201 ddesc->alias_cnt += 1;
1202 ddesc->alias_list = synlist;
1203 break;
1204 case XMSTRINGCHARSETNAME:
1205 ddesc->xms_name = wmlAllocateString (val);
1206 break;
1207 case DIRECTION:
1208 atrval = (long) val;
1209 switch ( atrval )
1210 {
1211 case LEFTTORIGHT:
1212 ddesc->direction = WmlCharSetDirectionLtoR;
1213 break;
1214 case RIGHTTOLEFT:
1215 ddesc->direction = WmlCharSetDirectionRtoL;
1216 break;
1217 default:
1218 printf
1219 ("\nwmlAddCharsetAttribute: bad DIRECTION value %ld",
1220 atrval);
1221 return;
1222 break;
1223 }
1224 break;
1225 case PARSEDIRECTION:
1226 atrval = (long) val;
1227 switch ( atrval )
1228 {
1229 case LEFTTORIGHT:
1230 ddesc->parsedirection = WmlCharSetDirectionLtoR;
1231 break;
1232 case RIGHTTOLEFT:
1233 ddesc->parsedirection = WmlCharSetDirectionRtoL;
1234 break;
1235 default:
1236 printf
1237 ("\nwmlAddCharsetAttribute: bad PARSEDIRECTION value %ld",
1238 atrval);
1239 return;
1240 break;
1241 }
1242 break;
1243 case CHARACTERSIZE:
1244 atrval = (long) val;
1245 switch ( atrval )
1246 {
1247 case ONEBYTE:
1248 ddesc->charsize = WmlCharSizeOneByte;
1249 break;
1250 case TWOBYTE:
1251 ddesc->charsize = WmlCharSizeTwoByte;
1252 break;
1253 case MIXED1_2BYTE:
1254 ddesc->charsize = WmlCharSizeMixed1_2Byte;
1255 break;
1256 default:
1257 printf
1258 ("\nwmlAddCharsetAttribute: bad CHARACTERSIZE value %ld",
1259 atrval);
1260 return;
1261 break;
1262 }
1263 break;
1264 default:
1265 printf ("\nwmlAddCharsetAttribute: unknown attrid %d", attrid);
1266 return;
1267 break;
1268 }
1269
1270 return;
1271 }
1272
1273
1274
1275 /*
1276 * The error reporting routine.
1277 *
1278 * For now, issue a very simple error message
1279 */
1280
LexIssueError(tkn)1281 void LexIssueError (tkn)
1282 int tkn;
1283
1284 {
1285
1286 switch ( tkn )
1287 {
1288 case SEMICOLON:
1289 printf ("\n Syntax error: expected a semicolon");
1290 break;
1291 case RBRACE:
1292 printf ("\n Syntax error: expected a right brace");
1293 break;
1294 case 0:
1295 printf ("\nSyntax error: Couldn't recognize a section name, probably fatal");
1296 break;
1297 }
1298 printf ("\n\tnear name='%s', value='%s', line %d",
1299 yynameval, yystringval, wml_line_count);
1300
1301 wml_err_count += 1;
1302
1303 return;
1304
1305 }
1306