ParserState.cxx revision 7c478bd95313f5f23a4c958a745db2134aa03244
// Copyright (c) 1994 James Clark
// See the file COPYING for copying permission.
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "ParserState.h"
#include "InternalInputSource.h"
#include "MessageArg.h"
#include "macros.h"
#include "SgmlParser.h"
#include "IListIter.h"
#include "ParserMessages.h"
#include "Undo.h"
#include "Trie.h"
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
static const size_t eventSizes[] = {
#define EVENT(c, f) sizeof(c),
#include "events.h"
};
static const size_t internalSizes[] = {
sizeof(InternalInputSource),
sizeof(OpenElement),
sizeof(UndoStartTag),
sizeof(UndoEndTag),
sizeof(UndoTransition)
};
static
{
for (size_t i = 0; i < n; i++) {
if (v[i] > max)
max = v[i];
}
return max;
}
const ParserOptions &opt,
unsigned subdocLevel,
: entityManager_(em),
inInstance_(0),
keepingMessages_(0),
inputLevel_(0),
hadLpd_(0),
pass2_(0),
allowPass2_(0),
hadPass2Start_(0),
currentMarkup_(0),
hadAfdrDecl_(0)
{
}
{
}
void ParserState::allDone()
{
}
void ParserState::setPass2Start()
{
if (hadPass2Start_)
return;
hadPass2Start_ = 1;
allowPass2_ = 1;
const InputSourceOrigin *p
}
else {
allowPass2_ = 0;
currentInput()->willNotRewind();
}
}
void ParserState::allLinkTypesActivated()
{
currentInput()->willNotRewind();
}
{
if (pass2_ || !allowPass2_)
return 0;
while (!pass1Handler_.empty()) {
if (cancelled())
return 0;
}
InputSource *top = 0;
if (top)
top->willNotRewind();
return 0;
}
while (inputLevel_ > 1) {
inputLevel_--;
delete p;
}
// Caller will call allDone() if inputLevel_ is 0.
if (inputLevel_ == 0)
return 0;
inputLevel_ = 0;
delete inputStack_.get();
return 0;
}
for (; pass2StartOffset_ > 0; pass2StartOffset_--)
inputLevel_ = 0;
delete inputStack_.get();
return 0;
}
markedSectionLevel_ = 0;
hadLpd_ = 0;
allowPass2_ = 0;
hadPass2Start_ = 0;
currentMarkup_ = 0;
inputLevel_ = 1;
inInstance_ = 0;
currentDtd_.clear();
pass2_ = 1;
return 1;
}
{
return 0;
return inputLevel() > 1;
}
{
= new InternalTextEntity(name,
Location(),
text,
}
Location(),
text);
}
}
void ParserState::endDtd()
{
currentDtd_.clear();
}
{
}
void ParserState::endLpd()
{
hadLpd_ = 1;
currentDtd_.clear();
}
void ParserState::popInputStack()
{
ASSERT(inputLevel_ > 0);
inputLevel_--;
delete p;
if (currentMode_ == dsiMode
&& inputLevel_ == 1
&& markedSectionLevel_ == 0)
if (inputLevelElementIndex_.size())
}
{
}
{
}
{
}
{
if (!in)
return;
inputLevel_++;
else if (currentMode_ == dsMode)
}
{
if (currentMode_ == dsMode)
}
{
}
void ParserState::endMarkedSection()
{
ASSERT(markedSectionLevel_ > 0);
- 1);
if (markedSectionSpecialLevel_ > 0) {
if (markedSectionSpecialLevel_ > 0)
return; // remain in imsMode
if (inInstance_)
currentMode_ = contentMode();
else
}
if (currentMode_ == dsiMode
&& inputLevel_ == 1
&& markedSectionLevel_ == 0)
}
{
ContentState::pushElement(e);
pcdataRecovering_ = 0;
// the start tag of this element may have been implied by data
// inside a cdata or rcdata marked section
if (markedSectionSpecialLevel_ == 0) {
currentMode_ = contentMode();
if (e->requiresSpecialParse()) {
}
}
}
// PCDATA was encountered somewhere where it was not allowed.
// Change the current mode to improve recovery.
void ParserState::pcdataRecover()
{
switch (currentMode_) {
case econMode:
break;
case econnetMode:
break;
default:
break;
}
pcdataRecovering_ = 1;
}
{
// the end tag of this element may have been implied by data
// inside a cdata or rcdata marked section
if (markedSectionSpecialLevel_ == 0) {
currentMode_ = contentMode();
}
pcdataRecovering_ = 0;
return e;
}
void ParserState::popElement()
{
delete popSaveElement();
}
{
const EntityOrigin *eo
return 1;
}
return 0;
}
void ParserState::startInstance()
{
if (!instanceSyntax_.isNull())
currentDtd_ = dtd_[0];
currentDtdConst_ = dtd_[0];
inInstance_ = 1;
}
{
if (!id) {
}
return id;
}
const Location &useLocation,
{
else
if (dtd) {
// Did we find it in pass1Dtd?
// Did we look at the defaultEntity?
if (referenced)
return entity1;
}
if (referenced)
noteReferencedEntity(entity, 0, 0);
return entity;
}
}
return entity;
}
if (!isParameter) {
if (referenced)
note = 1;
usedPass1 = 1;
}
}
if (inInstance_) {
mustCopy = 0;
}
}
if (mustCopy) {
p->generateSystemId(*this);
p->setDefaulted();
entity = p;
if (inInstance_) {
useLocation));
}
else
dtd->insertEntity(p);
}
if (note)
}
else
return entity;
}
}
return (Entity *)0;
}
{
return entity;
}
{
if (!old)
}
// Compare entity definitions.
// e1 is the original (will not be an external non-text entity).
// FIXME should look at generated sysids as well.
static
{
return 0;
if (i1) {
if (!i2)
return 0;
return 0;
return 1;
}
else if (i2)
return 0;
if (s1) {
if (!s2)
return 0;
return 0;
}
else if (s2)
return 0;
if (s1) {
if (!s2)
return 0;
return 0;
}
else if (s2)
return 0;
return 1;
}
void ParserState::checkEntityStability()
{
== Entity::parameterEntity,
== Entity::parameterEntity)
}
{
// Ensure that the memory is released.
}
}
const
{
return 1;
}
return 0;
}
{
}
{
*s++ = (*subst)[*p++];
}
{
if (cancelled()) {
delete event;
return;
}
if (keepingMessages_)
else
}
void ParserState::releaseKeptMessages()
{
keepingMessages_ = 0;
while (!keptMessages_.empty()) {
if (cancelled()) {
allDone();
return;
}
}
}
void ParserState::discardKeptMessages()
{
keepingMessages_ = 0;
}
{
if (inInstance()) {
}
}
{
}
{
}
unsigned i)
{
if (i < attributeLists_.size())
else {
}
return attributeLists_[i].pointer();
}
{
if (!hadPass2Start_ && !pass2_)
else
}
{
if (!activeLinkTypesSubsted_) {
// FIXME use mutable
}
if (name == activeLinkTypes_[i])
return 1;
return 0;
}
{
return dtd_[i];
}
{
return allLpd_[i];
}
const Location &)
{
if (haveCurrentDtd())
else if (resultAttributeSpecMode_) {
if (!resultDtd)
return 0;
}
return notation;
}
{
&& options().warnDefaultEntityReference) {
}
return entity;
}
{
if (!inInstance() || !validate())
return 1;
if (id->defined()) {
return 0;
}
return 1;
}
{
return;
if (!id->defined())
}
{
if (inInstance())
currentAttributes_[i] = value;
}
{
if (!inInstance())
return ConstPtr<AttributeValue>();
return currentAttributes_[i];
}
{
return syntax();
}
#ifdef SP_NAMESPACE
}
#endif