1 // Copyright (c) 1996 James Clark 2 // See the file COPYING for copying permission. 3 #pragma ident "%Z%%M% %I% %E% SMI" 4 5 #ifndef ArcProcessor_INCLUDED 6 #define ArcProcessor_INCLUDED 1 7 8 #include "Event.h" 9 #include "ContentState.h" 10 #include "Id.h" 11 #include "NamedTable.h" 12 #include "Vector.h" 13 #include "ArcEngine.h" 14 #include "SgmlParser.h" 15 16 #ifdef SP_NAMESPACE 17 namespace SP_NAMESPACE { 18 #endif 19 20 class Allocator; 21 22 // Processor for a single architecture 23 24 class ArcProcessor : private ContentState, private AttributeContext { 25 public: 26 struct MetaMap { 27 MetaMap(); 28 void clear(); 29 const Attributed *attributed; 30 unsigned suppressFlags; 31 // #ARCCONT and #CONTENT are handled with a special index 32 // list of indexes into element's attlist of architectural attributes 33 Vector<unsigned> attMapFrom; 34 // corresponding list of indexes in form's attlist 35 Vector<unsigned> attMapTo; 36 }; 37 struct MetaMapCache { 38 MetaMapCache(); 39 void clear(); 40 MetaMap map; 41 enum { nNoSpec = 4 }; 42 // Prerequisites for this cached entry to be valid. 43 // The cache is only valid if for each member of noSpec != -1 44 // the attribute with that index was not specified (or current) 45 unsigned noSpec[nNoSpec]; 46 unsigned suppressFlags; 47 const AttributeList *linkAtts; 48 }; 49 ArcProcessor(); 50 void setName(const StringC &); 51 void init(const EndPrologEvent &, 52 const ConstPtr<Sd> &, 53 const ConstPtr<Syntax> &, 54 const SgmlParser *parser, 55 Messenger *, 56 const Vector<StringC> &superName, 57 ArcDirector &director, 58 const volatile sig_atomic_t *cancelPtr); 59 // Return 0 if the content is needed, but wasn't supplied 60 Boolean processStartElement(const StartElementEvent &, 61 const AttributeList *linkAttributes, 62 const Text *content, 63 Allocator &); 64 void processEndElement(const EndElementEvent &, 65 Allocator &); 66 // Return true if its architectural. 67 Boolean processData(); dtdPointer()68 ConstPtr<Dtd> dtdPointer() const { return metaDtd_; } valid()69 Boolean valid() const { return valid_; } 70 void checkIdrefs(); name()71 const StringC &name() const { return name_; } docHandler()72 EventHandler &docHandler() const { return *docHandler_; } 73 private: 74 ArcProcessor(const ArcProcessor &); // undefined 75 void operator=(const ArcProcessor &); // undefined 76 const Syntax &attributeSyntax() const; 77 ConstPtr<Notation> getAttributeNotation(const StringC &, 78 const Location &); 79 ConstPtr<Entity> getAttributeEntity(const StringC &, 80 const Location &); 81 void noteCurrentAttribute(size_t, AttributeValue *); 82 ConstPtr<AttributeValue> getCurrentAttribute(size_t) const; 83 Boolean defineId(const StringC &, const Location &, Location &); 84 void noteIdref(const StringC &, const Location &); 85 Id *lookupCreateId(const StringC &); 86 void dispatchMessage(const Message &); 87 void dispatchMessage(Message &); 88 void initMessage(Message &); 89 const MetaMap &buildMetaMap(const ElementType *, 90 const Notation *, 91 const AttributeList &, 92 const AttributeList *linkAtts, 93 unsigned suppressFlags); 94 void considerSupr(const AttributeList &atts, 95 const AttributeList *linkAtts, 96 unsigned &thisSuppressFlags, 97 unsigned &newSuppressFlags, 98 Boolean &inhibitCache, 99 unsigned &arcSuprIndex); 100 void considerIgnD(const AttributeList &atts, 101 const AttributeList *linkAtts, 102 unsigned thisSuppressFlags, 103 unsigned &newSuppressFlags, 104 Boolean &inhibitCache, 105 unsigned &arcSuprIndex); 106 const Attributed *considerForm(const AttributeList &atts, 107 const AttributeList *linkAtts, 108 const StringC &name, 109 Boolean isNotation, 110 unsigned thisSuppressFlags, 111 unsigned &newSuppressFlags, 112 Boolean &inhibitCache, 113 unsigned &arcFormIndex); 114 const Attributed *autoForm(const AttributeList &atts, 115 const StringC &name, 116 Boolean isNotation, 117 unsigned thisSuppressFlags, 118 unsigned &newSuppressFlags, 119 Boolean &inhibitCache, 120 unsigned &idIndex); 121 const Text *considerNamer(const AttributeList &atts, 122 Boolean &inhibitCache, 123 unsigned &arcNamerIndex); 124 void buildAttributeMapRename(MetaMap &map, 125 const Text &rename, 126 const AttributeList &atts, 127 const AttributeList *linkAtts, 128 Vector<PackedBoolean> &attRenamed); 129 void buildAttributeMapRest(MetaMap &map, 130 const AttributeList &atts, 131 const AttributeList *linkAtts, 132 const Vector<PackedBoolean> &attRenamed); 133 Boolean matchName(const StringC &name, const char *key); 134 void split(const Text &text, 135 Char space, 136 Vector<StringC> &tokens, 137 Vector<size_t> &tokenPos); 138 Boolean mapAttributes(const AttributeList &from, 139 const AttributeList *fromLink, 140 const Text *content, 141 AttributeList &to, 142 ConstPtr<AttributeValue> &arcContent, 143 const MetaMap &map); 144 void supportAttributes(const AttributeList &); 145 void processArcOpts(const AttributeList &atts); 146 void processArcQuant(const Text &); 147 ConstPtr<Entity> makeDtdEntity(const Notation *); 148 void mungeMetaDtd(Dtd &metaDtd, const Dtd &docDtd); 149 Boolean mungeDataEntity(ExternalDataEntity &entity); 150 void emitArcContent(const Text &text, 151 EventHandler &handler, 152 Allocator &allocator); 153 154 Boolean valid_; 155 StringC name_; 156 Messenger *mgr_; 157 ConstPtr<Dtd> docDtd_; 158 Ptr<Dtd> metaDtd_; 159 ConstPtr<Syntax> docSyntax_; 160 ConstPtr<Syntax> metaSyntax_; 161 ConstPtr<Sd> docSd_; 162 enum ReservedName { 163 rArcFormA, 164 rArcNamrA, 165 rArcSuprA, 166 rArcIgnDA, 167 rArcDocF, 168 rArcSuprF, 169 rArcBridF, 170 rArcDataF, 171 rArcAuto, 172 rArcIndr, 173 rArcDTD, 174 rArcQuant 175 }; 176 enum { nReserve = rArcQuant + 1 }; 177 StringC supportAtts_[nReserve]; 178 Boolean arcDtdIsParam_; 179 Boolean arcAuto_; 180 Vector<StringC> arcOpts_; 181 StringC rniContent_; 182 StringC rniArcCont_; 183 StringC rniDefault_; 184 enum { 185 isArc = 01, 186 suppressForm = 02, 187 suppressSupr = 04, 188 ignoreData = 010, 189 condIgnoreData = 020, 190 // recovering from invalid data 191 recoverData = 040 192 }; 193 Vector<unsigned> openElementFlags_; 194 AttributeList attributeList_; 195 NCVector<Owner<MetaMapCache> > metaMapCache_; 196 MetaMap noCacheMetaMap_; 197 NamedTable<Id> idTable_; 198 Vector<ConstPtr<AttributeValue> > currentAttributes_; 199 ConstPtr<Notation> defaultNotation_; 200 Boolean errorIdref_; 201 ArcDirector *director_; 202 EventHandler *docHandler_; 203 Owner<EventHandler> ownEventHandler_; 204 size_t docIndex_; 205 }; 206 207 #ifdef SP_NAMESPACE 208 } 209 #endif 210 211 #endif /* not ArcProcessor_INCLUDED */ 212