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 /* $XConsortium: build.h /main/3 1995/11/08 10:00:30 rswiston $ */
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.
30 /* Build.h is the primary include file for allocation of global variables
36 #define BUILDINIT(a) = a
38 #define BUILDEXTERN extern
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 ;
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 {
85 NULL, NULL, NULL, NULL, NULL, NULL
90 BUILDEXTERN STACK *top BUILDINIT(&bot) ;
92 BUILDEXTERN int stacklevels BUILDINIT(0) ;
95 /* Used to report nondeterminism in and groups */
97 #define DATACONFLICT 2
100 /* Name of an element, and of the first element on the left-hand side of
102 #define thisrule lhs->elt->enptr
104 /* Set declared entity type */
105 #define SETETYPE(p,t) adddefent(p) ; entity->type = t
107 /* Definitions for entities */
113 /* Prefix for default short reference map and entities */
114 #define M_PREFIX "M-"
116 /* State transition network generated by CONTEXT */
120 /* Function prototypes */
123 /* Frequently output strings */
124 #define ndif "}\n#endif\n ;\n\n"
125 #define SUBONE else fputs("[1] ;\n\n", dtd) ;
127 /* An array used to indicate which characters can appear within
130 #include "chartype.h"
132 extern M_CHARTYPE m_ctarray[M_CHARSETLEN] ;
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 ;
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] ;
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 */
149 BUILDEXTERN int savechar[SAVECHAR] ;
151 /* Whether errors have occurred */
152 BUILDEXTERN LOGICAL errexit BUILDINIT(FALSE) ;
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
160 BUILDEXTERN struct state {
162 LOGICAL datacontent ;
168 BUILDEXTERN STATE *firststate BUILDINIT(NULL) ;
169 BUILDEXTERN STATE **nextstate BUILDINIT(&firststate) ;
170 BUILDEXTERN STATE *startstate ;
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).
187 BUILDEXTERN struct arc {
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
201 BUILDEXTERN struct andgroup{
207 BUILDEXTERN ANDGROUP *firstand BUILDINIT(NULL) ;
208 BUILDEXTERN ANDGROUP **nextand BUILDINIT(&firstand) ;
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. */
218 int connector, occurrence ;
222 TREE *first, *right, *parent ;
225 BUILDEXTERN TREE *ruletree BUILDINIT(NULL) ;
226 BUILDEXTERN TREE *curtree ;
228 /* Various counters */
229 BUILDEXTERN int eltsinrule BUILDINIT(0) ;
230 BUILDEXTERN int stateused BUILDINIT(0) ;
231 BUILDEXTERN int andused BUILDINIT(0) ;
233 /* Element names on the left-hand side of the current rule */
238 BUILDEXTERN LHS *lhs BUILDINIT(NULL) ;
239 BUILDEXTERN LHS **nextlhs BUILDINIT(&lhs) ;
241 /* Content type (regular expression, ANY, NONE, CDATA, RCDATA) of the
243 BUILDEXTERN int contype ;
245 /* Indicates whether <PARAM>, <USEMAP>, or <MIN> fields have occurred in
247 BUILDEXTERN LOGICAL poccur, uoccur, moccur ;
249 /* Indicates whether an ID parameter for this rule has occurred */
250 BUILDEXTERN LOGICAL idoccur ;
252 /* Short reference map for this rule */
253 BUILDEXTERN int srefp ;
254 BUILDEXTERN LOGICAL useoradd ;
256 /* Whether start- and end-tag minimization are permitted for the current
258 BUILDEXTERN LOGICAL smin, emin ;
260 /* Suffix for generated entity names */
261 BUILDEXTERN int egensuf ;
263 /* Storage for exceptions */
264 BUILDEXTERN int excount BUILDINIT(0) ;
270 BUILDEXTERN EXCEPTION *firstex BUILDINIT(NULL) ;
271 BUILDEXTERN EXCEPTION **nextex BUILDINIT(&firstex) ;
272 BUILDEXTERN EXCEPTION *exlist ;
274 /* Total number of parameters for all elements */
275 BUILDEXTERN int parcount BUILDINIT(0) ;
277 /* Primary representation of parameters */
286 /* Next parameter for this element */
288 /* Link for list of all parameters for all elements */
291 BUILDEXTERN PARAMETER *newpar BUILDINIT(NULL) ;
292 BUILDEXTERN PARAMETER *plist BUILDINIT(NULL) ;
293 BUILDEXTERN PARAMETER *firstpar BUILDINIT(NULL) ;
294 BUILDEXTERN PARAMETER **nextpar BUILDINIT(&firstpar) ;
296 /* Storage for parameter names */
297 BUILDEXTERN int pnamelen BUILDINIT(0) ;
299 /* Storage for parameter values that are named keywords */
300 BUILDEXTERN int ptypelen BUILDINIT(0) ;
306 BUILDEXTERN PTYPE *firstptype BUILDINIT(NULL) ;
307 BUILDEXTERN PTYPE *thisptype ;
308 BUILDEXTERN PTYPE **nextptype BUILDINIT(&firstptype) ;
309 BUILDEXTERN int kwlen BUILDINIT(0) ;
311 /* Storage for parameter default values */
312 BUILDEXTERN int deflen BUILDINIT(0) ;
314 /* Characters needed for element names */
315 BUILDEXTERN int enamelen BUILDINIT(0) ;
317 /* Description of an element: */
319 /* Pointer to element name */
321 /* Start state of element's content model's FSA */
323 /* Type of element's content (Regular expression, ANY, RCDATA, etc) */
325 /* Pointer to element's inclusion list */
327 /* Pointer to element's exclusion list */
329 /* Pointer to element's parameter list */
331 /* Index in output of first item in element's parameter list */
333 /* Number of element's parameters */
335 /* Whether start- and end-tag minimization are permitted */
336 LOGICAL stmin, etmin ;
337 /* Pointer to short reference map, if any */
339 /* TRUE for USEMAP, FALSE for ADDMAP */
345 BUILDEXTERN ELTSTRUCT *firstelt BUILDINIT(NULL) ;
346 BUILDEXTERN ELTSTRUCT **nextelt BUILDINIT(&firstelt) ;
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 ;
353 BUILDEXTERN FILE *dtd ;
354 BUILDEXTERN FILE *m_errfile ;
356 /* Line number in input file */
357 BUILDEXTERN int m_line BUILDINIT(1) ;
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) ;
369 /* File pointer used by utilities in ..\util\scanutil for input file */
370 BUILDEXTERN FILE *ifile ;
372 /* Element names are stored in a trie. */
373 BUILDEXTERN M_TRIE eltree ;
375 /* Count of elements */
376 BUILDEXTERN int ecount BUILDINIT(0) ;
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 ;
388 BUILDEXTERN SREFSTRUCT *firstsref BUILDINIT(NULL) ;
389 BUILDEXTERN SREFSTRUCT **nextsref BUILDINIT(&firstsref) ;
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 ;
406 BUILDEXTERN MAP *firstmap BUILDINIT(NULL) ;
407 BUILDEXTERN MAP **nextmap BUILDINIT(&firstmap) ;
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 ;
420 BUILDEXTERN LOGICAL entrule BUILDINIT(FALSE) ;
422 BUILDEXTERN M_WCHAR genname[M_NAMELEN + sizeof(M_PREFIX)] ;
424 M_WCHAR *MakeWideCharString(