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