2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: ParserEventGeneratorKit.C /main/1 1996/07/29 17:00:49 cde-hp $ */
24 // Copyright (c) 1995 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
33 #include "ParserApp.h"
35 #include "SGMLApplication.h"
36 #include "ParserEventGeneratorKit.h"
37 #include "GenericEventHandler.h"
40 using namespace SP_NAMESPACE;
43 class ParserEventGeneratorKitImpl : public ParserApp {
45 ParserOptions &options() { return options_; }
49 ErrorCountEventHandler *makeEventHandler() { return 0; }
52 class ParserEventGenerator : public EventGenerator {
54 ParserEventGenerator(SgmlParser &,
56 ParserEventGeneratorKitImpl *kit_);
57 ParserEventGenerator(const SgmlParser &,
58 const SGMLApplication::Char *,
61 bool messagesInhibited,
62 ParserEventGeneratorKitImpl *kit_);
63 ~ParserEventGenerator();
64 unsigned run(SGMLApplication &);
65 void inhibitMessages(bool);
68 makeSubdocEventGenerator(const SGMLApplication::Char *systemId,
69 size_t systemIdLength);
72 bool generalEntities_;
73 bool messagesInhibited_;
75 ParserEventGeneratorKitImpl *kit_;
78 ParserEventGeneratorKit::ParserEventGeneratorKit()
80 impl_ = new ParserEventGeneratorKitImpl;
82 impl_->generalEntities = 0;
85 ParserEventGeneratorKit::~ParserEventGeneratorKit()
88 if (impl_->refCount == 0)
93 ParserEventGeneratorKit::makeEventGenerator(int nFiles,
94 AppChar *const *files)
97 if (impl_->makeSystemId(nFiles, files, sysid))
98 impl_->initParser(sysid);
99 return new ParserEventGenerator(impl_->parser(),
100 impl_->generalEntities,
104 void ParserEventGeneratorKit::setProgramName(const AppChar *prog)
107 impl_->setProgramName(impl_->convertInput(prog));
110 void ParserEventGeneratorKit::setOption(Option opt)
113 case showOpenEntities:
114 impl_->processOption('e', 0);
116 case showOpenElements:
117 impl_->processOption('g', 0);
119 case outputCommentDecls:
120 impl_->options().eventsWanted.addCommentDecls();
122 case outputMarkedSections:
123 impl_->options().eventsWanted.addMarkedSections();
125 case outputGeneralEntities:
126 impl_->generalEntities = 1;
128 case mapCatalogDocument:
129 impl_->processOption('C', 0);
134 void ParserEventGeneratorKit::setOption(OptionWithArg opt,
139 impl_->processOption('c', arg);
142 impl_->processOption('i', arg);
145 impl_->processOption('w', arg);
148 impl_->processOption('D', arg);
151 impl_->processOption('a', arg);
154 impl_->processOption('A', arg);
159 ParserEventGenerator::ParserEventGenerator(SgmlParser &parser,
160 bool generalEntities,
161 ParserEventGeneratorKitImpl *kit)
162 : generalEntities_(generalEntities),
163 messagesInhibited_(0),
167 parser_.swap(parser);
171 ParserEventGenerator::ParserEventGenerator(const SgmlParser &parser,
172 const SGMLApplication::Char *s,
174 bool generalEntities,
175 bool messagesInhibited,
176 ParserEventGeneratorKitImpl *kit)
177 : generalEntities_(generalEntities),
178 messagesInhibited_(messagesInhibited),
183 SgmlParser::Params params;
184 params.parent = &parser;
185 params.sysid.assign(s, n);
186 params.entityType = SgmlParser::Params::subdoc;
187 parser_.init(params);
190 void ParserEventGenerator::halt()
195 ParserEventGenerator::~ParserEventGenerator()
198 if (kit_->refCount == 0)
202 unsigned ParserEventGenerator::run(SGMLApplication &app)
204 MsgGenericEventHandler handler(app, generalEntities_,
205 *kit_, &messagesInhibited_);
206 kit_->parseAll(parser_, handler, &cancel_);
207 return handler.errorCount();
210 void ParserEventGenerator::inhibitMessages(bool b)
212 messagesInhibited_ = b;
216 ParserEventGenerator::makeSubdocEventGenerator(const SGMLApplication::Char *s,
219 return new ParserEventGenerator(parser_, s, n, generalEntities_,
220 messagesInhibited_, kit_);