ArcProcessor.h 7.6 KB

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