SGMLApplication.h 8.0 KB

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