63ed6081bf6ef5510e291654b08b625d0e7096b5
[oweals/cde.git] / cde / programs / dthelp / parser.ccdf / htag / build / build.h
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 /* $XConsortium: build.h /main/3 1995/11/08 11:11:27 rswiston $ */
24 /*
25               Copyright 1986 Tandem Computers Incorporated.
26 This product and information is proprietary of Tandem Computers Incorporated.
27                    Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
28 */
29
30 /* Build.h is the primary include file for allocation of global variables
31    for program BUILD. */
32
33
34 #if defined(BUILDEF)
35 #define BUILDEXTERN
36 #define BUILDINIT(a) = a
37 #else
38 #define BUILDEXTERN extern
39 #define BUILDINIT(a)
40 #endif
41
42 #include <stdio.h>
43 #include "basic.h"
44 #include "trie.h"
45 #include "common.h"
46
47 /* Defined types */
48 typedef struct arc ARC ;
49 typedef struct state STATE ;
50 typedef struct tree TREE ;
51 typedef struct statelist STATELIST ;
52 typedef struct parameter PARAMETER ;
53 typedef struct exception EXCEPTION ;
54 typedef struct ptype PTYPE ;
55 typedef struct eltstruct ELTSTRUCT ;
56 typedef struct lhsstruct LHS ;
57 typedef struct stack STACK ;
58 typedef struct srefstruct SREFSTRUCT ;
59 typedef struct srefdata SREFDATA ;
60 typedef struct mapstruct MAP ;
61 typedef struct andgroup ANDGROUP ;
62
63 /* Each item in a list of states contains value, a pointer to a state;
64    next, a pointer to the next item in the list; and level, which
65    indicates the level of nested subexpressions within the regular expression
66    when the state was added to the FSA. */
67 BUILDEXTERN struct statelist {
68   STATE *value ;
69   STATELIST *next ;
70   int level ;
71   } ;
72
73 struct stack {
74   STACK *oldtop ;
75   STATELIST *starts ;
76   STATELIST *finals ;
77   STATELIST *allfinal ;
78   STATELIST *newfinal ;
79   ARC *starta ;
80   } ;
81
82 BUILDEXTERN STACK bot
83 #if defined(BUILDEF)
84   = {
85   NULL, NULL, NULL, NULL, NULL, NULL
86   }
87 #endif
88   ;
89
90 BUILDEXTERN STACK *top BUILDINIT(&bot) ;
91
92 BUILDEXTERN int stacklevels BUILDINIT(0) ;
93
94
95 /* Used to report nondeterminism in and groups */
96 #define ANDCONFLICT 1
97 #define DATACONFLICT 2
98 #define ELTCONFLICT 3
99
100 /* Name of an element, and of the first element on the left-hand side of
101    the current rule */
102 #define thisrule lhs->elt->enptr
103  
104 /* Set declared entity type */
105 #define SETETYPE(p,t) adddefent(p) ; entity->type = t
106
107 /* Definitions for entities */
108
109 #define EMPTYMAP 1
110
111 #define ERREXIT 1
112
113 /* Prefix for default short reference map and entities */
114 #define M_PREFIX "M-"
115
116 /* State transition network generated by CONTEXT */
117 #define sparse
118 #include "sparse.h"
119
120 /* Function prototypes */
121 #include "proto.h"
122
123 /*  Frequently output strings */
124 #define ndif "}\n#endif\n  ;\n\n" 
125 #define SUBONE else fputs("[1] ;\n\n", dtd) ;
126
127 /* An array used to indicate which characters can appear within
128    element names */
129 #if defined(BUILDEF)
130 #include "chartype.h"
131 #else
132 extern M_CHARTYPE m_ctarray[M_CHARSETLEN] ;
133 #endif
134
135 /* Current state of the finite-state machine which controls BUILD */
136 BUILDEXTERN int curcon BUILDINIT(RULE) ;
137 BUILDEXTERN int m_token ;
138 BUILDEXTERN M_WCHAR scanval ;
139
140 /* Used to pass names and literals from the scanner */
141 BUILDEXTERN M_WCHAR name[M_NAMELEN + 1] ;
142 BUILDEXTERN M_WCHAR literal[M_LITLEN + 1] ;
143
144 /* Scanner buffer for read-ahead */
145 BUILDEXTERN int toundo BUILDINIT(0) ;
146 BUILDEXTERN int maxundo BUILDINIT(0) ;
147 /* Size of scanner buffer for read-ahead */
148 #define SAVECHAR 50
149 BUILDEXTERN int savechar[SAVECHAR] ;
150
151 /* Whether errors have occurred */
152 BUILDEXTERN LOGICAL errexit BUILDINIT(FALSE) ;
153
154 /* FSA storage */
155
156 /* Each state in an FSA is represented by a flag indicating whether it is
157    a final state, a pointer to a list of transitions from the state,
158    and a flag that indicates whether parsed character data is possible
159    from the state */
160 BUILDEXTERN struct state {
161   LOGICAL final ;
162   LOGICAL datacontent ;
163   LOGICAL frompcdata ;
164   ARC *first ;
165   int count ;
166   STATE *next ;
167   } ;
168 BUILDEXTERN STATE *firststate BUILDINIT(NULL) ;
169 BUILDEXTERN STATE **nextstate BUILDINIT(&firststate) ;
170 BUILDEXTERN STATE *startstate ;
171
172 /* Each arc in an FSA is an element in the arc list emanating from a
173    particular state.  Associated fields include label, a pointer to
174    the name of the element labelling the arc (garbage if the label is an
175    and group); optional, a flag indicating whether or not the label is
176    contextually required; minim, a flag indicating whether or not the arc
177    corresponds to an element selected by explicit minimization;
178    and group, a pointer to the list of FSA's making
179    up the andgroup if the arc's label is an andgroup; to, a pointer to the
180    state entered by the arc; next, a pointer to the next arc
181    in the current arc list; and finally, id, a pointer to the node in the
182    tree representation of the model corresponding to the arc (id is used
183    in the detection of ambiguity to differentiate between arcs with the same
184    label corresponding to one model token and those with the same label
185    corresponding to more than one model token).
186    */
187 BUILDEXTERN struct arc {
188   ELTSTRUCT *label ;
189   LOGICAL optional ;
190   LOGICAL minim ;
191   ANDGROUP *group ;
192   STATE *to ;
193   ARC *next ;
194   int id ;
195   } ;
196
197 /* Andgroups are elements in a list of the FSA's corresponding to the
198 content submodels in an andgroup.  Each list element contains a pointer
199 to the start state of the FSA and a pointer to the next element in the
200 list */
201 BUILDEXTERN struct andgroup{
202   STATE *start ;
203   ANDGROUP *nextptr ;
204   ANDGROUP *next ;
205   int count ;
206   } ;
207 BUILDEXTERN ANDGROUP *firstand BUILDINIT(NULL) ;
208 BUILDEXTERN ANDGROUP **nextand BUILDINIT(&firstand) ;
209
210 /* Tree representation of a rule */
211 /* Each node in the tree representation corresponds to a submodel.
212    Associated with the node is the submodel's connector and occurrence
213    indicator; terminal, a flag indicating whether the submodel in turn
214    has submodels; value, the element of which a terminal submodel consists;
215    pointers first and last to the first and last submodel of the node;
216    and right pointing to the node's next sibling in the tree. */
217 struct tree {
218   int connector, occurrence ;
219   ELTSTRUCT *value ;
220   LOGICAL terminal ;
221   LOGICAL minim ;
222   TREE *first, *right, *parent ;
223   int eltid ;
224   } ;
225 BUILDEXTERN TREE *ruletree BUILDINIT(NULL) ;
226 BUILDEXTERN TREE *curtree ;
227
228 /* Various counters */
229 BUILDEXTERN int eltsinrule BUILDINIT(0) ;
230 BUILDEXTERN int stateused BUILDINIT(0) ;
231 BUILDEXTERN int andused BUILDINIT(0) ;
232
233 /* Element names on the left-hand side of the current rule */
234 struct lhsstruct {
235   ELTSTRUCT *elt ;
236   LHS *next ;
237   } ;
238 BUILDEXTERN LHS *lhs BUILDINIT(NULL) ;
239 BUILDEXTERN LHS **nextlhs BUILDINIT(&lhs) ;
240
241 /* Content type (regular expression, ANY, NONE, CDATA, RCDATA) of the
242    current rule. */
243 BUILDEXTERN int contype ;
244
245 /* Indicates whether <PARAM>, <USEMAP>, or <MIN> fields have occurred in
246    current rule */
247 BUILDEXTERN LOGICAL poccur, uoccur, moccur ;
248
249 /* Indicates whether an ID parameter for this rule has occurred */
250 BUILDEXTERN LOGICAL idoccur ;
251
252 /* Short reference map for this rule */
253 BUILDEXTERN int srefp ;
254 BUILDEXTERN LOGICAL useoradd ;
255
256 /* Whether start- and end-tag minimization are permitted for the current
257    rule */
258 BUILDEXTERN LOGICAL smin, emin ;
259
260 /* Suffix for generated entity names */
261 BUILDEXTERN int egensuf ;
262
263 /* Storage for exceptions */
264 BUILDEXTERN int excount BUILDINIT(0) ;
265 struct exception {
266   int element ;
267   EXCEPTION *next ;
268   EXCEPTION *nextptr ;
269   } ;
270 BUILDEXTERN EXCEPTION *firstex BUILDINIT(NULL) ;
271 BUILDEXTERN EXCEPTION **nextex BUILDINIT(&firstex) ;
272 BUILDEXTERN EXCEPTION *exlist ;
273
274 /* Total number of parameters for all elements */
275 BUILDEXTERN int parcount BUILDINIT(0) ;
276
277 /* Primary representation of parameters */
278 struct parameter {
279   M_WCHAR *paramname ;
280   int type ;
281   int kwlist ;
282   PTYPE *ptypep ;
283   int deftype ;
284   int defval ;
285   M_WCHAR *defstring ;
286   /* Next parameter for this element */
287   PARAMETER *next ; 
288   /* Link for list of all parameters for all elements */
289   PARAMETER *nextptr ; 
290   } ;
291 BUILDEXTERN PARAMETER *newpar BUILDINIT(NULL) ;
292 BUILDEXTERN PARAMETER *plist BUILDINIT(NULL) ;
293 BUILDEXTERN PARAMETER *firstpar BUILDINIT(NULL) ;
294 BUILDEXTERN PARAMETER **nextpar BUILDINIT(&firstpar) ;
295
296 /* Storage for parameter names */
297 BUILDEXTERN int pnamelen BUILDINIT(0) ;
298
299 /* Storage for parameter values that are named keywords */
300 BUILDEXTERN int ptypelen BUILDINIT(0) ;
301 struct ptype {
302   M_WCHAR *keyword ;
303   int next ;
304   PTYPE *nextptr ;
305   } ;
306 BUILDEXTERN PTYPE *firstptype BUILDINIT(NULL) ;
307 BUILDEXTERN PTYPE *thisptype ;
308 BUILDEXTERN PTYPE **nextptype BUILDINIT(&firstptype) ;
309 BUILDEXTERN int kwlen BUILDINIT(0) ;
310
311 /* Storage for parameter default values */
312 BUILDEXTERN int deflen BUILDINIT(0) ;
313
314 /* Characters needed for element names */
315 BUILDEXTERN int enamelen BUILDINIT(0) ;
316
317 /* Description of an element: */
318 struct eltstruct {
319   /* Pointer to element name */  
320   M_WCHAR *enptr ;
321   /* Start state of element's content model's FSA */
322   STATE *model ;
323   /* Type of element's content (Regular expression, ANY, RCDATA, etc) */
324   int content ;
325   /* Pointer to element's inclusion list */
326   int inptr ;
327   /* Pointer to element's exclusion list */
328   int exptr ;
329   /* Pointer to element's parameter list */
330   PARAMETER *parptr ;
331   /* Index in output of first item in element's parameter list */
332   int parindex ;
333   /* Number of element's parameters */
334   int paramcount ;
335   /* Whether start- and end-tag minimization are permitted */
336   LOGICAL stmin, etmin ;
337   /* Pointer to short reference map, if any */
338   int srefptr ;
339   /* TRUE for USEMAP, FALSE for ADDMAP */
340   LOGICAL useoradd ;
341
342   ELTSTRUCT *next ;
343   int eltno ;
344   } ;
345 BUILDEXTERN ELTSTRUCT *firstelt BUILDINIT(NULL) ;
346 BUILDEXTERN ELTSTRUCT **nextelt BUILDINIT(&firstelt) ;
347
348 /* Most number of parameters had by a single element */
349 BUILDEXTERN int maxpar BUILDINIT(0) ;
350 /* Number of parameters current element has */
351 BUILDEXTERN int pcount ;
352
353 BUILDEXTERN FILE *dtd ;
354 BUILDEXTERN FILE *m_errfile ;
355
356 /* Line number in input file */
357 BUILDEXTERN int m_line BUILDINIT(1) ;
358
359 /* Options */
360 /* Scan trace */
361 BUILDEXTERN LOGICAL scantrace BUILDINIT(FALSE) ;
362 /* Trace calls to malloc/free */
363 BUILDEXTERN LOGICAL m_malftrace BUILDINIT(FALSE) ;
364 /* Test validity of heap in calls to malloc/free */
365 BUILDEXTERN LOGICAL m_heapchk BUILDINIT(FALSE) ;
366 /* Flag set if strictly conforming to ISO 8879 */
367 BUILDEXTERN LOGICAL standard BUILDINIT(FALSE) ;
368
369 /* File pointer used by utilities in ..\util\scanutil for input file */
370 BUILDEXTERN FILE *ifile ;
371
372 /* Element names are stored in a trie. */  
373 BUILDEXTERN M_TRIE eltree ;
374
375 /* Count of elements */
376 BUILDEXTERN int ecount BUILDINIT(0) ;
377
378 /* Storage for short reference map names and definitions */
379 BUILDEXTERN M_TRIE maptree ;
380 BUILDEXTERN M_TRIE sreftree ;
381 BUILDEXTERN int mapcnt BUILDINIT(0) ;
382 BUILDEXTERN int curmap ;
383 struct srefstruct {
384   int srefcnt ;
385   SREFDATA *data ;
386   SREFSTRUCT *next ;
387   } ;
388 BUILDEXTERN SREFSTRUCT *firstsref BUILDINIT(NULL) ;
389 BUILDEXTERN SREFSTRUCT **nextsref BUILDINIT(&firstsref) ;
390 struct srefdata {
391   int map ;
392   int entidx ;
393   SREFDATA *next ;
394   } ;
395 BUILDEXTERN SREFDATA *thissref ;
396 BUILDEXTERN int sreflen BUILDINIT(0) ;
397 BUILDEXTERN M_WCHAR mapname[M_NAMELEN + 1] ;
398 BUILDEXTERN int maxsr ;
399 BUILDEXTERN int maxseq ;
400 struct mapstruct {
401   int map ;
402   M_WCHAR *mapname ;
403   LOGICAL defined ;
404   MAP *nextptr ;
405   } ;
406 BUILDEXTERN MAP *firstmap BUILDINIT(NULL) ;
407 BUILDEXTERN MAP **nextmap BUILDINIT(&firstmap) ;
408
409
410 /* Storage for entities */
411 BUILDEXTERN M_TRIE m_enttrie[1] ;
412 BUILDEXTERN M_ENTITY *entity ;
413 BUILDEXTERN M_ENTITY *lastent BUILDINIT(NULL) ;
414 BUILDEXTERN M_ENTITY *firstent BUILDINIT(NULL) ;
415 BUILDEXTERN M_WCHAR entcontent[M_LITLEN + 1] ;
416 BUILDEXTERN int entclen ;
417 BUILDEXTERN int m_entcnt BUILDINIT(0) ;
418 BUILDEXTERN FILE *entfile ;
419
420 BUILDEXTERN LOGICAL entrule BUILDINIT(FALSE) ;
421
422 BUILDEXTERN M_WCHAR genname[M_NAMELEN + sizeof(M_PREFIX)] ;
423
424 M_WCHAR *MakeWideCharString(
425 #if defined(M_PROTO)
426   const char *from
427 #endif
428   );