xref: /onnv-gate/usr/src/cmd/man/src/util/nsgmls.src/lib/Message.cxx (revision 0:68f95e015346)
1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
4 
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8 
9 #include "splib.h"
10 #include "Message.h"
11 #include "MessageArg.h"
12 
13 #ifdef SP_NAMESPACE
14 namespace SP_NAMESPACE {
15 #endif
16 
MessageFragment(unsigned module,unsigned number,const char * text)17 MessageFragment::MessageFragment(unsigned module, unsigned number, const char *
18 #ifndef SP_NO_MESSAGE_TEXT
19 				 text
20 #endif
21 				 )
22 : module_(module),
23 #ifndef SP_NO_MESSAGE_TEXT
24   text_(text),
25 #endif
26   number_(number)
27 {
28 }
29 
MessageType(Severity severity,unsigned module,unsigned number,const char * text,const char * auxText)30 MessageType::MessageType(Severity severity, unsigned module, unsigned number,
31 			 const char *text, const char *
32 #ifndef SP_NO_MESSAGE_TEXT
33 	     		 auxText
34 #endif
35 			 )
36 :
37 #ifndef SP_NO_MESSAGE_TEXT
38   auxText_(auxText),
39 #endif
40   MessageFragment(module, number, text)
41 {
42   spare_ = severity;
43 }
44 
MessageType0(Severity severity,unsigned module,unsigned number,const char * text)45 MessageType0::MessageType0(Severity severity, unsigned module, unsigned number,
46 			   const char *text)
47 : MessageType(severity, module, number, text)
48 {
49 }
50 
MessageType1(Severity severity,unsigned module,unsigned number,const char * text)51 MessageType1::MessageType1(Severity severity, unsigned module, unsigned number,
52 			   const char *text)
53 : MessageType(severity, module, number, text)
54 {
55 }
56 
MessageType2(Severity severity,unsigned module,unsigned number,const char * text)57 MessageType2::MessageType2(Severity severity, unsigned module, unsigned number,
58 			   const char *text)
59 : MessageType(severity, module, number, text)
60 {
61 }
62 
MessageType3(Severity severity,unsigned module,unsigned number,const char * text)63 MessageType3::MessageType3(Severity severity, unsigned module, unsigned number,
64 			   const char *text)
65 : MessageType(severity, module, number, text)
66 {
67 }
68 
MessageType4(Severity severity,unsigned module,unsigned number,const char * text)69 MessageType4::MessageType4(Severity severity, unsigned module, unsigned number,
70 			   const char *text)
71 : MessageType(severity, module, number, text)
72 {
73 }
74 
MessageType5(Severity severity,unsigned module,unsigned number,const char * text)75 MessageType5::MessageType5(Severity severity, unsigned module, unsigned number,
76 			   const char *text)
77 : MessageType(severity, module, number, text)
78 {
79 }
80 
MessageType6(Severity severity,unsigned module,unsigned number,const char * text)81 MessageType6::MessageType6(Severity severity, unsigned module, unsigned number,
82 			   const char *text)
83 : MessageType(severity, module, number, text)
84 {
85 }
86 
MessageType0L(Severity severity,unsigned module,unsigned number,const char * text,const char * auxText)87 MessageType0L::MessageType0L(Severity severity, unsigned module, unsigned number,
88 			     const char *text, const char *auxText)
89 : MessageType(severity, module, number, text, auxText)
90 {
91 }
92 
MessageType1L(Severity severity,unsigned module,unsigned number,const char * text,const char * auxText)93 MessageType1L::MessageType1L(Severity severity, unsigned module, unsigned number,
94 			     const char *text, const char *auxText)
95 : MessageType(severity, module, number, text, auxText)
96 {
97 }
98 
OpenElementInfo()99 OpenElementInfo::OpenElementInfo()
100 : included(0), matchIndex(0)
101 {
102 }
103 
Message()104 Message::Message()
105 {
106 }
107 
Message(int nArgs)108 Message::Message(int nArgs)
109 : args(nArgs)
110 {
111 }
112 
swap(Message & to)113 void Message::swap(Message &to)
114 {
115   const MessageType *tem = type;
116   type = to.type;
117   to.type = tem;
118   to.loc.swap(loc);
119   to.auxLoc.swap(auxLoc);
120   args.swap(to.args);
121   openElementInfo.swap(to.openElementInfo);
122 }
123 
Messenger()124 Messenger::Messenger()
125 : haveNextLocation_(0)
126 {
127 }
128 
~Messenger()129 Messenger::~Messenger()
130 {
131 }
132 
dispatchMessage(Message & msg)133 void Messenger::dispatchMessage(Message &msg)
134 {
135   const Message &tem = msg;
136   dispatchMessage(tem);
137 }
138 
message(const MessageType0 & type)139 void Messenger::message(const MessageType0 &type)
140 {
141   Message msg(0);
142   doInitMessage(msg);
143   msg.type = &type;
144   dispatchMessage(msg);
145 }
146 
message(const MessageType1 & type,const MessageArg & arg0)147 void Messenger::message(const MessageType1 &type, const MessageArg &arg0)
148 {
149   Message msg(1);
150   doInitMessage(msg);
151   msg.args[0] = arg0.copy();
152   msg.type = &type;
153   dispatchMessage(msg);
154 }
155 
message(const MessageType2 & type,const MessageArg & arg0,const MessageArg & arg1)156 void Messenger::message(const MessageType2 &type,
157 			const MessageArg &arg0,
158 			const MessageArg &arg1)
159 {
160   Message msg(2);
161   doInitMessage(msg);
162   msg.args[0] = arg0.copy();
163   msg.args[1] = arg1.copy();
164   msg.type = &type;
165   dispatchMessage(msg);
166 }
167 
message(const MessageType3 & type,const MessageArg & arg0,const MessageArg & arg1,const MessageArg & arg2)168 void Messenger::message(const MessageType3 &type,
169 			const MessageArg &arg0,
170 			const MessageArg &arg1,
171 			const MessageArg &arg2)
172 {
173   Message msg(3);
174   doInitMessage(msg);
175   msg.args[0] = arg0.copy();
176   msg.args[1] = arg1.copy();
177   msg.args[2] = arg2.copy();
178   msg.type = &type;
179   dispatchMessage(msg);
180 }
181 
message(const MessageType4 & type,const MessageArg & arg0,const MessageArg & arg1,const MessageArg & arg2,const MessageArg & arg3)182 void Messenger::message(const MessageType4 &type,
183 			const MessageArg &arg0,
184 			const MessageArg &arg1,
185 			const MessageArg &arg2,
186 			const MessageArg &arg3)
187 {
188   Message msg(4);
189   doInitMessage(msg);
190   msg.args[0] = arg0.copy();
191   msg.args[1] = arg1.copy();
192   msg.args[2] = arg2.copy();
193   msg.args[3] = arg3.copy();
194   msg.type = &type;
195   dispatchMessage(msg);
196 }
197 
message(const MessageType5 & type,const MessageArg & arg0,const MessageArg & arg1,const MessageArg & arg2,const MessageArg & arg3,const MessageArg & arg4)198 void Messenger::message(const MessageType5 &type,
199 			const MessageArg &arg0,
200 			const MessageArg &arg1,
201 			const MessageArg &arg2,
202 			const MessageArg &arg3,
203 			const MessageArg &arg4)
204 {
205   Message msg(5);
206   doInitMessage(msg);
207   msg.args[0] = arg0.copy();
208   msg.args[1] = arg1.copy();
209   msg.args[2] = arg2.copy();
210   msg.args[3] = arg3.copy();
211   msg.args[4] = arg4.copy();
212   msg.type = &type;
213   dispatchMessage(msg);
214 }
215 
message(const MessageType6 & type,const MessageArg & arg0,const MessageArg & arg1,const MessageArg & arg2,const MessageArg & arg3,const MessageArg & arg4,const MessageArg & arg5)216 void Messenger::message(const MessageType6 &type,
217 			const MessageArg &arg0,
218 			const MessageArg &arg1,
219 			const MessageArg &arg2,
220 			const MessageArg &arg3,
221 			const MessageArg &arg4,
222 			const MessageArg &arg5)
223 {
224   Message msg(6);
225   doInitMessage(msg);
226   msg.args[0] = arg0.copy();
227   msg.args[1] = arg1.copy();
228   msg.args[2] = arg2.copy();
229   msg.args[3] = arg3.copy();
230   msg.args[4] = arg4.copy();
231   msg.args[5] = arg5.copy();
232   msg.type = &type;
233   dispatchMessage(msg);
234 }
235 
message(const MessageType0L & type,const Location & loc)236 void Messenger::message(const MessageType0L &type, const Location &loc)
237 {
238   Message msg(0);
239   doInitMessage(msg);
240   msg.type = &type;
241   msg.auxLoc = loc;
242   dispatchMessage(msg);
243 }
244 
message(const MessageType1L & type,const MessageArg & arg0,const Location & loc)245 void Messenger::message(const MessageType1L &type, const MessageArg &arg0,
246 			const Location &loc)
247 {
248   Message msg(1);
249   doInitMessage(msg);
250   msg.args[0] = arg0.copy();
251   msg.type = &type;
252   msg.auxLoc = loc;
253   dispatchMessage(msg);
254 }
255 
256 
setNextLocation(const Location & loc)257 void Messenger::setNextLocation(const Location &loc)
258 {
259   haveNextLocation_ = 1;
260   nextLocation_ = loc;
261 }
262 
initMessage(Message &)263 void Messenger::initMessage(Message &)
264 {
265 }
266 
doInitMessage(Message & msg)267 void Messenger::doInitMessage(Message &msg)
268 {
269   initMessage(msg);
270   if (haveNextLocation_) {
271     msg.loc = nextLocation_;
272     haveNextLocation_ = 0;
273   }
274 }
275 
ForwardingMessenger(Messenger & to)276 ForwardingMessenger::ForwardingMessenger(Messenger &to)
277 : to_(&to)
278 {
279 }
280 
dispatchMessage(Message & msg)281 void ForwardingMessenger::dispatchMessage(Message &msg)
282 {
283   to_->dispatchMessage(msg);
284 }
285 
dispatchMessage(const Message & msg)286 void ForwardingMessenger::dispatchMessage(const Message &msg)
287 {
288   to_->dispatchMessage(msg);
289 }
290 
initMessage(Message & msg)291 void ForwardingMessenger::initMessage(Message &msg)
292 {
293   to_->initMessage(msg);
294 }
295 
ParentLocationMessenger(Messenger & mgr)296 ParentLocationMessenger::ParentLocationMessenger(Messenger &mgr)
297 : ForwardingMessenger(mgr)
298 {
299 }
300 
initMessage(Message & msg)301 void ParentLocationMessenger::initMessage(Message &msg)
302 {
303   ForwardingMessenger::initMessage(msg);
304   if (!msg.loc.origin().isNull())
305     msg.loc = msg.loc.origin()->parent();
306 }
307 
NullMessenger()308 NullMessenger::NullMessenger()
309 {
310 }
311 
dispatchMessage(const Message &)312 void NullMessenger::dispatchMessage(const Message &)
313 {
314 }
315 
316 #ifdef SP_NAMESPACE
317 }
318 #endif
319