📄 sgmlseventhandler.cxx
字号:
void SgmlsEventHandler::startAttribute(const StringC &name, char code, const StringC *ownerName){ os() << code; if (ownerName) os() << *ownerName << space; os() << name << space;}void SgmlsEventHandler::endElement(EndElementEvent *event){ flushData(); if (haveLinkProcess_) linkProcess_.endElement(); outputLocation(event->location()); os() << endElementCode << event->name() << nl; delete event;}void SgmlsEventHandler::externalDataEntity(ExternalDataEntityEvent *event){ currentLocation_ = event->location(); outputLocation(event->location()); flushData(); if (!outputEntity_ && !markEntity(event->entity())) defineExternalDataEntity(event->entity()); currentLocation_.clear(); os() << referenceEntityCode << event->entity()->name() << nl; delete event;}void SgmlsEventHandler::subdocEntity(SubdocEntityEvent *event){ currentLocation_ = event->location(); outputLocation(event->location()); flushData(); const SubdocEntity *entity = event->entity(); if (!outputEntity_ && !markEntity(entity)) defineSubdocEntity(entity); currentLocation_.clear(); os() << startSubdocCode << entity->name() << nl; SgmlParser::Params params; params.subdocInheritActiveLinkTypes = 1; params.subdocReferenced = 1; params.origin = event->entityOrigin()->copy(); params.parent = parser_; params.sysid = entity->externalId().effectiveSystemId(); params.entityType = SgmlParser::Params::subdoc; SgmlParser parser(params); SgmlsSubdocState oldState; SgmlsSubdocState::swap(oldState); SgmlsSubdocState::init(&parser); parser.parseAll(*this); oldState.swap(*this); os() << endSubdocCode << entity->name() << nl; delete event;}void SgmlsEventHandler::defineEntity(const Entity *entity){ const InternalEntity *internalEntity = entity->asInternalEntity(); if (internalEntity) defineInternalEntity(internalEntity); else { switch (entity->dataType()) { case Entity::cdata: case Entity::sdata: case Entity::ndata: defineExternalDataEntity(entity->asExternalDataEntity()); break; case Entity::subdoc: defineSubdocEntity(entity->asSubdocEntity()); break; case Entity::sgmlText: defineExternalTextEntity(entity->asExternalEntity()); break; default: CANNOT_HAPPEN(); } }}void SgmlsEventHandler::defineExternalDataEntity(const ExternalDataEntity *entity){ const Notation *notation = entity->notation(); defineNotation(notation); externalId(entity->externalId()); const char *typeString; switch (entity->dataType()) { case Entity::cdata: typeString = "CDATA"; break; case Entity::sdata: typeString = "SDATA"; break; case Entity::ndata: typeString = "NDATA"; break; default: CANNOT_HAPPEN(); } os() << defineExternalEntityCode << entity->name() << space << typeString << space << notation->name() << nl; attributes(entity->attributes(), dataAttributeCode, &entity->name());}void SgmlsEventHandler::defineSubdocEntity(const SubdocEntity *entity){ externalId(entity->externalId()); os() << defineSubdocEntityCode << entity->name() << nl;}void SgmlsEventHandler::defineExternalTextEntity(const ExternalEntity *entity){ externalId(entity->externalId()); os() << defineExternalTextEntityCode << entity->name() << nl;}void SgmlsEventHandler::defineInternalEntity(const InternalEntity *entity){ os() << defineInternalEntityCode << entity->name() << space; const char *s; switch (entity->dataType()) { case Entity::sdata: s = "SDATA"; break; case Entity::cdata: s = "CDATA"; break; case Entity::sgmlText: s = "TEXT"; break; case Entity::pi: s = "PI"; break; default: CANNOT_HAPPEN(); } os() << s << space; outputString(entity->string()); os() << nl;}void SgmlsEventHandler::defineNotation(const Notation *notation){ if (markNotation(notation)) return; externalId(notation->externalId(), outputNotationSysid_); os() << defineNotationCode << notation->name() << nl;}void SgmlsEventHandler::externalId(const ExternalId &id, Boolean outputFile){ const StringC *str = id.publicIdString(); if (str) { os() << pubidCode; outputString(*str); os() << nl; } str = id.systemIdString(); if (str) { os() << sysidCode; outputString(*str); os() << nl; } if (outputFile && id.effectiveSystemId().size()) { os() << fileCode; outputString(id.effectiveSystemId()); os() << nl; }}Boolean SgmlsEventHandler::markEntity(const Entity *entity){ return definedEntities_.add(entity->name());}Boolean SgmlsEventHandler::markNotation(const Notation *notation){ return definedNotations_.add(notation->name());}void SgmlsEventHandler::outputString(const Char *p, size_t n){ for (; n > 0; p++, n--) { switch (*p) { case '\\': // FIXME we're punning Chars and chars os() << "\\\\"; break; case re: os() << "\\n"; if (outputLine_ && haveData_) lastLineno_++; break; default: // FIXME not clear what to do here given possibility of wide characters if (*p < 040) { static const char digits[] = "0123456789"; os() << "\\0" << digits[*p / 8] << digits[*p % 8]; } else os().put(*p); break; } }}void SgmlsEventHandler::escape(OutputCharStream &s, Char c){ s << "\\#" << (unsigned long)c << ";";}void SgmlsEventHandler::outputLocation1(const Location &loc){ const Origin *origin = loc.origin().pointer(); const InputSourceOrigin *inputSourceOrigin; const ExternalInfo *info; Index index = loc.index(); for (;;) { if (!origin) return; inputSourceOrigin = origin->asInputSourceOrigin(); if (inputSourceOrigin) { info = inputSourceOrigin->externalInfo(); if (info) break; } const Location &loc = origin->parent(); index = loc.index(); origin = loc.origin().pointer(); } Offset off = inputSourceOrigin->startOffset(index); StorageObjectLocation soLoc; if (!ExtendEntityManager::externalize(info, off, soLoc)) return; if (soLoc.lineNumber == (unsigned long)-1) return; if (soLoc.storageObjectSpec == lastSos_) { if (soLoc.lineNumber == lastLineno_) return; flushData(); os() << locationCode << soLoc.lineNumber << nl; lastLineno_ = soLoc.lineNumber; } else { flushData(); os() << locationCode << soLoc.lineNumber << space; outputString(soLoc.actualStorageId); os() << nl; lastLineno_ = soLoc.lineNumber; lastSos_ = soLoc.storageObjectSpec; lastLoc_ = loc; // make sure lastSos_ doesn't get freed }}void SgmlsEventHandler::dispatchMessage(const Message &msg){ if (!cancelled()) { noteMessage(msg); messenger_->dispatchMessage(msg); }}void SgmlsEventHandler::initMessage(Message &msg){ msg.loc = currentLocation_;}SgmlsSubdocState::SgmlsSubdocState(): haveLinkProcess_(0), parser_(0){}SgmlsSubdocState::SgmlsSubdocState(const SgmlParser *parser): haveLinkProcess_(0), parser_(parser){}void SgmlsSubdocState::init(const SgmlParser *parser){ parser_ = parser; definedNotations_.clear(); definedEntities_.clear(); haveLinkProcess_ = 0; linkProcess_.clear();}void SgmlsSubdocState::swap(SgmlsSubdocState &to){ { const SgmlParser *tem = to.parser_; to.parser_ = parser_; parser_ = tem; } { Boolean tem = to.haveLinkProcess_; to.haveLinkProcess_ = haveLinkProcess_; haveLinkProcess_ = tem; } linkProcess_.swap(to.linkProcess_); definedNotations_.swap(to.definedNotations_); definedEntities_.swap(to.definedEntities_);}#ifdef SP_NAMESPACE}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -