Remove Unixware and openserver support
[oweals/cde.git] / cde / programs / nsgmls / SGMLApplication.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 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: SGMLApplication.h /main/1 1996/07/29 17:03:14 cde-hp $ */
24 // Copyright (c) 1995 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef SGMLApplication_INCLUDED
28 #define SGMLApplication_INCLUDED 1
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
33
34 #include <stddef.h>
35
36 #ifndef SP_API
37 #define SP_API /* as nothing */
38 #endif
39
40 class SP_API SGMLApplication {
41 public:
42 #ifdef SP_MULTI_BYTE
43   typedef unsigned short Char;
44 #else
45   typedef unsigned char Char;
46 #endif
47   // A Position represents a position in an OpenEntity.
48   // The meaning of a Position depends on the
49   // particular implementation of OpenEntity.
50   // It might be a line number or it might be
51   // an offset in the entity.  The only thing
52   // that can be done with Position is to use
53   // it with an OpenEntityPtr to get a Location.
54   typedef unsigned long Position;
55   struct CharString {
56     const Char *ptr;
57     size_t len;
58   };
59   struct ExternalId {
60     bool haveSystemId;
61     bool havePublicId;
62     bool haveGeneratedSystemId;
63     CharString systemId;        // valid only if haveSystemId is true
64     CharString publicId;        // valid only if havePublicId is true
65     CharString generatedSystemId; // valid if haveGeneratedSystemId is true
66   };
67   struct Notation {
68     CharString name;
69     ExternalId externalId;
70   };
71   struct Attribute;
72   struct Entity {
73     CharString name;
74     enum DataType { sgml, cdata, sdata, ndata, subdoc, pi };
75     enum DeclType { general, parameter, doctype, linktype };
76     DataType dataType;
77     DeclType declType;
78     bool isInternal;
79     // Following valid if isInternal is true
80     CharString text;
81     // Following valid if isInternal is false
82     ExternalId externalId;
83     size_t nAttributes;
84     const Attribute *attributes;
85     Notation notation;
86   };
87   struct Attribute {
88     CharString name;
89     enum Type {
90       invalid,
91       implied,
92       cdata,
93       tokenized
94       };
95     Type type;
96     enum Defaulted {
97       specified,                // not defaulted
98       definition,               // defaulted from definition
99       current                   // defaulted from current value
100       };
101     Defaulted defaulted;        // non-ESIS; valid only if type != implied
102     struct CdataChunk {
103       bool isSdata;
104       CharString data;
105       CharString entityName;    // non-ESIS; optional for SDATA chunks
106     };
107     // Following valid if type == cdata
108     size_t nCdataChunks;
109     const CdataChunk *cdataChunks; // valid if type == cdata
110     // Following valid if type == tokenized
111     CharString tokens; // separated by spaces
112     bool isId;         // non-ESIS (probably)
113     bool isGroup;      // non-ESIS
114     size_t nEntities;
115     const Entity *entities;
116     // length of notation.name will be 0 if no notation
117     Notation notation;
118   };
119   struct PiEvent {
120     Position pos;
121     CharString data;
122     CharString entityName;      // non-ESIS; optional for PI entities
123   };
124   struct StartElementEvent {
125     Position pos;
126     enum ContentType {
127       empty,                    // declared EMPTY or with CONREF attribute
128       cdata,
129       rcdata,
130       mixed,
131       element
132       };
133     CharString gi;
134     ContentType contentType;    // non-ESIS
135     bool included;              // non-ESIS
136     size_t nAttributes;
137     const Attribute *attributes;
138   };
139       
140   struct EndElementEvent {
141     Position pos;
142     CharString gi;
143   };
144   struct DataEvent {
145     Position pos;
146     CharString data;
147   };
148   struct SdataEvent {
149     Position pos;
150     CharString text;
151     CharString entityName;      // non-ESIS; optional
152   };
153   struct ExternalDataEntityRefEvent {
154     Position pos;
155     Entity entity;
156   };
157   struct SubdocEntityRefEvent {
158     Position pos;
159     Entity entity;
160   };
161   struct ErrorEvent {
162     Position pos;
163     enum Type {
164       info,                     // not an error
165       warning,                  // not an error
166       quantity,
167       idref,
168       capacity,
169       otherError
170       };
171     Type type;
172     CharString message;
173   };
174   struct AppinfoEvent {
175     Position pos;
176     bool none;
177     CharString string;
178   };
179   struct StartDtdEvent {
180     Position pos;
181     CharString name;
182     bool haveExternalId;
183     ExternalId externalId;
184   };
185   struct EndDtdEvent {
186     Position pos;
187     CharString name;
188   };
189   struct EndPrologEvent {
190     Position pos;
191   };
192   // non-ESIS
193   struct GeneralEntityEvent {
194     // no position
195     Entity entity;
196   };
197   // non-ESIS
198   struct CommentDeclEvent {
199     Position pos;
200     size_t nComments;
201     const CharString *comments;
202     const CharString *seps;
203   };
204   // non-ESIS
205   struct MarkedSectionStartEvent {
206     Position pos;
207     enum Status {
208       include,
209       rcdata,
210       cdata,
211       ignore
212     };
213     Status status;
214     struct Param {
215       enum Type {
216         temp,
217         include,
218         rcdata,
219         cdata,
220         ignore,
221         entityRef
222         };
223       Type type;
224       CharString entityName;
225     };
226     size_t nParams;
227     const Param *params;
228   };
229   // non-ESIS
230   struct MarkedSectionEndEvent {
231     Position pos;
232     enum Status {
233       include,
234       rcdata,
235       cdata,
236       ignore
237     };
238     Status status;
239   };
240   struct IgnoredCharsEvent {
241     Position pos;
242     CharString data;
243   };
244   class OpenEntityPtr;
245   struct SP_API Location {
246     Location();
247     Location(const OpenEntityPtr &, Position);
248     void init();
249
250     unsigned long lineNumber;
251     unsigned long columnNumber;
252     unsigned long byteOffset;
253     unsigned long entityOffset;
254     CharString entityName;
255     CharString filename;
256     const void *other;
257   };
258   class OpenEntity;
259   class SP_API OpenEntityPtr {
260   public:
261     OpenEntityPtr();
262     OpenEntityPtr(const OpenEntityPtr &);
263     void operator=(const OpenEntityPtr &);
264     void operator=(OpenEntity *);
265     ~OpenEntityPtr();
266     const OpenEntity *operator->() const;
267     operator int() const;
268   private:
269     OpenEntity *ptr_;
270   };
271   class SP_API OpenEntity {
272   public:
273     OpenEntity();
274     virtual ~OpenEntity();
275     virtual Location location(Position) const = 0;
276   private:
277     OpenEntity(const OpenEntity &); // undefined
278     void operator=(const OpenEntity &); // undefined
279     unsigned count_;
280     friend class OpenEntityPtr;
281   };
282   virtual ~SGMLApplication();
283   virtual void appinfo(const AppinfoEvent &);
284   virtual void startDtd(const StartDtdEvent &);
285   virtual void endDtd(const EndDtdEvent &);
286   virtual void endProlog(const EndPrologEvent &);
287   virtual void startElement(const StartElementEvent &);
288   virtual void endElement(const EndElementEvent &);
289   virtual void data(const DataEvent &);
290   virtual void sdata(const SdataEvent &);
291   virtual void pi(const PiEvent &);
292   virtual void externalDataEntityRef(const ExternalDataEntityRefEvent &);
293   virtual void subdocEntityRef(const SubdocEntityRefEvent &);
294   virtual void commentDecl(const CommentDeclEvent &);
295   virtual void markedSectionStart(const MarkedSectionStartEvent &);
296   virtual void markedSectionEnd(const MarkedSectionEndEvent &);
297   virtual void ignoredChars(const IgnoredCharsEvent &);
298   virtual void generalEntity(const GeneralEntityEvent &);
299   virtual void error(const ErrorEvent &);
300   virtual void openEntityChange(const OpenEntityPtr &);
301 };
302
303 inline
304 const SGMLApplication::OpenEntity *
305 SGMLApplication::OpenEntityPtr::operator->() const
306 {
307   return ptr_;
308 }
309
310 inline
311 void SGMLApplication::OpenEntityPtr::operator=(const OpenEntityPtr &ptr)
312 {
313   *this = ptr.ptr_;
314 }
315
316 inline
317 SGMLApplication::OpenEntityPtr::operator int() const
318 {
319   return ptr_ != 0;
320 }
321
322 #endif /* not SGMLApplication_INCLUDED */