1*0Sstevel@tonic-gate // Copyright (c) 1994 James Clark
2*0Sstevel@tonic-gate // See the file COPYING for copying permission.
3*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gate #ifdef __GNUG__
6*0Sstevel@tonic-gate #pragma implementation
7*0Sstevel@tonic-gate #endif
8*0Sstevel@tonic-gate #include "splib.h"
9*0Sstevel@tonic-gate #include "Param.h"
10*0Sstevel@tonic-gate #include "MessageBuilder.h"
11*0Sstevel@tonic-gate #include "macros.h"
12*0Sstevel@tonic-gate #include "ParserMessages.h"
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate #ifdef SP_NAMESPACE
15*0Sstevel@tonic-gate namespace SP_NAMESPACE {
16*0Sstevel@tonic-gate #endif
17*0Sstevel@tonic-gate
AllowedParams(Param::Type p1,Param::Type p2,Param::Type p3,Param::Type p4,Param::Type p5,Param::Type p6,Param::Type p7,Param::Type p8,Param::Type p9,Param::Type p10)18*0Sstevel@tonic-gate AllowedParams::AllowedParams(Param::Type p1,
19*0Sstevel@tonic-gate Param::Type p2,
20*0Sstevel@tonic-gate Param::Type p3,
21*0Sstevel@tonic-gate Param::Type p4,
22*0Sstevel@tonic-gate Param::Type p5,
23*0Sstevel@tonic-gate Param::Type p6,
24*0Sstevel@tonic-gate Param::Type p7,
25*0Sstevel@tonic-gate Param::Type p8,
26*0Sstevel@tonic-gate Param::Type p9,
27*0Sstevel@tonic-gate Param::Type p10)
28*0Sstevel@tonic-gate {
29*0Sstevel@tonic-gate init();
30*0Sstevel@tonic-gate allow(p1);
31*0Sstevel@tonic-gate allow(p2);
32*0Sstevel@tonic-gate allow(p3);
33*0Sstevel@tonic-gate allow(p4);
34*0Sstevel@tonic-gate allow(p5);
35*0Sstevel@tonic-gate allow(p6);
36*0Sstevel@tonic-gate allow(p7);
37*0Sstevel@tonic-gate allow(p8);
38*0Sstevel@tonic-gate allow(p9);
39*0Sstevel@tonic-gate allow(p10);
40*0Sstevel@tonic-gate }
41*0Sstevel@tonic-gate
AllowedParams(const Param::Type * v,int n)42*0Sstevel@tonic-gate AllowedParams::AllowedParams(const Param::Type *v, int n)
43*0Sstevel@tonic-gate {
44*0Sstevel@tonic-gate init();
45*0Sstevel@tonic-gate for (int i = 0; i < n; i++)
46*0Sstevel@tonic-gate allow(v[i]);
47*0Sstevel@tonic-gate }
48*0Sstevel@tonic-gate
init()49*0Sstevel@tonic-gate void AllowedParams::init()
50*0Sstevel@tonic-gate {
51*0Sstevel@tonic-gate for (int i = 0; i < Syntax::nNames; i++)
52*0Sstevel@tonic-gate reservedNames_[i] = 0;
53*0Sstevel@tonic-gate mainMode_ = mdMode;
54*0Sstevel@tonic-gate mdc_ = 0;
55*0Sstevel@tonic-gate rni_ = 0;
56*0Sstevel@tonic-gate dso_ = 0;
57*0Sstevel@tonic-gate inclusions_ = 0;
58*0Sstevel@tonic-gate exclusions_ = 0;
59*0Sstevel@tonic-gate extraDelimiter_ = Param::invalid;
60*0Sstevel@tonic-gate group_ = Param::invalid;
61*0Sstevel@tonic-gate nameStart_ = Param::invalid;
62*0Sstevel@tonic-gate digit_ = Param::invalid;
63*0Sstevel@tonic-gate nmchar_ = Param::invalid;
64*0Sstevel@tonic-gate literal_ = Param::invalid;
65*0Sstevel@tonic-gate }
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate
allow(Param::Type p)68*0Sstevel@tonic-gate void AllowedParams::allow(Param::Type p)
69*0Sstevel@tonic-gate {
70*0Sstevel@tonic-gate switch (p) {
71*0Sstevel@tonic-gate case Param::invalid:
72*0Sstevel@tonic-gate break;
73*0Sstevel@tonic-gate case Param::dso:
74*0Sstevel@tonic-gate dso_ = 1;
75*0Sstevel@tonic-gate break;
76*0Sstevel@tonic-gate case Param::mdc:
77*0Sstevel@tonic-gate mdc_ = 1;
78*0Sstevel@tonic-gate break;
79*0Sstevel@tonic-gate case Param::minus:
80*0Sstevel@tonic-gate ASSERT(mainMode_ == mdMode);
81*0Sstevel@tonic-gate mainMode_ = mdMinusMode;
82*0Sstevel@tonic-gate extraDelimiter_ = p;
83*0Sstevel@tonic-gate break;
84*0Sstevel@tonic-gate case Param::pero:
85*0Sstevel@tonic-gate ASSERT(mainMode_ == mdMode);
86*0Sstevel@tonic-gate mainMode_ = mdPeroMode;
87*0Sstevel@tonic-gate extraDelimiter_ = p;
88*0Sstevel@tonic-gate break;
89*0Sstevel@tonic-gate case Param::inclusions:
90*0Sstevel@tonic-gate inclusions_ = 1;
91*0Sstevel@tonic-gate break;
92*0Sstevel@tonic-gate case Param::exclusions:
93*0Sstevel@tonic-gate exclusions_ = 1;
94*0Sstevel@tonic-gate break;
95*0Sstevel@tonic-gate case Param::nameGroup:
96*0Sstevel@tonic-gate case Param::nameTokenGroup:
97*0Sstevel@tonic-gate case Param::modelGroup:
98*0Sstevel@tonic-gate ASSERT(group_ == Param::invalid);
99*0Sstevel@tonic-gate group_ = p;
100*0Sstevel@tonic-gate break;
101*0Sstevel@tonic-gate case Param::number:
102*0Sstevel@tonic-gate ASSERT(digit_ == Param::invalid);
103*0Sstevel@tonic-gate digit_ = p;
104*0Sstevel@tonic-gate break;
105*0Sstevel@tonic-gate case Param::minimumLiteral:
106*0Sstevel@tonic-gate case Param::tokenizedAttributeValueLiteral:
107*0Sstevel@tonic-gate case Param::attributeValueLiteral:
108*0Sstevel@tonic-gate case Param::systemIdentifier:
109*0Sstevel@tonic-gate case Param::paramLiteral:
110*0Sstevel@tonic-gate ASSERT(literal_ == Param::invalid);
111*0Sstevel@tonic-gate literal_ = p;
112*0Sstevel@tonic-gate break;
113*0Sstevel@tonic-gate case Param::name:
114*0Sstevel@tonic-gate case Param::entityName:
115*0Sstevel@tonic-gate case Param::paramEntityName:
116*0Sstevel@tonic-gate ASSERT(nameStart_ == Param::invalid);
117*0Sstevel@tonic-gate nameStart_ = p;
118*0Sstevel@tonic-gate break;
119*0Sstevel@tonic-gate case Param::attributeValue:
120*0Sstevel@tonic-gate ASSERT(nameStart_ == Param::invalid);
121*0Sstevel@tonic-gate nameStart_ = p;
122*0Sstevel@tonic-gate ASSERT(digit_ == Param::invalid);
123*0Sstevel@tonic-gate digit_ = p;
124*0Sstevel@tonic-gate ASSERT(nmchar_ == Param::invalid);
125*0Sstevel@tonic-gate nmchar_ = p;
126*0Sstevel@tonic-gate break;
127*0Sstevel@tonic-gate default:
128*0Sstevel@tonic-gate if (p < Param::indicatedReservedName) {
129*0Sstevel@tonic-gate ASSERT(nameStart_ == Param::invalid
130*0Sstevel@tonic-gate || nameStart_ == Param::reservedName);
131*0Sstevel@tonic-gate ASSERT(rni_ == 0);
132*0Sstevel@tonic-gate nameStart_ = Param::reservedName;
133*0Sstevel@tonic-gate reservedNames_[p - Param::reservedName] = 1;
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate else {
136*0Sstevel@tonic-gate ASSERT(nameStart_ != Param::reservedName);
137*0Sstevel@tonic-gate rni_ = 1;
138*0Sstevel@tonic-gate reservedNames_[p - Param::indicatedReservedName] = 1;
139*0Sstevel@tonic-gate }
140*0Sstevel@tonic-gate break;
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate
AllowedParamsMessageArg(const AllowedParams & allow,const ConstPtr<Syntax> & syntax)144*0Sstevel@tonic-gate AllowedParamsMessageArg::AllowedParamsMessageArg(
145*0Sstevel@tonic-gate const AllowedParams &allow,
146*0Sstevel@tonic-gate const ConstPtr<Syntax> &syntax)
147*0Sstevel@tonic-gate : allow_(allow),
148*0Sstevel@tonic-gate syntax_(syntax)
149*0Sstevel@tonic-gate {
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate
copy() const152*0Sstevel@tonic-gate MessageArg *AllowedParamsMessageArg::copy() const
153*0Sstevel@tonic-gate {
154*0Sstevel@tonic-gate return new AllowedParamsMessageArg(*this);
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate
append(MessageBuilder & builder) const157*0Sstevel@tonic-gate void AllowedParamsMessageArg::append(MessageBuilder &builder) const
158*0Sstevel@tonic-gate {
159*0Sstevel@tonic-gate Syntax::DelimGeneral delims[3];
160*0Sstevel@tonic-gate int nDelims = 0;
161*0Sstevel@tonic-gate if (allow_.mdc())
162*0Sstevel@tonic-gate delims[nDelims++] = Syntax::dMDC;
163*0Sstevel@tonic-gate if (allow_.dso())
164*0Sstevel@tonic-gate delims[nDelims++] = Syntax::dDSO;
165*0Sstevel@tonic-gate switch (allow_.mainMode()) {
166*0Sstevel@tonic-gate case mdMinusMode:
167*0Sstevel@tonic-gate delims[nDelims++] = Syntax::dMINUS;
168*0Sstevel@tonic-gate break;
169*0Sstevel@tonic-gate case mdPeroMode:
170*0Sstevel@tonic-gate delims[nDelims++] = Syntax::dPERO;
171*0Sstevel@tonic-gate break;
172*0Sstevel@tonic-gate default:
173*0Sstevel@tonic-gate break;
174*0Sstevel@tonic-gate }
175*0Sstevel@tonic-gate Boolean first = 1;
176*0Sstevel@tonic-gate int i;
177*0Sstevel@tonic-gate for (i = 0; i < nDelims; i++) {
178*0Sstevel@tonic-gate if (!first)
179*0Sstevel@tonic-gate builder.appendFragment(ParserMessages::listSep);
180*0Sstevel@tonic-gate else
181*0Sstevel@tonic-gate first = 0;
182*0Sstevel@tonic-gate const StringC &delim = syntax_->delimGeneral(delims[i]);
183*0Sstevel@tonic-gate builder.appendFragment(ParserMessages::delimStart);
184*0Sstevel@tonic-gate builder.appendChars(delim.data(), delim.size());
185*0Sstevel@tonic-gate builder.appendFragment(ParserMessages::delimEnd);
186*0Sstevel@tonic-gate }
187*0Sstevel@tonic-gate const MessageFragment *fragment[5];
188*0Sstevel@tonic-gate int nFragments = 0;
189*0Sstevel@tonic-gate if (allow_.inclusions())
190*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::inclusions;
191*0Sstevel@tonic-gate if (allow_.exclusions())
192*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::exclusions;
193*0Sstevel@tonic-gate switch (allow_.literal()) {
194*0Sstevel@tonic-gate case Param::minimumLiteral:
195*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::minimumLiteral;
196*0Sstevel@tonic-gate break;
197*0Sstevel@tonic-gate case Param::attributeValueLiteral:
198*0Sstevel@tonic-gate case Param::tokenizedAttributeValueLiteral:
199*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::attributeValueLiteral;
200*0Sstevel@tonic-gate break;
201*0Sstevel@tonic-gate case Param::systemIdentifier:
202*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::systemIdentifier;
203*0Sstevel@tonic-gate break;
204*0Sstevel@tonic-gate case Param::paramLiteral:
205*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::parameterLiteral;
206*0Sstevel@tonic-gate break;
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate switch (allow_.nameStart()) {
209*0Sstevel@tonic-gate case Param::name:
210*0Sstevel@tonic-gate case Param::entityName:
211*0Sstevel@tonic-gate case Param::paramEntityName:
212*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::name;
213*0Sstevel@tonic-gate break;
214*0Sstevel@tonic-gate case Param::attributeValue:
215*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::attributeValue;
216*0Sstevel@tonic-gate break;
217*0Sstevel@tonic-gate }
218*0Sstevel@tonic-gate if (allow_.digit() == Param::number)
219*0Sstevel@tonic-gate fragment[nFragments++] = &ParserMessages::number;
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate for (i = 0; i < nFragments; i++) {
222*0Sstevel@tonic-gate if (!first)
223*0Sstevel@tonic-gate builder.appendFragment(ParserMessages::listSep);
224*0Sstevel@tonic-gate else
225*0Sstevel@tonic-gate first = 0;
226*0Sstevel@tonic-gate builder.appendFragment(*fragment[i]);
227*0Sstevel@tonic-gate }
228*0Sstevel@tonic-gate if (allow_.rni() || allow_.nameStart() == Param::reservedName) {
229*0Sstevel@tonic-gate for (int i = 0; i < Syntax::nNames; i++) {
230*0Sstevel@tonic-gate if (allow_.reservedName(Syntax::ReservedName(i))) {
231*0Sstevel@tonic-gate if (!first)
232*0Sstevel@tonic-gate builder.appendFragment(ParserMessages::listSep);
233*0Sstevel@tonic-gate else
234*0Sstevel@tonic-gate first = 0;
235*0Sstevel@tonic-gate StringC str;
236*0Sstevel@tonic-gate if (allow_.rni())
237*0Sstevel@tonic-gate str = syntax_->delimGeneral(Syntax::dRNI);
238*0Sstevel@tonic-gate str += syntax_->reservedName(Syntax::ReservedName(i));
239*0Sstevel@tonic-gate builder.appendChars(str.data(), str.size());
240*0Sstevel@tonic-gate }
241*0Sstevel@tonic-gate }
242*0Sstevel@tonic-gate }
243*0Sstevel@tonic-gate }
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate #ifdef SP_NAMESPACE
246*0Sstevel@tonic-gate }
247*0Sstevel@tonic-gate #endif
248