nsgmls: fix up some gcc 4.8 warnings.
[oweals/cde.git] / cde / programs / nsgmls / RastEventHandler.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: RastEventHandler.h /main/1 1996/07/29 17:02:31 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef RastEventHandler_INCLUDED
28 #define RastEventHandler_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "Event.h"
34 #include "Vector.h"
35 #include "Vector.h"
36 #include "Boolean.h"
37 #include "Vector.h"
38 #include "StringC.h"
39 #include "types.h"
40 #include "OutputCharStream.h"
41 #include "LinkProcess.h"
42 #include "Message.h"
43 #include "Link.h"
44 #include "IQueue.h"
45 #include "ErrorCountEventHandler.h"
46
47 #include <limits.h>
48 #include <stddef.h>
49
50 #ifdef SP_NAMESPACE
51 namespace SP_NAMESPACE {
52 #endif
53
54 class AttributeList;
55 class ExternalDataEntity;
56 class SubdocEntity;
57 class ExternalId;
58 class InternalEntity;
59 class SgmlParser;
60
61 class RastPrintable {
62 public:
63   RastPrintable();
64   int operator()(Char c) const;
65 private:
66   char v_[UCHAR_MAX + 1];
67 };
68
69 class RastEventHandler;
70
71 class RastLinkProcess : public LinkProcess {
72 public:
73   RastLinkProcess();
74   void setHandler(RastEventHandler *);
75   Boolean selectLinkRule(const Vector<const AttributeList *> &linkAttributes,
76                          const Location &location,
77                          size_t &selected);
78   void swap(RastLinkProcess &);
79 private:
80   Boolean selectLinkRulePi(const StringC &str,
81                            const Location &loc,
82                            const Vector<const AttributeList *> &linkAttributes,
83                            size_t &selected);
84
85   RastLinkProcess(const RastLinkProcess &); // undefined
86   void operator=(RastLinkProcess &);        // undefined
87   RastEventHandler *rast_;
88 };
89
90 struct LinkRulePi : public Link {
91   StringC pi;
92   Location loc;
93 };
94
95 class RastSubdocState {
96 public:
97   RastSubdocState();
98   RastSubdocState(SgmlParser *, RastEventHandler *);
99   void init(SgmlParser *, RastEventHandler *);
100   void swap(RastSubdocState &);
101 protected:
102   SgmlParser *parser_;
103   Boolean hadActiveLpdOrDtd_;
104   Location activeLpdOrDtdLocation_;
105   Vector<StringC> activeLinkTypes_;
106   Boolean hadDocumentElement_;
107   RastLinkProcess linkProcess_;
108   Boolean haveLinkProcess_;
109   Owner<EndPrologEvent> endPrologEvent_;
110   Vector<PackedBoolean> parseSubdocQueue_;
111   IQueue<LinkRulePi> linkRuleQueue_;
112   enum AttributeType {
113     dtdAttribute,
114     linkAttribute,
115     resultAttribute,
116     simpleAttribute
117     };
118   enum { nAttributeType = simpleAttribute + 1 };
119   Vector<Vector<size_t> > attributeSortOrder_[nAttributeType];
120 private:
121   RastSubdocState(const RastSubdocState &); // undefined
122   void operator=(const RastSubdocState &);  // undefined
123   friend class RastLinkProcess;
124 };
125
126 class RastEventHandler : public ErrorCountEventHandler,
127                          private RastSubdocState,
128                          private Messenger {
129 public:
130   RastEventHandler(SgmlParser *, Messenger *);
131   void data(DataEvent *);
132   void startElement(StartElementEvent *);
133   void endElement(EndElementEvent *);
134   void pi(PiEvent *);
135   void sdataEntity(SdataEntityEvent *);
136   void externalDataEntity(ExternalDataEntityEvent *);
137   void subdocEntity(SubdocEntityEvent *);
138   void sgmlDecl(SgmlDeclEvent *);
139   void endProlog(EndPrologEvent *);
140   void uselink(UselinkEvent *);
141   virtual void truncateOutput();
142   void end();
143   void setOutputStream(OutputCharStream *os);
144   // static const char *messageText(int);
145   // static const char messageSource[];
146 protected:
147   void initMessage(Message &);
148   void dispatchMessage(const Message &);
149   void dispatchMessage(Message &);
150 private:
151   RastEventHandler(const RastEventHandler &); // undefined
152   void operator=(const RastEventHandler &);   // undefined
153
154   enum LineType { dataLine = '|', markupLine = '!' };
155   void lines(LineType, const Char *p, size_t length);
156   enum { maxLineLength = 60 };
157   enum { RS = '\n', RE = '\r', TAB = '\t' };
158 #if 0
159   static const RastPrintable printable;
160 #else
161   static RastPrintable printable;
162 #endif
163   int lineLength_;
164   OutputCharStream *os_;
165   StringC rastParseSubdocYesString_;
166   StringC rastParseSubdocNoString_;
167   StringC rastActiveLpdString_;
168   StringC rastLinkRuleString_;
169   unsigned piErrorCount_;
170   Messenger *mgr_;
171
172   int lexCmp(const StringC &s1, const StringC &s2);
173   void flushLine(LineType);
174   void attributeInfo(const AttributeList &, AttributeType);
175   void externalEntityInfo(const ExternalDataEntity *, AttributeType);
176   void subdocEntityInfo(const SubdocEntity *,
177                         const Ptr<InputSourceOrigin> &entityOrigin,
178                         Boolean referenced);
179   void externalIdInfo(const ExternalId &);
180   void internalEntityInfo(const InternalEntity *);
181   void queueParseSubdoc(Boolean);
182   Boolean parseNextSubdoc();
183   Boolean interpretRastPi(const Char *data, size_t dataLength,
184                           const Location &);
185   void activeLinks();
186   void simpleLinkInfo();
187   void impliedSourceLinkRules();
188   
189   OutputCharStream &os();
190   friend class RastLinkProcess;
191 };
192
193 inline
194 int RastPrintable::operator()(Char c) const
195 {
196   return c <= UCHAR_MAX ? v_[c] : 0;
197 }
198
199 inline
200 void RastEventHandler::setOutputStream(OutputCharStream *os)
201 {
202   os_ = os;
203 }
204
205 inline
206 OutputCharStream &RastEventHandler::os()
207 {
208   return *os_;
209 }
210
211 #ifdef SP_NAMESPACE
212 }
213 #endif
214
215 #endif /* not RastEventHandler_INCLUDED */