Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / Event.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 librararies 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: Event.C /main/1 1996/07/29 16:51:15 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 #include "splib.h"
31 #include "Event.h"
32 #include "Entity.h"
33 #include "Attribute.h"
34 #include "EventQueue.h"
35
36 #ifdef SP_NAMESPACE
37 namespace SP_NAMESPACE {
38 #endif
39
40 void Event::copyData()
41 {
42 }
43
44 LocatedEvent::LocatedEvent(Type type, const Location &location)
45 : location_(location), Event(type)
46 {
47 }
48
49 MarkupEvent::MarkupEvent(Type type)
50 : LocatedEvent(type, Location())
51 {
52 }
53
54 MarkupEvent::MarkupEvent(Type type, const Location &loc, Markup *markup)
55 : LocatedEvent(type, loc)
56 {
57   if (markup)
58     markup->swap(markup_);
59 }
60
61 StartElementEvent::StartElementEvent(const ElementType *elementType,
62                                      const ConstPtr<Dtd> &dtd,
63                                      AttributeList *attributes,
64                                      const Location &startLocation,
65                                      Markup *markup)
66 : LocatedEvent(startElement, startLocation),
67   elementType_(elementType),
68   dtd_(dtd),
69   included_(0),
70   copied_(0),
71   markup_(markup),
72   attributes_(attributes)
73 {
74 }
75
76 StartElementEvent::~StartElementEvent()
77 {
78   if (copied_) {
79     delete attributes_;
80     delete markup_;
81   }
82 }
83
84 void StartElementEvent::copyData()
85 {
86   if (!copied_) {
87     {
88       AttributeList *p = new AttributeList;
89       attributes_->swap(*p);
90       attributes_ = p;
91     }
92     if (markup_) {
93       Markup *p = new Markup;
94       markup_->swap(*p);
95       markup_ = p;
96     }
97     copied_ = 1;
98   }
99 }
100
101 EndElementEvent::EndElementEvent(const ElementType *elementType,
102                                  const ConstPtr<Dtd> &dtd,
103                                  const Location &startLocation,
104                                  Markup *markup)
105 : LocatedEvent(endElement, startLocation),
106   elementType_(elementType),
107   dtd_(dtd),
108   included_(0),
109   copied_(0),
110   markup_(markup)
111 {
112 }
113
114 EndElementEvent::~EndElementEvent()
115 {
116   if (copied_)
117     delete markup_;
118 }
119
120 void EndElementEvent::copyData()
121 {
122   if (!copied_) {
123     if (markup_) {
124       Markup *p = new Markup;
125       markup_->swap(*p);
126       markup_ = p;
127     }
128     copied_ = 1;
129   }
130 }
131
132 DataEvent::DataEvent(Type type, const Char *p, size_t length,
133                      const Location &location)
134 : p_(p),length_(length), LocatedEvent(type, location)
135 {
136 }
137
138 const Entity *DataEvent::entity() const
139 {
140   return 0;
141 }
142
143 Boolean DataEvent::isRe(unsigned long &) const
144 {
145   return 0;
146 }
147
148 ImmediateDataEvent::ImmediateDataEvent(Type type, const Char *p, size_t length,
149                                        const Location &location,
150                                        Boolean copy)
151 : DataEvent(type, p, length, location), alloc_(0)
152 {
153   if (copy) 
154     ImmediateDataEvent::copyData();
155 }
156
157 ImmediateDataEvent::~ImmediateDataEvent()
158 {
159   if (alloc_)
160     delete [] alloc_;
161 }
162
163 void ImmediateDataEvent::copyData()
164 {
165   if (!alloc_) {
166     alloc_ = new Char[length_];
167     memcpy(alloc_, p_, length_*sizeof(Char));
168     p_ = alloc_;
169   }
170 }
171
172 ReEvent::ReEvent(const Char *p, const Location &location, unsigned long serial)
173 : ImmediateDataEvent(characterData, p, 1, location, 0),
174   serial_(serial)
175 {
176 }
177
178 Boolean ReEvent::isRe(unsigned long &serial) const
179 {
180   serial = serial_;
181   return 1;
182 }
183
184 DataEntityEvent::DataEntityEvent(Type type, const InternalEntity *entity,
185                                  const ConstPtr<Origin> &origin)
186 : DataEvent(type,
187             entity->string().data(),
188             entity->string().size(),
189             Location(origin, 0))
190 {
191 }
192
193 const Entity *DataEntityEvent::entity() const
194 {
195   return location().origin()->asEntityOrigin()->entity().pointer();
196 }
197
198 CdataEntityEvent::CdataEntityEvent(const InternalEntity *entity,
199                                    const ConstPtr<Origin> &origin)
200 : DataEntityEvent(characterData, entity, origin)
201 {
202 }
203
204 SdataEntityEvent::SdataEntityEvent(const InternalEntity *entity,
205                                    const ConstPtr<Origin> &origin)
206 : DataEntityEvent(sdataEntity, entity, origin)
207 {
208 }
209
210 MessageEvent::MessageEvent(const Message &m)
211 : Event(Event::message), message_(m)
212 {
213 }
214
215 MessageEvent::MessageEvent(Message &m)
216 : Event(Event::message)
217 {
218   m.swap(message_);
219 }
220
221 PiEvent::PiEvent(const Char *data, size_t dataLength, const Location &location)
222 : data_(data), dataLength_(dataLength), LocatedEvent(pi, location)
223 {
224 }
225
226 const Entity *PiEvent::entity() const
227 {
228   return 0;
229 }
230
231 PiEntityEvent::PiEntityEvent(const PiEntity *entity,
232                              const ConstPtr<Origin> &origin)
233 : PiEvent(entity->string().data(), entity->string().size(),
234           Location(origin, 0))
235 {
236 }
237
238 const Entity *PiEntityEvent::entity() const
239 {
240   return location().origin()->asEntityOrigin()->entity().pointer();
241 }
242
243 ImmediatePiEvent::ImmediatePiEvent(StringC &str, const Location &loc)
244 : PiEvent(str.data(), str.size(), loc)
245 {
246   str.swap(string_);
247 }
248
249 ExternalEntityEvent::ExternalEntityEvent(Type type, 
250                                          const ConstPtr<EntityOrigin> &origin)
251 : origin_(origin), Event(type)
252 {
253 }
254
255 ExternalDataEntityEvent::ExternalDataEntityEvent(const ExternalDataEntity *entity,
256                                                  const ConstPtr<EntityOrigin> &origin)
257 : dataEntity_(entity), ExternalEntityEvent(externalDataEntity, origin)
258 {
259 }
260
261 SubdocEntityEvent::SubdocEntityEvent(const SubdocEntity *entity,
262                                      const ConstPtr<EntityOrigin> &origin)
263 : subdocEntity_(entity), ExternalEntityEvent(subdocEntity, origin)
264 {
265 }
266
267 AppinfoEvent::AppinfoEvent(const Location &location)
268 : LocatedEvent(appinfo, location), appinfoNone_(1)
269 {
270 }
271
272 AppinfoEvent::AppinfoEvent(const Text &text, const Location &location)
273 : LocatedEvent(appinfo, location), appinfoNone_(0), appinfo_(text)
274 {
275 }
276
277 UselinkEvent::UselinkEvent(const ConstPtr<Lpd> &lpd,
278                            const LinkSet *linkSet,
279                            Boolean restore,
280                            const Location &loc,
281                            Markup *markup)
282 : MarkupEvent(uselink, loc, markup),
283   lpd_(lpd),
284   linkSet_(linkSet),
285   restore_(restore)
286 {
287 }
288
289 UsemapEvent::UsemapEvent(const ShortReferenceMap *map,
290                          Vector<const ElementType *> &elements,
291                          const ConstPtr<Dtd> &dtd,
292                          const Location &loc,
293                          Markup *markup)
294 : MarkupEvent(usemap, loc, markup),
295   map_(map),
296   dtd_(dtd)
297 {
298   elements.swap(elements_);
299 }
300
301 StartSubsetEvent::StartSubsetEvent(Type type,
302                                    const StringC &name,
303                                    const ConstPtr<Entity> &entity,
304                                    Boolean hasInternalSubset,
305                                    const Location &loc,
306                                    Markup *markup)
307 : name_(name), entity_(entity), hasInternalSubset_(hasInternalSubset),
308   MarkupEvent(type, loc, markup)
309 {
310 }
311
312 StartDtdEvent::StartDtdEvent(const StringC &name,
313                              const ConstPtr<Entity> &entity,
314                              Boolean hasInternalSubset,
315                              const Location &loc,
316                              Markup *markup)
317 : StartSubsetEvent(startDtd, name, entity, hasInternalSubset, loc, markup)
318 {
319 }
320
321 StartLpdEvent::StartLpdEvent(Boolean active,
322                              const StringC &name,
323                              const ConstPtr<Entity> &entity,
324                              Boolean hasInternalSubset,
325                              const Location &loc,
326                              Markup *markup)
327 : StartSubsetEvent(startLpd, name, entity, hasInternalSubset, loc, markup),
328   active_(active)
329 {
330 }
331
332 EndDtdEvent::EndDtdEvent(const ConstPtr<Dtd> &dtd,
333                          const Location &loc,
334                          Markup *markup)
335 :  MarkupEvent(endDtd, loc, markup), dtd_(dtd)
336 {
337 }
338
339 EndLpdEvent::EndLpdEvent(const ConstPtr<Lpd> &lpd,
340                          const Location &loc,
341                          Markup *markup)
342 :  MarkupEvent(endLpd, loc, markup), lpd_(lpd)
343 {
344 }
345
346 EndPrologEvent::EndPrologEvent(const ConstPtr<Dtd> &dtd,
347                                const ConstPtr<ComplexLpd> &lpd,
348                                Vector<StringC> &simpleLinkNames,
349                                Vector<AttributeList> &simpleLinkAttributes,
350                                const Location &location)
351 : LocatedEvent(endProlog, location), dtd_(dtd), lpd_(lpd)
352 {
353   simpleLinkAttributes.swap(simpleLinkAttributes_);
354   simpleLinkNames.swap(simpleLinkNames_);
355 }
356
357 EndPrologEvent::EndPrologEvent(const ConstPtr<Dtd> &dtd,
358                                const Location &location)
359 : LocatedEvent(endProlog, location), dtd_(dtd)
360 {
361 }
362
363 SgmlDeclEvent::SgmlDeclEvent(const ConstPtr<Sd> &sd,
364                              const ConstPtr<Syntax> &syntax)
365
366 : sd_(sd), prologSyntax_(syntax), instanceSyntax_(syntax),
367   nextIndex_(0), MarkupEvent(sgmlDecl)
368 {
369 }
370
371 SgmlDeclEvent::SgmlDeclEvent(const ConstPtr<Sd> &sd,
372                              const ConstPtr<Syntax> &prologSyntax,
373                              const ConstPtr<Syntax> &instanceSyntax,
374                              const ConstPtr<Sd> &refSd,
375                              const ConstPtr<Syntax> &refSyntax,
376                              Index nextIndex,
377                              const StringC &implySystemId,
378                              const Location &loc,
379                              Markup *markup)
380 : sd_(sd), prologSyntax_(prologSyntax), instanceSyntax_(instanceSyntax),
381   refSd_(refSd), refSyntax_(refSyntax),
382   nextIndex_(nextIndex), implySystemId_(implySystemId),
383   MarkupEvent(sgmlDecl, loc, markup)
384 {
385 }
386
387 CommentDeclEvent::CommentDeclEvent(const Location &loc,
388                                    Markup *markup)
389 : MarkupEvent(commentDecl, loc, markup)
390 {
391 }
392
393 SSepEvent::SSepEvent(const Char *p, size_t length,
394                      const Location &location, Boolean copy)
395 : ImmediateDataEvent(sSep, p, length, location, copy)
396 {
397 }
398
399 IgnoredRsEvent::IgnoredRsEvent(Char c, const Location &location)
400 : LocatedEvent(ignoredRs, location), c_(c)
401 {
402 }
403
404 IgnoredReEvent::IgnoredReEvent(Char c, const Location &location,
405                                unsigned long serial)
406 : LocatedEvent(ignoredRe, location),
407   c_(c),
408   serial_(serial)
409 {
410 }
411
412 ReOriginEvent::ReOriginEvent(Char c, const Location &location,
413                              unsigned long serial)
414 : LocatedEvent(reOrigin, location), c_(c), serial_(serial)
415 {
416 }
417
418
419 IgnoredCharsEvent::IgnoredCharsEvent(const Char *p, size_t length,
420                                      const Location &location, Boolean copy)
421 : ImmediateDataEvent(ignoredChars, p, length, location, copy)
422 {
423 }
424
425 MarkedSectionEvent::MarkedSectionEvent(Type type, Status status,
426                                        const Location &loc,
427                                        Markup *markup)
428 : MarkupEvent(type, loc, markup),
429   status_(status)
430 {
431 }
432
433 MarkedSectionStartEvent::MarkedSectionStartEvent(Status status,
434                                                  const Location &loc,
435                                                  Markup *markup)
436 : MarkedSectionEvent(markedSectionStart, status, loc, markup)
437 {
438 }
439
440 MarkedSectionEndEvent::MarkedSectionEndEvent(Status status,
441                                              const Location &loc,
442                                              Markup *markup)
443 : MarkedSectionEvent(markedSectionEnd, status, loc, markup)
444 {
445 }
446
447 EntityStartEvent::EntityStartEvent(const ConstPtr<EntityOrigin> &origin)
448 : Event(entityStart), origin_(origin)
449 {
450 }
451
452 EntityEndEvent::EntityEndEvent(const Location &location)
453 : LocatedEvent(entityEnd, location)
454 {
455 }
456
457 EntityDeclEvent:: EntityDeclEvent(const ConstPtr<Entity> &entity,
458                                   Boolean ignored, const Location &loc,
459                                   Markup *markup)
460 : MarkupEvent(entityDecl, loc, markup),
461   entity_(entity),
462   ignored_(ignored)
463 {
464 }
465
466 NotationDeclEvent:: NotationDeclEvent(const ConstPtr<Notation> &notation,
467                                       const Location &loc,
468                                       Markup *markup)
469 : MarkupEvent(notationDecl, loc, markup), notation_(notation)
470 {
471 }
472
473 ElementDeclEvent::ElementDeclEvent(Vector<const ElementType *> &elements,
474                                    const ConstPtr<Dtd> &dtd,
475                                    const Location &loc,
476                                    Markup *markup)
477 : MarkupEvent(elementDecl, loc, markup), dtd_(dtd)
478 {
479   elements.swap(elements_);
480 }
481
482 AttlistDeclEvent::AttlistDeclEvent(Vector<const ElementType *> &elements,
483                                    const ConstPtr<Dtd> &dtd,
484                                    const Location &loc,
485                                    Markup *markup)
486 : MarkupEvent(attlistDecl, loc, markup), dtd_(dtd)
487 {
488   elements.swap(elements_);
489 }
490
491 AttlistNotationDeclEvent::AttlistNotationDeclEvent(
492   Vector<ConstPtr<Notation> > &notations, const Location &loc,
493                                                    Markup *markup)
494 : MarkupEvent(attlistNotationDecl, loc, markup)
495 {
496   notations.swap(notations_);
497 }
498
499 LinkAttlistDeclEvent
500 ::LinkAttlistDeclEvent(Vector<const ElementType *> &elements,
501                        const ConstPtr<Lpd> &lpd,
502                        const Location &loc,
503                        Markup *markup)
504 : MarkupEvent(linkAttlistDecl, loc, markup), lpd_(lpd)
505 {
506   elements.swap(elements_);
507 }
508
509 LinkDeclEvent::LinkDeclEvent(const LinkSet *linkSet,
510                              const ConstPtr<ComplexLpd> &lpd,
511                              const Location &loc,
512                              Markup *markup)
513 : MarkupEvent(linkDecl, loc, markup), lpd_(lpd), linkSet_(linkSet)
514 {
515 }
516
517 IdLinkDeclEvent::IdLinkDeclEvent(const ConstPtr<ComplexLpd> &lpd,
518                                  const Location &loc,
519                                  Markup *markup)
520 : MarkupEvent(linkDecl, loc, markup), lpd_(lpd)
521 {
522 }
523
524 ShortrefDeclEvent::ShortrefDeclEvent(const ShortReferenceMap *map,
525                                      const ConstPtr<Dtd> &dtd,
526                                      const Location &loc,
527                                      Markup *markup)
528 : MarkupEvent(shortrefDecl, loc, markup), map_(map), dtd_(dtd)
529 {
530 }
531
532 IgnoredMarkupEvent::IgnoredMarkupEvent(const Location &loc,
533                                        Markup *markup)
534 : MarkupEvent(ignoredMarkup, loc, markup)
535 {
536 }
537
538 EntityDefaultedEvent::EntityDefaultedEvent(const ConstPtr<Entity> &entity,
539                                            const Location &loc)
540 : LocatedEvent(entityDefaulted, loc), entity_(entity)
541 {
542 }
543
544 SgmlDeclEntityEvent::  SgmlDeclEntityEvent(const PublicId &publicId,
545                                            PublicId::TextClass entityType,
546                                            const StringC &effectiveSystemId,
547                                            const Location &loc)
548 : LocatedEvent(sgmlDeclEntity, loc), publicId_(publicId),
549   entityType_(entityType), effectiveSystemId_(effectiveSystemId)
550 {
551 }
552
553 EventHandler::~EventHandler()
554 {
555 }
556
557 EventQueue::EventQueue()
558 {
559 }
560
561 #define EVENT(c, f) \
562   void EventHandler::f(c *event) { delete event; } \
563   void EventQueue::f(c *event) { append(event); } \
564   void c::handle(EventHandler &handler) { handler.f(this); }
565 #include "events.h"
566 #undef EVENT
567
568 Pass1EventHandler::Pass1EventHandler()
569 : hadError_(0), origHandler_(0)
570 {
571 }
572
573 void Pass1EventHandler::init(EventHandler *origHandler)
574 {
575   hadError_ = 0;
576   origHandler_ = origHandler;
577 }
578
579 void Pass1EventHandler::message(MessageEvent *event)
580 {
581   if (event->message().isError()) {
582     hadError_ = 1;
583     origHandler_->message(event);
584   }
585   else
586     IQueue<Event>::append(event);
587 }
588
589 #ifdef SP_NAMESPACE
590 }
591 #endif