Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / pass1 / 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 10:23:43 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(PREAMBLE) ;
300 M_PAREXTERN int m_prevcon ;
301 M_PAREXTERN int m_token ;
302 M_PAREXTERN int m_scanval ;
303
304 /* Declarations for tentative list of omitted tags when checking for tag
305    MINimization */
306 typedef struct m_min M_MIN ;
307 struct m_min {
308   int val ;
309   M_MIN *next ;
310   } ;
311 M_PAREXTERN M_MIN *m_minstart ;
312 M_PAREXTERN M_MIN *m_minend ;
313 M_PAREXTERN M_MIN **m_nextms ;
314 M_PAREXTERN M_MIN **m_nextme ;
315
316 /* Count of the number of open elements expecting to be terminated with
317    a NET */
318 M_PAREXTERN int m_netlevel M_PARINIT(0) ;
319
320 /* Count of errors that have occurred */
321 M_PAREXTERN int m_errcnt M_PARINIT(0) ;
322 #define M_ERRLIM 100
323 M_PAREXTERN int m_errlim M_PARINIT(M_ERRLIM) ;
324 M_PAREXTERN int m_expcount ;
325 M_PAREXTERN LOGICAL m_errexit M_PARINIT(FALSE) ;
326
327 /* Flag to indicate whether processing of the text has begun */
328 M_PAREXTERN LOGICAL m_start M_PARINIT(FALSE) ;
329
330 /* Flag indicates whether current start tag is terminated by End-tag
331    indicator or by tag-close delimiter (or start of another tag) */
332 M_PAREXTERN LOGICAL m_scannet ;
333
334 /* Storage for literals */
335 M_PAREXTERN M_WCHAR m_literal[M_LITLEN + 1] ;
336
337 /* Buffer for sequence of white space that has been read before it is
338    determined whether or not the white space is significant */
339 #define M_WSPACELEN 100
340 M_PAREXTERN int m_wspace[M_WSPACELEN] ;
341 M_PAREXTERN int m_wscount M_PARINIT(0) ;
342 M_PAREXTERN int m_maxws M_PARINIT(0) ;
343 M_PAREXTERN int m_wsused ;
344
345 /* Temporary pointers to parameter values.  Used while scanning start tag
346    before element is placed on parse stack.*/
347 M_PAREXTERN
348 #if defined M_PROTO
349 #endif
350 M_WCHAR *m_poccur[
351 #if defined(M_PARDEF)
352 M_MAXPAR ? M_MAXPAR : 1
353 #endif
354 ] ;
355
356 /* Index of a particular parameter within the parameter list for a given
357    element */
358 M_PAREXTERN int m_psave ;
359 /* Index of a particular parameter within the list of all parameters for all
360    elements */
361 M_PAREXTERN int m_ppsave ;
362
363 /* Index of element of tag just scanned; may be result of short tag
364    minimization */
365 M_PAREXTERN M_ELEMENT m_scanel ;
366
367 /* Read-ahead buffer and number of characters currently in that buffer */
368 #define M_SAVECHAR 500
369 M_PAREXTERN int m_savechar[M_SAVECHAR] ;
370 M_PAREXTERN M_WCHAR m_savedchar[M_SAVECHAR] ;
371 M_PAREXTERN M_WCHAR m_oldlinestat[M_SAVECHAR] ;
372 M_PAREXTERN M_WCHAR m_oldatrs[M_SAVECHAR] ;
373 M_PAREXTERN int m_sourcefile[M_SAVECHAR] ;
374 M_PAREXTERN M_WCHAR m_atrs M_PARINIT(TRUE) ;
375 M_PAREXTERN int m_oldlsindex M_PARINIT(M_SAVECHAR - 1) ;
376 M_PAREXTERN int m_toundo M_PARINIT(0) ;
377 M_PAREXTERN int m_maxundo M_PARINIT(0) ;
378 #define M_LINELENGTH 80
379 M_PAREXTERN int m_saveline[M_LINELENGTH][M_ENTLVL + 1] ;
380 M_PAREXTERN int m_svlncnt[M_ENTLVL + 1] M_PARINIT({0}) ;
381 M_PAREXTERN LOGICAL m_svlnwrap[M_ENTLVL + 1] M_PARINIT({FALSE}) ;
382
383 /* Arrays used for short references */
384 M_PAREXTERN int m_hold[M_HOLDSIZ] ;
385 M_PAREXTERN M_HOLDTYPE m_dhold[M_HOLDSIZ] ;
386 M_PAREXTERN int m_delim[M_HOLDSIZ] ;
387 M_PAREXTERN char m_srefchartype[M_HOLDSIZ] ;
388 M_PAREXTERN int m_current[M_HOLDSIZ] ;
389
390 /* Options
391       A -- Trace of calls to m_malloc() and m_free()
392       B -- 
393       C -- Trace of calls to m_getachar(), putachar()
394       D -- Trace of encountered data characters
395       E -- Don't report duplicate entity declarations
396       F -- 
397       G -- 
398       H -- M_malloc and m_free check for valid heap
399       I -- 
400       J -- 
401       K -- 
402       L -- Don't limit number of possible tokens displayed by expecting()
403       M -- Determine start-tag minimization strictly according to the Standard
404       N -- 
405       O -- 
406       P -- 
407       Q -- 
408       R -- 
409       S -- Scanner trace
410       T -- Tag trace
411       U -- 
412       V -- 
413       W -- Missing tagc not considered an error
414       X -- 
415       Y -- 
416       Z -- 
417 */
418
419 M_PAREXTERN LOGICAL m_malftrace M_PARINIT(FALSE) ;
420 M_PAREXTERN LOGICAL m_chtrace M_PARINIT(FALSE) ;
421 M_PAREXTERN LOGICAL m_cdtrace M_PARINIT(FALSE) ;
422 M_PAREXTERN LOGICAL m_entdupchk M_PARINIT(TRUE) ;
423 M_PAREXTERN LOGICAL m_heapchk M_PARINIT(FALSE) ;
424 M_PAREXTERN LOGICAL m_explimit M_PARINIT(TRUE) ;
425 M_PAREXTERN LOGICAL m_conform M_PARINIT(FALSE) ;
426 M_PAREXTERN LOGICAL m_scantrace M_PARINIT(FALSE) ;
427 M_PAREXTERN LOGICAL m_tagtrace M_PARINIT(FALSE) ;
428 M_PAREXTERN LOGICAL m_wholetag M_PARINIT(FALSE) ;
429 M_PAREXTERN int m_toptstat ;
430
431 /* Flag that indicates when unexpected content detected after document
432    appears to be complete */
433 M_PAREXTERN LOGICAL m_aftereod M_PARINIT(FALSE) ;
434
435 /* Save standard C main program arguments */
436 M_PAREXTERN int m_argc ;
437 M_PAREXTERN char **m_argv ;
438
439 /* PARSER output file */
440 M_PAREXTERN FILE *m_outfile M_PARINIT(stdout) ;
441 M_PAREXTERN FILE *m_errfile M_PARINIT(stdout) ;
442
443 /* Save processing instruction */
444 M_PAREXTERN M_WCHAR m_pi[M_PILEN + 1] ;
445 M_PAREXTERN int m_pilen M_PARINIT(0) ;
446
447 /* Entity being defined */
448 M_PAREXTERN M_ENTITY *m_entity ;
449 M_PAREXTERN int m_entclen ;
450 M_PAREXTERN M_WCHAR m_entcontent[M_LITLEN + 1] ;
451
452 /* Largest positive integer */
453 #define M_BIGINT 0x7FFF
454
455 /* Include function prototypes */
456 #include "proto.h"
457