Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / ArcProcessor.h
1 /* $XConsortium: ArcProcessor.h /main/1 1996/07/29 16:46:28 cde-hp $ */
2 // Copyright (c) 1996 James Clark
3 // See the file COPYING for copying permission.
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             SP_CONST SP_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();
68   const ConstPtr<Dtd> &dtdPointer() const { return metaDtd_; }
69   Boolean valid() const { return valid_; }
70   void checkIdrefs();
71   const StringC &name() const { return name_; }
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 initNotationSet(const Location &loc);
145   const Attributed *considerNotation(const AttributeList &atts,
146                                      unsigned thisSuppressFlags,
147                                      Boolean &inhibitCache,
148                                      unsigned &notAttIndex);
149   void supportAttributes(const AttributeList &);
150   void processArcOpts(const AttributeList &atts);
151   void processArcQuant(const Text &);
152   ConstPtr<Entity> makeDtdEntity(const Notation *);
153   void mungeMetaDtd(Dtd &metaDtd, const Dtd &docDtd);
154   Boolean mungeDataEntity(ExternalDataEntity &entity);
155   void emitArcContent(const Text &text,
156                       EventHandler &handler,
157                       Allocator &allocator);
158
159   Boolean valid_;
160   StringC name_;
161   Messenger *mgr_;
162   ConstPtr<Dtd> docDtd_;
163   ConstPtr<Dtd> metaDtd_;
164   ConstPtr<Syntax> docSyntax_;
165   ConstPtr<Syntax> metaSyntax_;
166   ConstPtr<Sd> docSd_;
167   enum ReservedName {
168     rArcFormA,
169     rArcNamrA,
170     rArcSuprA,
171     rArcIgnDA,
172     rArcDocF,
173     rArcSuprF,
174     rArcBridF,
175     rArcDataF,
176     rArcAuto,
177     rArcIndr,
178     rArcDTD,
179     rArcQuant
180   };
181   enum { nReserve = rArcQuant + 1 };
182   StringC supportAtts_[nReserve];
183   Boolean arcDtdIsParam_;
184   Boolean arcAuto_;
185   Vector<StringC> arcOpts_;
186   StringC rniContent_;
187   StringC rniArcCont_;
188   StringC rniDefault_;
189   enum {
190     isArc = 01,
191     suppressForm = 02,
192     suppressSupr = 04,
193     ignoreData = 010,
194     condIgnoreData = 020,
195     // recovering from invalid data
196     recoverData = 040
197     };
198   Vector<unsigned> openElementFlags_;
199   AttributeList attributeList_;
200   NCVector<Owner<struct MetaMapCache> > metaMapCache_;
201   MetaMap noCacheMetaMap_;
202   NamedTable<Id> idTable_;
203   Vector<ConstPtr<AttributeValue> > currentAttributes_;
204   ConstPtr<Notation> defaultNotation_;
205   Boolean errorIdref_;
206   Boolean notationSetArch_;
207   ArcDirector *director_;
208   EventHandler *docHandler_;
209   Owner<EventHandler> ownEventHandler_;
210   size_t docIndex_;
211 };
212
213 #ifdef SP_NAMESPACE
214 }
215 #endif
216
217 #endif /* not ArcProcessor_INCLUDED */