1 // Copyright (c) 1995 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
11 #include "ParserApp.h"
13 #include "SGMLApplication.h"
14 #include "ParserEventGeneratorKit.h"
15 #include "GenericEventHandler.h"
17 class ParserEventGeneratorKitImpl
: public SP_NAMESPACE_SCOPE ParserApp
{
19 SP_NAMESPACE_SCOPE ParserOptions
&options() { return options_
; }
23 SP_NAMESPACE_SCOPE ErrorCountEventHandler
*makeEventHandler() { return 0; }
27 namespace SP_NAMESPACE
{
30 class ParserEventGenerator
: public EventGenerator
{
32 ParserEventGenerator(SgmlParser
&,
34 ParserEventGeneratorKitImpl
*kit_
);
35 ParserEventGenerator(const SgmlParser
&,
36 const SGMLApplication::Char
*,
39 bool messagesInhibited
,
40 ParserEventGeneratorKitImpl
*kit_
);
41 ~ParserEventGenerator();
42 unsigned run(SGMLApplication
&);
43 void inhibitMessages(bool);
46 makeSubdocEventGenerator(const SGMLApplication::Char
*systemId
,
47 size_t systemIdLength
);
50 bool generalEntities_
;
51 bool messagesInhibited_
;
53 ParserEventGeneratorKitImpl
*kit_
;
60 ParserEventGeneratorKit::ParserEventGeneratorKit()
62 impl_
= new ParserEventGeneratorKitImpl
;
64 impl_
->generalEntities
= 0;
67 ParserEventGeneratorKit::~ParserEventGeneratorKit()
70 if (impl_
->refCount
== 0)
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
,
86 void ParserEventGeneratorKit::setProgramName(const SP_NAMESPACE_SCOPE
ParserApp::AppChar
*prog
)
89 impl_
->setProgramName(impl_
->convertInput(prog
));
92 void ParserEventGeneratorKit::setOption(Option opt
)
95 case showOpenEntities
:
96 impl_
->processOption('e', 0);
98 case showOpenElements
:
99 impl_
->processOption('g', 0);
101 case outputCommentDecls
:
102 impl_
->options().eventsWanted
.addCommentDecls();
104 case outputMarkedSections
:
105 impl_
->options().eventsWanted
.addMarkedSections();
107 case outputGeneralEntities
:
108 impl_
->generalEntities
= 1;
110 case mapCatalogDocument
:
111 impl_
->processOption('C', 0);
116 void ParserEventGeneratorKit::setOption(OptionWithArg opt
,
117 const SP_NAMESPACE_SCOPE
ParserApp::AppChar
*arg
)
121 impl_
->processOption('c', arg
);
124 impl_
->processOption('i', arg
);
127 impl_
->processOption('w', arg
);
130 impl_
->processOption('D', arg
);
133 impl_
->processOption('a', arg
);
136 impl_
->processOption('A', arg
);
142 namespace SP_NAMESPACE
{
145 ParserEventGenerator::ParserEventGenerator(SgmlParser
&parser
,
146 bool generalEntities
,
147 ParserEventGeneratorKitImpl
*kit
)
148 : generalEntities_(generalEntities
),
149 messagesInhibited_(0),
153 parser_
.swap(parser
);
157 ParserEventGenerator::ParserEventGenerator(const SgmlParser
&parser
,
158 const SGMLApplication::Char
*s
,
160 bool generalEntities
,
161 bool messagesInhibited
,
162 ParserEventGeneratorKitImpl
*kit
)
163 : generalEntities_(generalEntities
),
164 messagesInhibited_(messagesInhibited
),
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()
181 ParserEventGenerator::~ParserEventGenerator()
184 if (kit_
->refCount
== 0)
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
;
202 ParserEventGenerator::makeSubdocEventGenerator(const SGMLApplication::Char
*s
,
205 return new ParserEventGenerator(parser_
, s
, n
, generalEntities_
,
206 messagesInhibited_
, kit_
);