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