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 libraries 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: 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.
28 #pragma implementation
33 #include "ParserMessages.h"
37 namespace SP_NAMESPACE {
40 Parser::Parser(const SgmlParser::Params ¶ms)
41 : ParserState(params.parent
42 ? params.parent->parser_->entityManagerPtr()
43 : params.entityManager,
46 : params.parent->parser_->options(),
47 paramsSubdocLevel(params),
48 params.entityType == SgmlParser::Params::dtd
54 parent = params.parent->parser_;
55 if (params.entityType == SgmlParser::Params::document) {
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);
70 CharsetDecl docCharsetDecl;
71 docCharsetDecl.addSection(publicId);
72 docCharsetDecl.addRange(0, charMax > 99999999 ? 99999999 : charMax + 1, 0);
73 sd->setDocCharsetDecl(docCharsetDecl);
76 else if (params.sd.isNull()) {
77 setSd(parent->sdPointer());
78 setSyntaxes(parent->prologSyntaxPointer(),
79 parent->instanceSyntaxPointer());
83 setSyntaxes(params.prologSyntax, params.instanceSyntax);
87 StringC sysid(params.sysid);
88 ConstPtr<EntityCatalog> catalog
89 = entityManager().makeCatalog(sysid,
92 if (!catalog.isNull())
93 setEntityCatalog(catalog);
95 setEntityCatalog(parent->entityCatalogPtr());
101 // Set up the input stack.
102 if (sysid.size() == 0) {
106 Ptr<InputSourceOrigin> origin;
107 if (params.origin.isNull())
108 origin = new InputSourceOrigin;
110 origin = params.origin;
111 pushInput(entityManager().open(sysid,
116 if (inputLevel() == 0) {
120 switch (params.entityType) {
121 case SgmlParser::Params::document:
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();
132 case SgmlParser::Params::dtd:
133 compilePrologModes();
134 startDtd(params.doctypeName);
135 setPhase(declSubsetPhase);
140 void Parser::giveUp()
142 if (subdocLevel() > 0) // FIXME might be subdoc if level == 0
143 message(ParserMessages::subdocGiveUp);
145 message(ParserMessages::giveUp);
149 unsigned Parser::paramsSubdocLevel(const SgmlParser::Params ¶ms)
153 unsigned n = params.parent->parser_->subdocLevel();
154 if (params.subdocReferenced)
160 Event *Parser::nextEvent()
162 while (eventQueueEmpty()) {
172 case declSubsetPhase:
175 case instanceStartPhase:
183 return eventQueueGet();
186 void Parser::parseAll(EventHandler &handler,
187 SP_CONST SP_VOLATILE sig_atomic_t *cancelPtr)
189 while (!eventQueueEmpty())
190 eventQueueGet()->handle(handler);
191 // FIXME catch exceptions and reset handler.
192 setHandler(&handler, cancelPtr);
204 case declSubsetPhase:
207 case instanceStartPhase: