nsgml: Resolve symbol collision when building with SunStudio 12.1
[oweals/cde.git] / cde / programs / nsgmls / Parser.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 libraries 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.C /main/1 1996/07/29 17:00:24 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30
31 #include "splib.h"
32 #include "Parser.h"
33 #include "ParserMessages.h"
34 #include "constant.h"
35
36 #ifdef SP_NAMESPACE
37 namespace SP_NAMESPACE {
38 #endif
39
40 Parser::Parser(const SgmlParser::Params &params)
41 : ParserState(params.parent
42               ? params.parent->parser_->entityManagerPtr()
43               : params.entityManager,
44               params.options
45               ? *params.options
46               : params.parent->parser_->options(),
47               paramsSubdocLevel(params),
48               params.entityType == SgmlParser::Params::dtd
49               ? declSubsetPhase
50               : contentPhase)
51 {
52   Parser *parent = 0;
53   if (params.parent)
54     parent = params.parent->parser_;
55   if (params.entityType == SgmlParser::Params::document) {
56     Sd *sd = new Sd();
57     const ParserOptions &opt = *params.options;
58     sd->setDocCharsetDesc(*params.initialCharset);
59     sd->setBooleanFeature(Sd::fDATATAG, opt.datatag);
60     sd->setBooleanFeature(Sd::fOMITTAG, opt.omittag);
61     sd->setBooleanFeature(Sd::fRANK, opt.rank);
62     sd->setBooleanFeature(Sd::fSHORTTAG, opt.shorttag);
63     sd->setNumberFeature(Sd::fSIMPLE, opt.linkSimple);
64     sd->setBooleanFeature(Sd::fIMPLICIT, opt.linkImplicit);
65     sd->setNumberFeature(Sd::fEXPLICIT, opt.linkExplicit);
66     sd->setNumberFeature(Sd::fCONCUR, opt.concur);
67     sd->setNumberFeature(Sd::fSUBDOC, opt.subdoc);
68     sd->setBooleanFeature(Sd::fFORMAL, opt.formal);
69     PublicId publicId;
70     CharsetDecl docCharsetDecl;
71     docCharsetDecl.addSection(publicId);
72     docCharsetDecl.addRange(0, charMax > 99999999 ? 99999999 : charMax + 1, 0);
73     sd->setDocCharsetDecl(docCharsetDecl);
74     setSd(sd);
75   }
76   else if (params.sd.isNull()) {
77     setSd(parent->sdPointer());
78     setSyntaxes(parent->prologSyntaxPointer(),
79                 parent->instanceSyntaxPointer());
80   }
81   else {
82     setSd(params.sd);
83     setSyntaxes(params.prologSyntax, params.instanceSyntax);
84   }
85
86   // Make catalog
87   StringC sysid(params.sysid);
88   ConstPtr<EntityCatalog> catalog
89     = entityManager().makeCatalog(sysid,
90                                   sd().docCharset(),
91                                   messenger());
92   if (!catalog.isNull())
93     setEntityCatalog(catalog);
94   else if (parent)
95     setEntityCatalog(parent->entityCatalogPtr());
96   else {
97     allDone();
98     return;
99   }
100   
101   // Set up the input stack.
102   if (sysid.size() == 0) {
103     allDone();
104     return;
105   }
106   Ptr<InputSourceOrigin> origin;
107   if (params.origin.isNull())
108     origin = new InputSourceOrigin;
109   else
110     origin = params.origin;
111   pushInput(entityManager().open(sysid,
112                                  sd().docCharset(),
113                                  origin.pointer(),
114                                  1,
115                                  messenger()));
116   if (inputLevel() == 0) {
117     allDone();
118     return;
119   }
120   switch (params.entityType) {
121   case SgmlParser::Params::document:
122     setPhase(initPhase);
123     break;
124   case SgmlParser::Params::subdoc:
125     if (params.subdocInheritActiveLinkTypes && parent)
126       inheritActiveLinkTypes(*parent);
127     if (subdocLevel() == sd().subdoc() + 1)
128       message(ParserMessages::subdocLevel, NumberMessageArg(sd().subdoc()));
129     setPhase(prologPhase);
130     compilePrologModes();
131     break;
132   case SgmlParser::Params::dtd:
133     compilePrologModes();
134     startDtd(params.doctypeName);
135     setPhase(declSubsetPhase);
136     break;
137   }
138 }
139
140 void Parser::giveUp()
141 {
142   if (subdocLevel() > 0)        // FIXME might be subdoc if level == 0
143     message(ParserMessages::subdocGiveUp);
144   else
145     message(ParserMessages::giveUp);
146   allDone();
147 }
148
149 unsigned Parser::paramsSubdocLevel(const SgmlParser::Params &params)
150 {
151   if (!params.parent)
152     return 0;
153   unsigned n = params.parent->parser_->subdocLevel();
154   if (params.subdocReferenced)
155     return n + 1;
156   else
157     return n;
158 }
159
160 Event *Parser::nextEvent()
161 {
162   while (eventQueueEmpty()) {
163     switch (phase()) {
164     case noPhase:
165       return 0;
166     case initPhase:
167       doInit();
168       break;
169     case prologPhase:
170       doProlog();
171       break;
172     case declSubsetPhase:
173       doDeclSubset();
174       break;
175     case instanceStartPhase:
176       doInstanceStart();
177       break;
178     case contentPhase:
179       doContent();
180       break;
181     }
182   }
183   return eventQueueGet();
184 }
185
186 void Parser::parseAll(EventHandler &handler,
187                       SP_CONST SP_VOLATILE sig_atomic_t *cancelPtr)
188 {
189   while (!eventQueueEmpty())
190     eventQueueGet()->handle(handler);
191   // FIXME catch exceptions and reset handler.
192   setHandler(&handler, cancelPtr);
193   for (;;) {
194     switch (phase()) {
195     case noPhase:
196       unsetHandler();
197       return;
198     case initPhase:
199       doInit();
200       break;
201     case prologPhase:
202       doProlog();
203       break;
204     case declSubsetPhase:
205       doDeclSubset();
206       break;
207     case instanceStartPhase:
208       doInstanceStart();
209       break;
210     case contentPhase:
211       doContent();
212       break;
213     }
214   }
215 }
216
217 #ifdef SP_NAMESPACE
218 }
219 #endif