1 // Copyright (c) 1995, 1996 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
4
5 #ifndef GenericEventHandler_INCLUDED
6 #define GenericEventHandler_INCLUDED 1
7
8 #ifdef __GNUG__
9 #pragma interface
10 #endif
11
12 // Must include Boolean.h before SGMLApplication.h.
13
14 #include "Boolean.h"
15 #include "SGMLApplication.h"
16 #include "Event.h"
17 #include "MessageReporter.h"
18 #include "ErrorCountEventHandler.h"
19
20 #ifdef SP_NAMESPACE
21 namespace SP_NAMESPACE {
22 #endif
23
24 class SP_API GenericEventHandler : public ErrorCountEventHandler {
25 public:
26 GenericEventHandler(SGMLApplication &, bool generalEntities);
27 ~GenericEventHandler();
28 void message(MessageEvent *);
29 void appinfo(AppinfoEvent *);
30 void startDtd(StartDtdEvent *);
31 void endDtd(EndDtdEvent *);
32 void endProlog(EndPrologEvent *);
33 void entityDefaulted(EntityDefaultedEvent *);
34 void startElement(StartElementEvent *);
35 void endElement(EndElementEvent *);
36 void data(DataEvent *);
37 void pi(PiEvent *);
38 void sdataEntity(SdataEntityEvent *);
39 void externalDataEntity(ExternalDataEntityEvent *);
40 void subdocEntity(SubdocEntityEvent *);
41 void nonSgmlChar(NonSgmlCharEvent *);
42 void commentDecl(CommentDeclEvent *);
43 void ignoredChars(IgnoredCharsEvent *);
44 void markedSectionStart(MarkedSectionStartEvent *);
45 void markedSectionEnd(MarkedSectionEndEvent *);
46 void *allocate(size_t);
47 void freeAll();
48 void freeAll1();
49
50 struct Block {
51 Block *next;
52 char *mem;
53 size_t size;
54 };
55 static void setString(SGMLApplication::CharString &, const StringC &);
56 static void clearString(SGMLApplication::CharString &);
57 virtual void reportMessage(const Message &msg, StringC &) = 0;
58 private:
59 GenericEventHandler(const GenericEventHandler &); // undefined
60 void operator=(const GenericEventHandler &); // undefined
61 void setLocation(SGMLApplication::Position &, const Location &);
62 void setLocation1(SGMLApplication::Position &, const Location &);
63 void setAttributes(const SGMLApplication::Attribute *&attributes,
64 const AttributeList &attributeList);
65 void setExternalId(SGMLApplication::ExternalId &to,
66 const ExternalId &from);
67 void setEntity(SGMLApplication::Entity &to, const Entity &from);
68 void setNotation(SGMLApplication::Notation &, const Notation ¬ation);
69 static void clearNotation(SGMLApplication::Notation &);
70 static void clearExternalId(SGMLApplication::ExternalId &);
71 ConstPtr<Origin> lastOrigin_;
72 SGMLApplication::OpenEntityPtr openEntityPtr_;
73 size_t firstBlockUsed_;
74 size_t firstBlockSpare_;
75 Block *freeBlocks_;
76 Block *allocBlocks_;
77 bool generalEntities_;
78 SGMLApplication *app_;
79 };
80
81 class SP_API MsgGenericEventHandler : public GenericEventHandler {
82 public:
83 MsgGenericEventHandler(SGMLApplication &,
84 bool generalEntities,
85 MessageReporter &reporter,
86 const bool *messagesInhibitedPtr);
87 void reportMessage(const Message &msg, StringC &);
88 private:
89 MsgGenericEventHandler(const MsgGenericEventHandler &); // undefined
90 void operator=(const MsgGenericEventHandler &); // undefined
91 struct WrapReporter {
WrapReporterWrapReporter92 WrapReporter(MessageReporter *r) : reporter(r), origStream(0) {
93 origStream = reporter->releaseMessageStream();
94 reporter->setMessageStream(&strStream);
95 }
~WrapReporterWrapReporter96 ~WrapReporter() {
97 if (origStream) {
98 reporter->releaseMessageStream();
99 reporter->setMessageStream(origStream);
100 }
101 }
102 MessageReporter *reporter;
103 OutputCharStream *origStream;
104 StrOutputCharStream strStream;
105 };
106 const bool *messagesInhibitedPtr_;
107 MessageReporter *reporter_;
108 };
109
110 inline void
setString(SGMLApplication::CharString & to,const StringC & from)111 GenericEventHandler::setString(SGMLApplication::CharString &to,
112 const StringC &from)
113 {
114 to.ptr = from.data();
115 to.len = from.size();
116 }
117
118 inline
clearString(SGMLApplication::CharString & to)119 void GenericEventHandler::clearString(SGMLApplication::CharString &to)
120 {
121 to.len = 0;
122 }
123
124 #ifdef SP_NAMESPACE
125 }
126 #endif
127
128 #endif /* not GenericEventHandler_INCLUDED */
129