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: ParserApp.C /main/1 1996/07/29 17:00:34 cde-hp $ */
24 // Copyright (c) 1996 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "ParserApp.h"
33 #include "ParserAppMessages.h"
34 #include "MessageArg.h"
38 #include "ArcEngine.h"
44 #ifndef DEFAULT_ERROR_LIMIT
45 #define DEFAULT_ERROR_LIMIT 200
49 namespace SP_NAMESPACE {
52 ParserApp::ParserApp()
53 : errorLimit_(DEFAULT_ERROR_LIMIT)
55 registerOption('a', SP_T("link_type"));
56 registerOption('A', SP_T("arch"));
58 registerOption('E', SP_T("max_errors"));
60 registerOption('i', SP_T("entity"));
61 registerOption('w', SP_T("warning_type"));
64 void ParserApp::initParser(const StringC &sysid)
66 SgmlParser::Params params;
68 params.entityManager = entityManager().pointer();
69 params.initialCharset = &systemCharset_.desc();
70 params.options = &options_;
72 if (arcNames_.size() > 0)
73 parser_.activateLinkType(arcNames_[0]);
74 for (size_t i = 0; i < activeLinkTypes_.size(); i++)
75 parser_.activateLinkType(convertInput(activeLinkTypes_[i]));
76 allLinkTypesActivated();
79 void ParserApp::allLinkTypesActivated()
81 parser_.allLinkTypesActivated();
84 int ParserApp::processSysid(const StringC &sysid)
87 ErrorCountEventHandler *eceh = makeEventHandler();
89 eceh->setErrorLimit(errorLimit_);
90 return generateEvents(eceh);
93 int ParserApp::generateEvents(ErrorCountEventHandler *eceh)
95 Owner<EventHandler> eh(eceh);
96 parseAll(parser_, *eh, (SP_CONST sig_atomic_t*) eceh->cancelPtr());
97 unsigned errorCount = eceh->errorCount();
98 if (errorLimit_ != 0 && errorCount >= errorLimit_)
99 message(ParserAppMessages::errorLimitExceeded,
100 NumberMessageArg(errorLimit_));
101 return errorCount > 0;
104 void ParserApp::parseAll(SgmlParser &parser,
106 SP_CONST SP_VOLATILE sig_atomic_t *cancelPtr)
108 if (arcNames_.size() > 0) {
109 SelectOneArcDirector director(arcNames_, eh);
110 ArcEngine::parseAll(parser, director, director, cancelPtr);
113 parser.parseAll(eh, cancelPtr);
116 void ParserApp::processOption(AppChar opt, const AppChar *arg)
121 activeLinkTypes_.push_back(arg);
124 arcNames_.push_back(convertInput(arg));
129 unsigned long n = tcstoul((AppChar *)arg, &end, 10);
130 if ((n == 0 && end == arg)
131 || *end != SP_T('\0')
132 || (n == ULONG_MAX && errno == ERANGE)
134 message(ParserAppMessages::badErrorLimit);
136 errorLimit_ = unsigned(n);
140 // describe open entities in error messages
141 addOption(MessageReporter::openEntities);
144 // show gis of open elements in error messages
145 addOption(MessageReporter::openElements);
148 // pretend that arg is defined as INCLUDE
149 options_.includes.push_back(convertInput(arg));
152 if (!enableWarning(arg))
153 message(ParserAppMessages::unknownWarning,
154 StringMessageArg(convertInput(arg)));
157 EntityApp::processOption(opt, arg);
162 Boolean ParserApp::enableWarning(const AppChar *s)
166 PackedBoolean ParserOptions::*ptr;
167 PackedBoolean partOfAll;
169 { SP_T("mixed"), &ParserOptions::warnMixedContent, 1 },
170 { SP_T("should"), &ParserOptions::warnShould, 1 },
171 { SP_T("duplicate"), &ParserOptions::warnDuplicateEntity, 0 },
172 { SP_T("default"), &ParserOptions::warnDefaultEntityReference, 1 },
173 { SP_T("undefined"), &ParserOptions::warnUndefinedElement, 1 },
174 { SP_T("sgmldecl"), &ParserOptions::warnSgmlDecl, 1 },
175 { SP_T("unclosed"), &ParserOptions::warnUnclosedTag, 1 },
176 { SP_T("empty"), &ParserOptions::warnEmptyTag, 1 },
177 { SP_T("net"), &ParserOptions::warnNet, 0 },
178 { SP_T("unused-map"), &ParserOptions::warnUnusedMap, 1 },
179 { SP_T("unused-param"), &ParserOptions::warnUnusedParam, 1 },
180 { SP_T("notation-sysid"), &ParserOptions::warnNotationSystemId, 0 },
181 { SP_T("idref"), &ParserOptions::errorIdref, 0 },
182 { SP_T("significant"), &ParserOptions::errorSignificant, 0 },
183 { SP_T("afdr"), &ParserOptions::errorAfdr, 0 },
184 { SP_T("lpd-notation"), &ParserOptions::errorLpdNotation, 0 },
186 PackedBoolean val = 1;
187 if (tcsncmp(s, SP_T("no-"), 3) == 0) {
191 if (tcscmp(s, SP_T("all")) == 0) {
192 for (size_t i = 0; i < SIZEOF(table); i++)
193 if (table[i].partOfAll) {
194 // Use parentheses to work around Watcom 10.0a bug.
195 (options_.*(table[i].ptr)) = val;
199 for (size_t i = 0; i < SIZEOF(table); i++)
200 if (tcscmp(s, table[i].name) == 0) {
201 // Use parentheses to work around Watcom 10.0a bug.
202 (options_.*(table[i].ptr)) = val;
205 if (tcscmp(s, SP_T("min-tag")) == 0) {
206 options_.warnUnclosedTag = val;
207 options_.warnEmptyTag = val;
208 options_.warnNet = val;