xref: /onnv-gate/usr/src/cmd/man/src/util/nsgmls.src/lib/Group.cxx (revision 0:68f95e015346)
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 "Group.h"
10*0Sstevel@tonic-gate #include "MessageBuilder.h"
11*0Sstevel@tonic-gate #include "ParserMessages.h"
12*0Sstevel@tonic-gate #include "macros.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 
AllowedGroupTokens(GroupToken::Type t1,GroupToken::Type t2,GroupToken::Type t3,GroupToken::Type t4)18*0Sstevel@tonic-gate AllowedGroupTokens::AllowedGroupTokens(GroupToken::Type t1, GroupToken::Type t2,
19*0Sstevel@tonic-gate 				       GroupToken::Type t3, GroupToken::Type t4)
20*0Sstevel@tonic-gate : flags_(0)
21*0Sstevel@tonic-gate {
22*0Sstevel@tonic-gate   allow(t1);
23*0Sstevel@tonic-gate   allow(t2);
24*0Sstevel@tonic-gate   allow(t3);
25*0Sstevel@tonic-gate   allow(t4);
26*0Sstevel@tonic-gate }
27*0Sstevel@tonic-gate 
AllowedGroupConnectors(GroupConnector::Type c1)28*0Sstevel@tonic-gate AllowedGroupConnectors::AllowedGroupConnectors(GroupConnector::Type c1)
29*0Sstevel@tonic-gate : flags_(0)
30*0Sstevel@tonic-gate {
31*0Sstevel@tonic-gate   allow(c1);
32*0Sstevel@tonic-gate }
33*0Sstevel@tonic-gate 
AllowedGroupConnectors(GroupConnector::Type c1,GroupConnector::Type c2)34*0Sstevel@tonic-gate AllowedGroupConnectors::AllowedGroupConnectors(GroupConnector::Type c1,
35*0Sstevel@tonic-gate 					       GroupConnector::Type c2)
36*0Sstevel@tonic-gate : flags_(0)
37*0Sstevel@tonic-gate {
38*0Sstevel@tonic-gate   allow(c1);
39*0Sstevel@tonic-gate   allow(c2);
40*0Sstevel@tonic-gate }
41*0Sstevel@tonic-gate 
AllowedGroupConnectors(GroupConnector::Type c1,GroupConnector::Type c2,GroupConnector::Type c3)42*0Sstevel@tonic-gate AllowedGroupConnectors::AllowedGroupConnectors(GroupConnector::Type c1,
43*0Sstevel@tonic-gate 					       GroupConnector::Type c2,
44*0Sstevel@tonic-gate 					       GroupConnector::Type c3)
45*0Sstevel@tonic-gate : flags_(0)
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate   allow(c1);
48*0Sstevel@tonic-gate   allow(c2);
49*0Sstevel@tonic-gate   allow(c3);
50*0Sstevel@tonic-gate }
51*0Sstevel@tonic-gate 
AllowedGroupConnectors(GroupConnector::Type c1,GroupConnector::Type c2,GroupConnector::Type c3,GroupConnector::Type c4)52*0Sstevel@tonic-gate AllowedGroupConnectors::AllowedGroupConnectors(GroupConnector::Type c1,
53*0Sstevel@tonic-gate 					       GroupConnector::Type c2,
54*0Sstevel@tonic-gate 					       GroupConnector::Type c3,
55*0Sstevel@tonic-gate 					       GroupConnector::Type c4)
56*0Sstevel@tonic-gate : flags_(0)
57*0Sstevel@tonic-gate {
58*0Sstevel@tonic-gate   allow(c1);
59*0Sstevel@tonic-gate   allow(c2);
60*0Sstevel@tonic-gate   allow(c3);
61*0Sstevel@tonic-gate   allow(c4);
62*0Sstevel@tonic-gate }
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate 
AllowedGroupConnectorsMessageArg(const AllowedGroupConnectors & allow,const ConstPtr<Syntax> & syntax)65*0Sstevel@tonic-gate AllowedGroupConnectorsMessageArg::AllowedGroupConnectorsMessageArg(
66*0Sstevel@tonic-gate   const AllowedGroupConnectors &allow,
67*0Sstevel@tonic-gate   const ConstPtr<Syntax> &syntax)
68*0Sstevel@tonic-gate : allow_(allow),
69*0Sstevel@tonic-gate   syntax_(syntax)
70*0Sstevel@tonic-gate {
71*0Sstevel@tonic-gate }
72*0Sstevel@tonic-gate 
copy() const73*0Sstevel@tonic-gate MessageArg *AllowedGroupConnectorsMessageArg::copy() const
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate   return new AllowedGroupConnectorsMessageArg(*this);
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate 
append(MessageBuilder & builder) const78*0Sstevel@tonic-gate void AllowedGroupConnectorsMessageArg::append(MessageBuilder &builder) const
79*0Sstevel@tonic-gate {
80*0Sstevel@tonic-gate   static GroupConnector::Type types[] = {
81*0Sstevel@tonic-gate     GroupConnector::andGC, GroupConnector::orGC, GroupConnector::seqGC,
82*0Sstevel@tonic-gate     GroupConnector::grpcGC, GroupConnector::dtgcGC
83*0Sstevel@tonic-gate     };
84*0Sstevel@tonic-gate   static Syntax::DelimGeneral delims[] = {
85*0Sstevel@tonic-gate     Syntax::dAND, Syntax::dOR, Syntax::dSEQ,
86*0Sstevel@tonic-gate     Syntax::dGRPC, Syntax::dDTGC
87*0Sstevel@tonic-gate     };
88*0Sstevel@tonic-gate   Boolean first = 1;
89*0Sstevel@tonic-gate   for (size_t i = 0; i < SIZEOF(types); i++)
90*0Sstevel@tonic-gate     if (allow_.groupConnector(types[i])) {
91*0Sstevel@tonic-gate       if (!first)
92*0Sstevel@tonic-gate 	builder.appendFragment(ParserMessages::listSep);
93*0Sstevel@tonic-gate       else
94*0Sstevel@tonic-gate 	first = 0;
95*0Sstevel@tonic-gate       const StringC &delim = syntax_->delimGeneral(delims[i]);
96*0Sstevel@tonic-gate       builder.appendFragment(ParserMessages::delimStart);
97*0Sstevel@tonic-gate       builder.appendChars(delim.data(), delim.size());
98*0Sstevel@tonic-gate       builder.appendFragment(ParserMessages::delimEnd);
99*0Sstevel@tonic-gate     }
100*0Sstevel@tonic-gate }
101*0Sstevel@tonic-gate 
AllowedGroupTokensMessageArg(const AllowedGroupTokens & allow,const ConstPtr<Syntax> & syntax)102*0Sstevel@tonic-gate AllowedGroupTokensMessageArg::AllowedGroupTokensMessageArg(
103*0Sstevel@tonic-gate   const AllowedGroupTokens &allow,
104*0Sstevel@tonic-gate   const ConstPtr<Syntax> &syntax)
105*0Sstevel@tonic-gate : allow_(allow),
106*0Sstevel@tonic-gate   syntax_(syntax)
107*0Sstevel@tonic-gate {
108*0Sstevel@tonic-gate }
109*0Sstevel@tonic-gate 
copy() const110*0Sstevel@tonic-gate MessageArg *AllowedGroupTokensMessageArg::copy() const
111*0Sstevel@tonic-gate {
112*0Sstevel@tonic-gate   return new AllowedGroupTokensMessageArg(*this);
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate 
append(MessageBuilder & builder) const115*0Sstevel@tonic-gate void AllowedGroupTokensMessageArg::append(MessageBuilder &builder) const
116*0Sstevel@tonic-gate {
117*0Sstevel@tonic-gate   const MessageFragment *fragment[4];
118*0Sstevel@tonic-gate   int nFragments = 0;
119*0Sstevel@tonic-gate   if (allow_.groupToken(GroupToken::dataTagLiteral))
120*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::parameterLiteral;
121*0Sstevel@tonic-gate   if (allow_.groupToken(GroupToken::dataTagGroup))
122*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::dataTagGroup;
123*0Sstevel@tonic-gate   switch (allow_.group()) {
124*0Sstevel@tonic-gate   case GroupToken::modelGroup:
125*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::modelGroup;
126*0Sstevel@tonic-gate     break;
127*0Sstevel@tonic-gate   case GroupToken::dataTagTemplateGroup:
128*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::dataTagTemplateGroup;
129*0Sstevel@tonic-gate     break;
130*0Sstevel@tonic-gate   default:
131*0Sstevel@tonic-gate     break;
132*0Sstevel@tonic-gate   }
133*0Sstevel@tonic-gate   switch (allow_.nameStart()) {
134*0Sstevel@tonic-gate   case GroupToken::name:
135*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::name;
136*0Sstevel@tonic-gate     break;
137*0Sstevel@tonic-gate   case GroupToken::nameToken:
138*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::nameToken;
139*0Sstevel@tonic-gate     break;
140*0Sstevel@tonic-gate   case GroupToken::elementToken:
141*0Sstevel@tonic-gate     fragment[nFragments++] = &ParserMessages::elementToken;
142*0Sstevel@tonic-gate     break;
143*0Sstevel@tonic-gate   default:
144*0Sstevel@tonic-gate     break;
145*0Sstevel@tonic-gate   }
146*0Sstevel@tonic-gate   Boolean first = 1;
147*0Sstevel@tonic-gate   for (int i = 0; i < nFragments; i++) {
148*0Sstevel@tonic-gate     if (!first)
149*0Sstevel@tonic-gate       builder.appendFragment(ParserMessages::listSep);
150*0Sstevel@tonic-gate     else
151*0Sstevel@tonic-gate       first = 0;
152*0Sstevel@tonic-gate     builder.appendFragment(*fragment[i]);
153*0Sstevel@tonic-gate   }
154*0Sstevel@tonic-gate   if (allow_.groupToken(GroupToken::pcdata)) {
155*0Sstevel@tonic-gate     if (!first)
156*0Sstevel@tonic-gate       builder.appendFragment(ParserMessages::listSep);
157*0Sstevel@tonic-gate     StringC pcdata(syntax_->delimGeneral(Syntax::dRNI));
158*0Sstevel@tonic-gate     pcdata += syntax_->reservedName(Syntax::rPCDATA);
159*0Sstevel@tonic-gate     builder.appendChars(pcdata.data(), pcdata.size());
160*0Sstevel@tonic-gate   }
161*0Sstevel@tonic-gate }
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate #ifdef SP_NAMESPACE
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate #endif
166