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