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