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