ArcEngine.cxx revision 7c478bd95313f5f23a4c958a745db2134aa03244
// Copyright (c) 1996 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 "ArcEngine.h"
#include "ArcProcessor.h"
#include "Vector.h"
#include "NCVector.h"
#include "IQueue.h"
#include "ArcEngineMessages.h"
#include "MessageArg.h"
#include "ParserOptions.h"
#include "SgmlParser.h"
#include "Allocator.h"
#include "LinkProcess.h"
#include "macros.h"
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
sizeof(StartElementEvent),
sizeof(EndElementEvent),
sizeof(ImmediateDataEvent),
sizeof(SdataEntityEvent),
sizeof(EndPrologEvent),
sizeof(CdataEntityEvent),
sizeof(SdataEntityEvent),
sizeof(ExternalDataEntityEvent),
sizeof(OpenElement)
};
static
{
for (size_t i = 0; i < n; i++) {
if (v[i] > max)
max = v[i];
}
return max;
}
const unsigned invalidAtt = unsigned(-1);
const unsigned contentPseudoAtt = unsigned(-2);
class DelegateEventHandler : public EventHandler {
public:
#include "events.h"
protected:
};
public:
#include "events.h"
};
// This just passes through messages.
class NullEventHandler : public EventHandler {
public:
}
private:
};
public:
const SgmlParser *parser,
const volatile sig_atomic_t *cancelPtr,
const Notation *,
~ArcEngineImpl();
void sgmlDecl(SgmlDeclEvent *);
void appinfo(AppinfoEvent *);
void startElement(StartElementEvent *);
void endElement(EndElementEvent *);
void sdataEntity(SdataEntityEvent *);
void endProlog(EndPrologEvent *);
void startDtd(StartDtdEvent *);
void endDtd(EndDtdEvent *);
void startLpd(StartLpdEvent *);
void endLpd(EndLpdEvent *);
void uselink(UselinkEvent *);
private:
void dispatchMessage(const Message &);
void dispatchMessage(Message &);
void initMessage(Message &);
int stage_;
const SgmlParser *parser_;
unsigned gatheringContent_;
unsigned startAgain_;
const AttributeList *linkAttributes_;
const volatile sig_atomic_t *cancelPtr_;
};
const volatile sig_atomic_t *cancelPtr)
{
}
{
return 0;
return 0;
}
return eh_;
}
{
}
{
}
const SgmlParser *parser,
const volatile sig_atomic_t *cancelPtr,
{
if (!eventHandler_)
}
{
if (arcProcessors_[i].valid())
arcProcessors_[i].checkIdrefs();
}
{
}
{
if (stage_ == 1
size_t i = 0;
match = 0;
match = 0;
do {
i++;
if (i >= event->dataLength()
match = 0;
match = 0;
if (match) {
for (;;) {
i++;
if (i >= dataLength)
break;
i++;
}
}
}
}
{
sd_,
this,
haveLinkProcess_ = 1;
}
}
{
stage_++;
}
{
stage_++;
}
{
stage_ = 1;
}
{
stage_++;
}
{
atStart = 1;
else if (atStart) {
break;
break;
break;
}
// Allow quotes around replacement name.
}
break;
}
}
atStart = 0;
}
}
{
if (gatheringContent_) {
return;
}
if (startAgain_) {
startAgain_ = 0;
}
else {
contentP = 0;
start = 0;
if (haveLinkProcess_) {
const ResultElementSpec *resultElementSpec;
event->attributes(),
*this, // Messenger &
}
else
linkAttributes_ = 0;
}
if (arcProcessors_[i].valid()) {
alloc_)) {
startAgain_ = i + 1;
gatheringContent_ = 1;
return;
}
}
}
}
{
if (gatheringContent_) {
if (entity)
else {
// Do attribute value literal interpretation.
else
}
else
}
}
}
else {
if (entity)
arcProcessors_[i].docHandler()
else
arcProcessors_[i].docHandler()
event->dataLength(),
0));
}
}
}
}
{
if (gatheringContent_) {
return;
}
else {
arcProcessors_[i].docHandler()
.sdataEntity(new (alloc_)
}
}
}
}
{
if (!gatheringContent_) {
if (arcProcessors_[i].valid()
&& arcProcessors_[i].processData()) {
= arcProcessors_[i].dtdPointer()
markup);
arcProcessors_[i].docHandler()
.externalDataEntity(new (alloc_)
newOrigin));
}
// otherwise entity is not architectural
}
}
}
}
{
while (gatheringContent_) {
if (--gatheringContent_ > 0) {
return;
}
// Clear out eventQueue_ in case handling the events
// causes events to be queued again.
}
if (arcProcessors_[i].valid())
if (haveLinkProcess_)
}
{
if (!gatheringContent_)
}
{
}
{
}
{
}
{
}
{
}
{
return *docSyntax_;
}
const Location &)
{
return 0;
}
const Location &)
{
// FIXME What about default entity
return 0;
}
{
if (valid_)
currentAttributes_[i] = value;
}
{
return currentAttributes_[i];
}
// This code is the same as in the main parser.
// Maybe factor out into AttributeContext.
{
if (!valid_)
return 1;
if (id->defined()) {
return 0;
}
return 1;
}
{
if (!valid_ || !errorIdref_)
return;
if (!id->defined())
}
{
if (!id) {
}
return id;
}
void ArcProcessor::checkIdrefs()
{
}
}
}
const SgmlParser *parentParser,
const volatile sig_atomic_t *cancelPtr)
{
docSyntax_ = syntax;
valid_ = 0;
mayDefaultAttribute_ = 1;
attributeList_.finish(*this);
}
else
return;
sd->internalCharset(),
*mgr_,
sysid)) {
return;
}
0,
0));
metaSyntax_ = tem;
}
return;
valid_ = 1;
}
{
}
// FIXME check for ArcAutoF
for (;;) {
break;
if (!copy->asExternalDataEntity()
}
}
{
entity.attributes(),
0,
0);
if (!map.attributed)
return 0;
// FIXME check arcContent
return 1;
}
// FIXME error tried to use #CONTENT
return 0;
}
{
return 0;
}
return 0;
}
if (!entity->asExternalEntity()) {
return 0;
}
#if 0
// Use the public identifier of the notation to find the meta-DTD.
}
else if (!externalId.publicId()) {
unsigned textClassPos = 2;
textClassPos += 3;
break;
const MessageType1 *msg;
}
}
}
#endif
entity->defLocation(),
}
{
static const char *const s[] = {
"ArcFormA",
"ArcNamrA",
"ArcSuprA",
"ArcIgnDA",
"ArcDocF",
"ArcSuprF",
"ArcBridF",
"ArcDataF",
"ArcAuto",
"ArcIndr",
"ArcDTD",
"ArcQuant",
};
unsigned ind;
if (value) {
// FIXME check for empty value
if (textP) {
switch (i) {
case rArcQuant:
break;
case rArcAuto:
arcAuto_ = 1;
arcAuto_ = 0;
else
StringMessageArg(supportAtts_[i]));
break;
case rArcIndr:
}
StringMessageArg(supportAtts_[i]));
}
break;
case rArcFormA:
case rArcNamrA:
case rArcSuprA:
case rArcIgnDA:
break;
case rArcDocF:
case rArcSuprF:
case rArcBridF:
case rArcDataF:
break;
case rArcDTD:
{
arcDtdIsParam_ = 1;
}
}
}
break;
}
}
}
}
}
}
{
unsigned ind;
const Text *arcOptAText = 0;
if (value) {
if (arcOptAText)
}
}
if (!arcOptAText)
if (value) {
if (textP) {
}
}
}
}
}
{
StringMessageArg(tokens[i]));
}
StringMessageArg(tokens[i]));
}
else {
i++;
unsigned long val = 0;
StringMessageArg(tokens[i]));
}
if (weight < 0) {
val = 0;
break;
}
else {
val *= 10;
}
}
if (newMetaSyntax.isNull())
}
}
}
if (!newMetaSyntax.isNull())
}
const AttributeList *linkAttributes,
{
: (unsigned)condIgnoreData);
if ((suppressFlags & suppressForm)
&& (suppressFlags & suppressSupr)) {
// Make this case efficient.
return 1;
}
0,
atts,
const ElementType *metaType;
if (map.attributed == 0) {
if (!(tagLevel() == 0
&& !currentElement().isFinished())) {
if (!arcContent.isNull()
&& (currentElement().declaredEmpty()
|| !currentElement().tryTransitionPcdata()))
return 1;
}
attributeList_.finish(*this);
}
else {
arcContent, map))
return 0;
}
0);
else if (elementIsExcluded(metaType))
else if (elementIsIncluded(metaType))
genEvent->setIncluded();
0,
0,
if (attributeList_.conref())
currentElement().setConref();
if (currentElement().declaredEmpty()
|| !currentElement().tryTransitionPcdata())
else
}
suppressFlags &= ~recoverData;
return 1;
}
{
const Char *s;
size_t n;
switch (type) {
// +1 because first dataEvent is the non-architectural data.
s,
n,
*loc,
0));
else
->entity()->asInternalEntity(),
break;
->entity()->asInternalEntity(),
break;
default:
break;
}
}
{
if (openElementFlags_.size() > 0
return 0;
if (!currentElement().declaredEmpty()
&& currentElement().tryTransitionPcdata())
return 1;
else if (openElementFlags_.size() > 0
return 0;
else {
// Only give this error once per element
if (openElementFlags_.size() > 0) {
return 1;
}
return 1;
}
}
const AttributeList *fromLink,
{
if (map.attributed)
}
if (fromIndex != contentPseudoAtt)
}
else {
Boolean fromTextTokenized = 0;
if (!content)
return 0;
}
else {
if (value) {
if (fromText
->missingValueWouldMatch(*fromText, *this)))
fromText = 0;
}
}
if (fromText) {
unsigned specLength = 0;
else
}
}
}
if (map.attributed)
return 1;
}
const ArcProcessor::MetaMap &
const AttributeList &atts,
const AttributeList *linkAtts,
unsigned suppressFlags)
{
if (!attributed) {
isNotation = 1;
}
else {
isNotation = 0;
}
// Try to use cached entry.
Boolean inhibitCache = 0;
inhibitCache = 1;
cacheIndex = (unsigned)-1;
}
else {
if (cache
for (int i = 0;; i++) {
if (i == MetaMapCache::nNoSpec)
break;
}
}
}
// no valid cached MetaMap
// Handle suppression.
unsigned oldSuppressFlags = suppressFlags;
unsigned newSuppressFlags = suppressFlags;
unsigned arcSuprIndex;
if (!isNotation)
else
// Handle ArcIgnD
unsigned arcIgnDIndex;
if (!isNotation)
else
// Handle ArcForm.
unsigned arcFormIndex;
const Attributed *metaAttributed
// See if there's a renamer that will inhibit cacheing.
#pragma "%Z%%M% %I% %E% SMI"
unsigned arcNamerIndex;
if (metaAttributed)
else {
namerText = 0;
}
if (inhibitCache) {
mapP = &noCacheMetaMap_;
}
else {
if (cache)
else {
cache = new MetaMapCache;
}
}
// Build the attribute map.
if (metaAttributed) {
= metaAttributed->attributeDef();
if (!metaAttDef.isNull())
if (linkAtts) {
unsigned index;
if (linkNamerText)
}
if (namerText)
}
return *mapP;
}
const AttributeList *linkAtts,
unsigned &thisSuppressFlags,
unsigned &newSuppressFlags,
unsigned &arcSuprIndex)
{
if (thisSuppressFlags & suppressSupr)
return;
return;
const AttributeValue *val;
unsigned tem;
inhibitCache = 1;
}
else
return;
if (!val)
return;
if (!textP)
return;
// FIXME trim spaces
// sArcForm suppress processing for all elements except
// those that have a non-implied ArcSupr attribute.
#if 0
// I don't think this is useful
#endif
}
}
const AttributeList *linkAtts,
unsigned thisSuppressFlags,
unsigned &newSuppressFlags,
unsigned &arcIgnDIndex)
{
if (thisSuppressFlags & suppressSupr)
return;
return;
const AttributeValue *val;
unsigned tem;
inhibitCache = 1;
}
else
return;
if (!val)
return;
if (!textP)
return;
// FIXME trim spaces
}
}
const Attributed *
const AttributeList *linkAtts,
unsigned thisSuppressFlags,
unsigned &newSuppressFlags,
unsigned &arcFormIndex)
{
if ((thisSuppressFlags & suppressForm)
|| (thisSuppressFlags & suppressSupr)
|| isNotation))
return 0;
unsigned tem;
const AttributeValue *val;
inhibitCache = 1;
}
else
if (!val)
return 0;
if (!textP)
return 0;
// FIXME should trim leading and trailing spaces
if (!isNotation) {
if (!metaAttributed) // CONSTDTD
return metaAttributed;
}
if (thisSuppressFlags & suppressForm)
return 0;
return metaAttributed;
}
else
}
const Attributed *
unsigned thisSuppressFlags,
unsigned &newSuppressFlags,
unsigned &idIndex)
{
if (!isNotation) {
const Attributed *metaAttributed;
if (openElementFlags_.size() == 0) {
inhibitCache = 1;
}
else {
metaAttributed = 0;
if (arcAuto_)
if (!metaAttributed
inhibitCache = 1;
}
}
if (metaAttributed
}
else if (thisSuppressFlags & suppressForm)
return 0;
return metaAttributed;
}
else if (thisSuppressFlags & suppressForm)
return 0;
else {
const Attributed *metaAttributed = 0;
if (arcAuto_)
return metaAttributed;
}
}
const Text *
unsigned &arcNamerIndex)
{
return 0;
inhibitCache = 1;
if (!val)
return 0;
}
const AttributeList &atts,
const AttributeList *linkAtts,
{
if (map.attributed)
// FIXME Should check that ARCCONT doesn't appear more than once.
unsigned fromIndex = invalidAtt;
unsigned toIndex = invalidAtt;
if (tokens[i] == rniArcCont_)
else if (metaAttDef.isNull()
StringMessageArg(tokens[i]));
}
else if (attRenamed[toIndex]) {
StringMessageArg(tokens[i]));
}
}
else {
}
if (toIndex != contentPseudoAtt)
}
else if (linkAtts
}
}
if (toIndex != contentPseudoAtt) {
->name()));
}
}
}
}
const AttributeList &atts,
const AttributeList *linkAtts,
{
if (metaAttDef.isNull())
return;
for (unsigned i = 0; i < metaAttDef->size(); i++)
if (!attRenamed[i]) {
unsigned fromIndex;
break;
}
}
fromIndex)) {
}
}
}
}
{
return 0;
}
{
for (size_t i = 0;;) {
;
break;
;
}
}
{
if (wasArc) {
0);
if (currentElement().included())
genEvent->setIncluded();
if (!currentElement().isFinished())
popElement();
}
}
{
}
{
}
{
if (valid_) {
}
}
{
for (int i = 0; i < nNoSpec; i++)
noSpec[i] = invalidAtt;
linkAtts = 0;
}
{
for (int i = 0; i < nNoSpec; i++)
noSpec[i] = invalidAtt;
linkAtts = 0;
}
: attributed(0)
{
}
{
attMapFrom.clear();
attributed = 0;
}
#ifdef SP_NAMESPACE
}
#endif