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