1 /* $XConsortium: Parser.C /main/1 1996/07/29 17:00:24 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
11 #include "ParserMessages.h"
15 namespace SP_NAMESPACE {
18 Parser::Parser(const SgmlParser::Params ¶ms)
19 : ParserState(params.parent
20 ? params.parent->parser_->entityManagerPtr()
21 : params.entityManager,
24 : params.parent->parser_->options(),
25 paramsSubdocLevel(params),
26 params.entityType == SgmlParser::Params::dtd
32 parent = params.parent->parser_;
33 if (params.entityType == SgmlParser::Params::document) {
35 const ParserOptions &opt = *params.options;
36 sd->setDocCharsetDesc(*params.initialCharset);
37 sd->setBooleanFeature(Sd::fDATATAG, opt.datatag);
38 sd->setBooleanFeature(Sd::fOMITTAG, opt.omittag);
39 sd->setBooleanFeature(Sd::fRANK, opt.rank);
40 sd->setBooleanFeature(Sd::fSHORTTAG, opt.shorttag);
41 sd->setNumberFeature(Sd::fSIMPLE, opt.linkSimple);
42 sd->setBooleanFeature(Sd::fIMPLICIT, opt.linkImplicit);
43 sd->setNumberFeature(Sd::fEXPLICIT, opt.linkExplicit);
44 sd->setNumberFeature(Sd::fCONCUR, opt.concur);
45 sd->setNumberFeature(Sd::fSUBDOC, opt.subdoc);
46 sd->setBooleanFeature(Sd::fFORMAL, opt.formal);
48 CharsetDecl docCharsetDecl;
49 docCharsetDecl.addSection(publicId);
50 docCharsetDecl.addRange(0, charMax > 99999999 ? 99999999 : charMax + 1, 0);
51 sd->setDocCharsetDecl(docCharsetDecl);
54 else if (params.sd.isNull()) {
55 setSd(parent->sdPointer());
56 setSyntaxes(parent->prologSyntaxPointer(),
57 parent->instanceSyntaxPointer());
61 setSyntaxes(params.prologSyntax, params.instanceSyntax);
65 StringC sysid(params.sysid);
66 ConstPtr<EntityCatalog> catalog
67 = entityManager().makeCatalog(sysid,
70 if (!catalog.isNull())
71 setEntityCatalog(catalog);
73 setEntityCatalog(parent->entityCatalogPtr());
79 // Set up the input stack.
80 if (sysid.size() == 0) {
84 Ptr<InputSourceOrigin> origin;
85 if (params.origin.isNull())
86 origin = new InputSourceOrigin;
88 origin = params.origin;
89 pushInput(entityManager().open(sysid,
94 if (inputLevel() == 0) {
98 switch (params.entityType) {
99 case SgmlParser::Params::document:
102 case SgmlParser::Params::subdoc:
103 if (params.subdocInheritActiveLinkTypes && parent)
104 inheritActiveLinkTypes(*parent);
105 if (subdocLevel() == sd().subdoc() + 1)
106 message(ParserMessages::subdocLevel, NumberMessageArg(sd().subdoc()));
107 setPhase(prologPhase);
108 compilePrologModes();
110 case SgmlParser::Params::dtd:
111 compilePrologModes();
112 startDtd(params.doctypeName);
113 setPhase(declSubsetPhase);
118 void Parser::giveUp()
120 if (subdocLevel() > 0) // FIXME might be subdoc if level == 0
121 message(ParserMessages::subdocGiveUp);
123 message(ParserMessages::giveUp);
127 unsigned Parser::paramsSubdocLevel(const SgmlParser::Params ¶ms)
131 unsigned n = params.parent->parser_->subdocLevel();
132 if (params.subdocReferenced)
138 Event *Parser::nextEvent()
140 while (eventQueueEmpty()) {
150 case declSubsetPhase:
153 case instanceStartPhase:
161 return eventQueueGet();
164 void Parser::parseAll(EventHandler &handler,
165 SP_CONST SP_VOLATILE sig_atomic_t *cancelPtr)
167 while (!eventQueueEmpty())
168 eventQueueGet()->handle(handler);
169 // FIXME catch exceptions and reset handler.
170 setHandler(&handler, cancelPtr);
182 case declSubsetPhase:
185 case instanceStartPhase: