3065 some functions in the tcp module can be static
[unleashed.git] / usr / src / cmd / man / src / util / nsgmls.src / lib / ParserEventGeneratorKit.cxx
blobb9cf1805483da5a849d2ff95e145624ccf53155e
1 // Copyright (c) 1995 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
9 #include "splib.h"
10 #include "Boolean.h"
11 #include "ParserApp.h"
12 #include "macros.h"
13 #include "SGMLApplication.h"
14 #include "ParserEventGeneratorKit.h"
15 #include "GenericEventHandler.h"
17 class ParserEventGeneratorKitImpl : public SP_NAMESPACE_SCOPE ParserApp {
18 public:
19 SP_NAMESPACE_SCOPE ParserOptions &options() { return options_; }
20 bool generalEntities;
21 unsigned refCount;
22 private:
23 SP_NAMESPACE_SCOPE ErrorCountEventHandler *makeEventHandler() { return 0; }
26 #ifdef SP_NAMESPACE
27 namespace SP_NAMESPACE {
28 #endif
30 class ParserEventGenerator : public EventGenerator {
31 public:
32 ParserEventGenerator(SgmlParser &,
33 bool generalEntities,
34 ParserEventGeneratorKitImpl *kit_);
35 ParserEventGenerator(const SgmlParser &,
36 const SGMLApplication::Char *,
37 size_t n,
38 bool generalEntities,
39 bool messagesInhibited,
40 ParserEventGeneratorKitImpl *kit_);
41 ~ParserEventGenerator();
42 unsigned run(SGMLApplication &);
43 void inhibitMessages(bool);
44 void halt();
45 EventGenerator *
46 makeSubdocEventGenerator(const SGMLApplication::Char *systemId,
47 size_t systemIdLength);
48 private:
49 SgmlParser parser_;
50 bool generalEntities_;
51 bool messagesInhibited_;
52 sig_atomic_t cancel_;
53 ParserEventGeneratorKitImpl *kit_;
56 #ifdef SP_NAMESPACE
58 #endif
60 ParserEventGeneratorKit::ParserEventGeneratorKit()
62 impl_ = new ParserEventGeneratorKitImpl;
63 impl_->refCount = 1;
64 impl_->generalEntities = 0;
67 ParserEventGeneratorKit::~ParserEventGeneratorKit()
69 impl_->refCount -= 1;
70 if (impl_->refCount == 0)
71 delete impl_;
74 EventGenerator *
75 ParserEventGeneratorKit::makeEventGenerator(int nFiles,
76 SP_NAMESPACE_SCOPE ParserApp::AppChar *const *files)
78 SP_NAMESPACE_SCOPE StringC sysid;
79 if (impl_->makeSystemId(nFiles, files, sysid))
80 impl_->initParser(sysid);
81 return new SP_NAMESPACE_SCOPE ParserEventGenerator(impl_->parser(),
82 impl_->generalEntities,
83 impl_);
86 void ParserEventGeneratorKit::setProgramName(const SP_NAMESPACE_SCOPE ParserApp::AppChar *prog)
88 if (prog)
89 impl_->setProgramName(impl_->convertInput(prog));
92 void ParserEventGeneratorKit::setOption(Option opt)
94 switch (opt) {
95 case showOpenEntities:
96 impl_->processOption('e', 0);
97 break;
98 case showOpenElements:
99 impl_->processOption('g', 0);
100 break;
101 case outputCommentDecls:
102 impl_->options().eventsWanted.addCommentDecls();
103 break;
104 case outputMarkedSections:
105 impl_->options().eventsWanted.addMarkedSections();
106 break;
107 case outputGeneralEntities:
108 impl_->generalEntities = 1;
109 break;
110 case mapCatalogDocument:
111 impl_->processOption('C', 0);
112 break;
116 void ParserEventGeneratorKit::setOption(OptionWithArg opt,
117 const SP_NAMESPACE_SCOPE ParserApp::AppChar *arg)
119 switch (opt) {
120 case addCatalog:
121 impl_->processOption('c', arg);
122 break;
123 case includeParam:
124 impl_->processOption('i', arg);
125 break;
126 case enableWarning:
127 impl_->processOption('w', arg);
128 break;
129 case addSearchDir:
130 impl_->processOption('D', arg);
131 break;
132 case activateLink:
133 impl_->processOption('a', arg);
134 break;
135 case architecture:
136 impl_->processOption('A', arg);
137 break;
141 #ifdef SP_NAMESPACE
142 namespace SP_NAMESPACE {
143 #endif
145 ParserEventGenerator::ParserEventGenerator(SgmlParser &parser,
146 bool generalEntities,
147 ParserEventGeneratorKitImpl *kit)
148 : generalEntities_(generalEntities),
149 messagesInhibited_(0),
150 cancel_(0),
151 kit_(kit)
153 parser_.swap(parser);
154 kit_->refCount += 1;
157 ParserEventGenerator::ParserEventGenerator(const SgmlParser &parser,
158 const SGMLApplication::Char *s,
159 size_t n,
160 bool generalEntities,
161 bool messagesInhibited,
162 ParserEventGeneratorKitImpl *kit)
163 : generalEntities_(generalEntities),
164 messagesInhibited_(messagesInhibited),
165 cancel_(0),
166 kit_(kit)
168 kit_->refCount += 1;
169 SgmlParser::Params params;
170 params.parent = &parser;
171 params.sysid.assign(s, n);
172 params.entityType = SgmlParser::Params::subdoc;
173 parser_.init(params);
176 void ParserEventGenerator::halt()
178 cancel_ = 1;
181 ParserEventGenerator::~ParserEventGenerator()
183 kit_->refCount -= 1;
184 if (kit_->refCount == 0)
185 delete kit_;
188 unsigned ParserEventGenerator::run(SGMLApplication &app)
190 MsgGenericEventHandler handler(app, generalEntities_,
191 *kit_, &messagesInhibited_);
192 kit_->parseAll(parser_, handler, &cancel_);
193 return handler.errorCount();
196 void ParserEventGenerator::inhibitMessages(bool b)
198 messagesInhibited_ = b;
201 EventGenerator *
202 ParserEventGenerator::makeSubdocEventGenerator(const SGMLApplication::Char *s,
203 size_t n)
205 return new ParserEventGenerator(parser_, s, n, generalEntities_,
206 messagesInhibited_, kit_);
209 #ifdef SP_NAMESPACE
211 #endif