Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / canon1 / parser / parser.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: parser.h /main/3 1995/11/08 09:41:12 rswiston $ */
24 /*
25               Copyright 1986 Tandem Computers Incorporated.
26 This product and information is proprietary of Tandem Computers Incorporated.
27                    Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
28 */
29
30 /* Parser.h allocates global variables for PARSER */
31
32 #if defined(M_PARDEF)
33 #define M_PAREXTERN
34 #define M_PARINIT(a) = a
35 #else
36 #define M_PAREXTERN extern
37 #define M_PARINIT(a)
38 #endif
39
40 #include "common.h"
41
42 /* Stack of open entities and line number in each external file */
43 #define M_ENTLVL 16 /* Maximum number of open entities */
44 M_PAREXTERN M_ENTITY *m_opene[M_ENTLVL] ;
45 M_PAREXTERN int m_eopencnt M_PARINIT(0) ;
46 M_PAREXTERN void *m_sysent[M_ENTLVL + 1] ;
47 #define M_FIRSTLINE 1
48 M_PAREXTERN int m_line[M_ENTLVL + 1] M_PARINIT({M_FIRSTLINE}) ;
49 M_PAREXTERN int m_sysecnt M_PARINIT(0) ;
50
51 /* Possible states of a line -- no SGML characters yet processed, SGML
52    characters processed but no data character or contextual end tag,
53    data character or contextual end tag (i.e., end tag of a proper
54    subelement) has occurred.  Note that linestat is stacked with each
55    element.  If an element contains a line that
56          * is neither its first nor last line
57          * contains data characters within an included element
58   the status of the line should be M_SOMETHING not M_DCORCET because the data
59   characters belong to the inner element rather than the outer one.
60   
61   Also note that "M_DCORCET" originally stood for "data character or contextual
62   end tag" when the Standard used the term "contextual element" to mean
63   an element allowed by a model rather than an inclusion and when
64   the rules for ignoring RE's referred to the occurrence of end tags of
65   such elements rather than the entire elements.  Now the acronym can be
66   interpreted as "data character or contextual element".
67  */
68 #define M_NOTHING 0
69 #define M_SOMETHING 1
70 #define M_DCORCET 2
71
72 /* Definitions for parse stack. The primary data structure of PARSER
73    is a stack containing one entry for each open element.  Each entry
74    on the stack is described in an m_parse structure. Entries for
75    element's whose content is defined by a content model have a
76    pointer to a stack of open FSAs.  These FSA stacks do not describe
77    the actual automata (which are coded in the data structures
78    generated by BUILD, but rather the current state in the active
79    automata.  An element's FSA stack will have one entry for the
80    content model and an additional entry for each active and-group.
81 */
82
83 typedef struct m_parse M_PARSE ;
84 typedef struct m_openfsa M_OPENFSA ;
85 typedef struct m_andlist M_ANDLIST ;
86
87 struct m_parse {
88   /* Pointer to preceding entry on stack */
89   M_PARSE *oldtop ;
90
91   /* Identifier of element this entry represents */
92   M_ELEMENT element ;
93
94   /* Pointer to table of parameter pointers for this instance of this
95      element */
96   M_WCHAR **param ;
97
98   /* Pointer to stack of open FSAs for this element */
99   M_OPENFSA *fsastack ;
100
101   /* For RCDATA elements to indicate the nesting level
102      of entities when the element opened, since net and etago
103      delimiters are not recognized except in the same entity
104      as the element began. */
105   int thisent ;
106
107   /* TRUE iff the element's start-tag ended with a NET so that a NET
108      is expected to end the element */
109   LOGICAL neednet ;
110
111   /* Has a Record End occurred in the element's content? */
112   LOGICAL firstre ; 
113
114   /* Flag that indicates whether the element is contextual, i.e.,
115      whether it occurred because it was allowed in context by a
116      content model, or it was allowed by an inclusion exception or
117      occurred by error.  (The term "contextual subelement" was used
118      in the Draft International Standard in the same sense as
119      "proper subelement" in the International Standard.) */
120   LOGICAL contextual ;
121
122   /* Whether character data is currently being processed. */
123   LOGICAL intext ;
124
125   /* Line status.  Indicates whether anything has occurred after
126      the start-tag or most recent Record Start in this element */
127   char linestat ;
128
129   /* Flag indicating whether or not a Record End (carriage return)
130      has been scanned and is being held to see if there is more
131      content in the element.  If there is, the RE will be processed
132      as a data character, otherwise it will be discarded. */
133   LOGICAL holdre ;
134
135   /* Pointer to the element's short reference map.  The value is NULL
136      if there is no map. */
137   int *map ;
138
139   /* Index in actions for processing text characters encountered
140      in this element, and pointer to stack location where parameters
141      should be retrieved. */
142   int cdcase ;
143   M_PARSE *cdparam ;
144
145   /* Index in actions for processing processing instructions
146      encountered in this element, and pointer to stack location where
147      parameters should be retrieved. */
148   int picase ;
149   M_PARSE *piparam ;
150
151   /* Index in actions for processing start- and end-strings
152      encountered in this element, and pointer to stack location where
153      parameters should be retrieved. */
154   int stccase ;
155   M_PARSE *stparam ;
156
157   /* Pointer to name of input file in which the current element
158     began (NULL if primary input file). */
159   M_WCHAR *file ;
160
161   /* Line number where the current element began. */
162   int line ;
163
164   /* Interface-defined pointer stored on the stack */
165   void *ifdata ;
166   } ;
167
168 struct m_openfsa {
169   /* Pointer to preceding entry on FSA stack */
170   M_OPENFSA *oldtop ;
171
172   /* Current state in this FSA */
173   M_STATE current ;
174
175   /* Identifier of set of and-groups being processed and pointer to list of 
176      and-groups that have occurred within this set. */
177   M_ANDGROUP andgroup ;
178   M_ANDLIST *usedand ;
179   } ;
180
181 struct m_andlist {
182   M_ANDGROUP group ;
183   M_ANDLIST *next ;
184   } ;
185
186 extern M_OPENFSA m_botfsa ;
187
188 /* Bottom marker of parse stack */
189 M_PAREXTERN M_PARSE m_stackbot 
190 #if defined(M_PARDEF)
191   = {
192   /* M_PARSE *oldtop ;*/           NULL,
193   /* M_ELEMENT element ;*/         M_NULLVAL,
194   /* M_WCHAR **param ;*/           NULL,
195   /* M_OPENFSA *fsastack ;*/       &m_botfsa,
196   /* int thisent ;*/               0,
197   /* LOGICAL neednet ;*/           FALSE,
198   /* LOGICAL firstre ; */          FALSE,
199   /* LOGICAL contextual ;*/        TRUE,
200   /* LOGICAL intext ;*/            FALSE,
201   /* int linestat ;*/              M_NOTHING,
202   /* LOGICAL holdre ;*/            FALSE,
203   /* int *map ;*/                  NULL,
204   /* int cdcase ;*/                1,
205   /* M_PARSE *cdparam ;*/          &m_stackbot,
206   /* int picase ;*/                1,
207   /* M_PARSE *piparam ;*/          &m_stackbot,
208   /* int stccase ;*/               1,
209   /* M_PARSE *stparam ;*/          &m_stackbot,
210   /* M_WCHAR *file ;*/             NULL,
211   /* int line ;*/                  M_FIRSTLINE,
212   /* void *ifdata ;*/              NULL,
213   }
214 #endif
215   ;
216
217 M_PAREXTERN M_OPENFSA m_botfsa
218 #if defined(M_PARDEF)
219   = {
220   /* M_OPENFSA *oldtop ;*/         NULL,
221   /* M_STATE current ;*/           1,
222   /* M_ANDGROUP andgroup ;*/       M_NULLVAL,
223   /* M_ANDGROUP *usedand ;*/       NULL,
224   }
225 #endif
226   ;
227
228 /* Index of current top of parse stack */
229 M_PAREXTERN M_PARSE *m_stacktop M_PARINIT(&m_stackbot) ;
230
231 /* Pointer to stack location where parameters for current code
232 segment are defined.  Used for inherited code segments (text-code,
233 pi-code, string-code) */
234 M_PAREXTERN M_PARSE *m_stackpar ;
235
236 /* Type of characters */
237 typedef char M_HOLDTYPE ;
238
239 #if defined(M_PARDEF)
240 #include "chartype.h"
241 #else
242 extern M_CHARTYPE m_ctarray[M_CHARSETLEN] ;
243 #endif
244
245 /* Indicates a start tag is allowed by an inclusion exception */
246 #define M_NONCONTEXTUAL 2
247
248 /* Character used to delimit parameter names in start and end strings 
249    entered as data to ELTDEF */
250 #define M_ESCAPECHAR '@'
251
252 /* Pointer to name of element */
253 #define m_nameofelt(x) &m_ename[m_element[x - 1].enptr]
254
255 /* Status of characters as read from input stream */
256 #define M_EE 0
257 #define M_NORMAL 1
258 #define M_CDCHAR 2
259 #define M_ENTNORMAL 3
260
261 /* State transition network generated by CONTEXT */
262 #include "sparse.h"
263
264 /* Maximum length of a sequence of blanks in a short reference delimiter */
265 #define M_BSEQLEN 100
266
267 /* #defines used in recognition of short reference delimiters */
268 #if defined(M_PARDEF)
269 #define M_HOLDSIZ M_MAXSR + M_BSEQLEN * M_MAXSEQ + 1
270 #else
271 #define M_HOLDSIZ
272 #endif
273 #define M_REGCHAR 1
274 #define M_SEQCHAR 2
275 #define M_BSCHAR 3
276 #define M_WSCHAR 4
277 #define M_RSCHAR 5
278
279 /* Number of allowable tokens to display after a syntax error */
280 #define M_EXPLIMIT 5
281
282 /* Status of T option output */
283 #define M_TOPTSTARTTAG 0
284 #define M_WHITESPACE 1
285 #define M_OTHER 2
286
287 /* Maximum length of processing instruction (not in a PI entity) */
288 #define M_PILEN 240
289
290 /* Storage for a name token just read by the scanner; and for a name read
291    while parsing parameters */
292 M_PAREXTERN M_WCHAR m_name[M_NAMELEN + 1] ;
293 M_PAREXTERN M_WCHAR m_saveatt[M_NAMELEN + 1] ;
294
295 /* M_curcon is current state of FSA that controls parser; m_prevcon is the
296    value of m_curcon before last character was scanned; m_token is the token
297    type returned by last call to scanner; and
298    m_scanval is index of element name just read within tag delimiters */
299 M_PAREXTERN int m_curcon M_PARINIT(PROLOG) ;
300 M_PAREXTERN int m_prevcon ;
301 M_PAREXTERN int m_token ;
302 M_PAREXTERN int m_scanval ;
303
304 char *user_defined_entities M_PARINIT("USER-DEFINED-ENTITIES");
305
306 /* Declarations for tentative list of omitted tags when checking for tag
307    MINimization */
308 typedef struct m_min M_MIN ;
309 struct m_min {
310   int val ;
311   M_MIN *next ;
312   } ;
313 M_PAREXTERN M_MIN *m_minstart ;
314 M_PAREXTERN M_MIN *m_minend ;
315 M_PAREXTERN M_MIN **m_nextms ;
316 M_PAREXTERN M_MIN **m_nextme ;
317
318 /* Count of the number of open elements expecting to be terminated with
319    a NET */
320 M_PAREXTERN int m_netlevel M_PARINIT(0) ;
321
322 /* Count of errors that have occurred */
323 M_PAREXTERN int m_errcnt M_PARINIT(0) ;
324 #define M_ERRLIM 100
325 M_PAREXTERN int m_errlim M_PARINIT(M_ERRLIM) ;
326 M_PAREXTERN int m_expcount ;
327 M_PAREXTERN LOGICAL m_errexit M_PARINIT(FALSE) ;
328
329 /* Flag to indicate whether processing of the text has begun */
330 M_PAREXTERN LOGICAL m_start M_PARINIT(FALSE) ;
331
332 /* Flag indicates whether current start tag is terminated by End-tag
333    indicator or by tag-close delimiter (or start of another tag) */
334 M_PAREXTERN LOGICAL m_scannet ;
335
336 /* Storage for literals */
337 M_PAREXTERN M_WCHAR m_literal[M_LITLEN + 1] ;
338
339 /* Buffer for sequence of white space that has been read before it is
340    determined whether or not the white space is significant */
341 #define M_WSPACELEN 100
342 M_PAREXTERN int m_wspace[M_WSPACELEN] ;
343 M_PAREXTERN int m_wscount M_PARINIT(0) ;
344 M_PAREXTERN int m_maxws M_PARINIT(0) ;
345 M_PAREXTERN int m_wsused ;
346
347 /* Temporary pointers to parameter values.  Used while scanning start tag
348    before element is placed on parse stack.*/
349 M_PAREXTERN
350 #if defined M_PROTO
351 #endif
352 M_WCHAR *m_poccur[
353 #if defined(M_PARDEF)
354 M_MAXPAR ? M_MAXPAR : 1
355 #endif
356 ] ;
357
358 /* Index of a particular parameter within the parameter list for a given
359    element */
360 M_PAREXTERN int m_psave ;
361 /* Index of a particular parameter within the list of all parameters for all
362    elements */
363 M_PAREXTERN int m_ppsave ;
364
365 /* Index of element of tag just scanned; may be result of short tag
366    minimization */
367 M_PAREXTERN M_ELEMENT m_scanel ;
368
369 /* Read-ahead buffer and number of characters currently in that buffer */
370 #define M_SAVECHAR 500
371 M_PAREXTERN int m_savechar[M_SAVECHAR] ;
372 M_PAREXTERN M_WCHAR m_savedchar[M_SAVECHAR] ;
373 M_PAREXTERN M_WCHAR m_oldlinestat[M_SAVECHAR] ;
374 M_PAREXTERN M_WCHAR m_oldatrs[M_SAVECHAR] ;
375 M_PAREXTERN int m_sourcefile[M_SAVECHAR] ;
376 M_PAREXTERN M_WCHAR m_atrs M_PARINIT(TRUE) ;
377 M_PAREXTERN int m_oldlsindex M_PARINIT(M_SAVECHAR - 1) ;
378 M_PAREXTERN int m_toundo M_PARINIT(0) ;
379 M_PAREXTERN int m_maxundo M_PARINIT(0) ;
380 #define M_LINELENGTH 80
381 M_PAREXTERN int m_saveline[M_LINELENGTH][M_ENTLVL + 1] ;
382 M_PAREXTERN int m_svlncnt[M_ENTLVL + 1] M_PARINIT({0}) ;
383 M_PAREXTERN LOGICAL m_svlnwrap[M_ENTLVL + 1] M_PARINIT({FALSE}) ;
384
385 /* Arrays used for short references */
386 M_PAREXTERN int m_hold[M_HOLDSIZ] ;
387 M_PAREXTERN M_HOLDTYPE m_dhold[M_HOLDSIZ] ;
388 M_PAREXTERN int m_delim[M_HOLDSIZ] ;
389 M_PAREXTERN char m_srefchartype[M_HOLDSIZ] ;
390 M_PAREXTERN int m_current[M_HOLDSIZ] ;
391
392 /* Options
393       A -- Trace of calls to m_malloc() and m_free()
394       B -- 
395       C -- Trace of calls to m_getachar(), putachar()
396       D -- Trace of encountered data characters
397       E -- Don't report duplicate entity declarations
398       F -- 
399       G -- 
400       H -- M_malloc and m_free check for valid heap
401       I -- 
402       J -- 
403       K -- 
404       L -- Don't limit number of possible tokens displayed by expecting()
405       M -- Determine start-tag minimization strictly according to the Standard
406       N -- 
407       O -- 
408       P -- 
409       Q -- 
410       R -- 
411       S -- Scanner trace
412       T -- Tag trace
413       U -- 
414       V -- 
415       W -- Missing tagc not considered an error
416       X -- 
417       Y -- 
418       Z -- 
419 */
420
421 M_PAREXTERN LOGICAL m_malftrace M_PARINIT(FALSE) ;
422 M_PAREXTERN LOGICAL m_chtrace M_PARINIT(FALSE) ;
423 M_PAREXTERN LOGICAL m_cdtrace M_PARINIT(FALSE) ;
424 M_PAREXTERN LOGICAL m_entdupchk M_PARINIT(TRUE) ;
425 M_PAREXTERN LOGICAL m_heapchk M_PARINIT(FALSE) ;
426 M_PAREXTERN LOGICAL m_explimit M_PARINIT(TRUE) ;
427 M_PAREXTERN LOGICAL m_conform M_PARINIT(FALSE) ;
428 M_PAREXTERN LOGICAL m_scantrace M_PARINIT(FALSE) ;
429 M_PAREXTERN LOGICAL m_tagtrace M_PARINIT(FALSE) ;
430 M_PAREXTERN LOGICAL m_wholetag M_PARINIT(FALSE) ;
431 M_PAREXTERN int m_toptstat ;
432
433 /* Flag that indicates when unexpected content detected after document
434    appears to be complete */
435 M_PAREXTERN LOGICAL m_aftereod M_PARINIT(FALSE) ;
436
437 /* Save standard C main program arguments */
438 M_PAREXTERN int m_argc ;
439 M_PAREXTERN char **m_argv ;
440
441 /* PARSER output file */
442 M_PAREXTERN FILE *m_outfile M_PARINIT(stdout) ;
443 M_PAREXTERN FILE *m_errfile M_PARINIT(stdout) ;
444
445 /* Save processing instruction */
446 M_PAREXTERN M_WCHAR m_pi[M_PILEN + 1] ;
447 M_PAREXTERN int m_pilen M_PARINIT(0) ;
448
449 /* Entity being defined */
450 M_PAREXTERN M_ENTITY *m_entity ;
451 M_PAREXTERN int m_entclen ;
452 M_PAREXTERN M_WCHAR m_entcontent[M_LITLEN + 1] ;
453
454 /* Largest positive integer */
455 #define M_BIGINT 0x7FFF
456
457 /* Include function prototypes */
458 #include "proto.h"
459