Merge branch 'master' of https://git.code.sf.net/p/cdesktopenv/code
[oweals/cde.git] / cde / programs / nsgmls / Sd.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: Sd.h /main/1 1996/07/29 17:03:44 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Sd_INCLUDED
28 #define Sd_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "types.h"
34 #include "Boolean.h"
35 #include "Resource.h"
36 #include "CharsetInfo.h"
37 #include "ExternalId.h"
38 #include "ISet.h"
39 #include "Syntax.h"
40 #include "CharsetDecl.h"
41 #include "HashTable.h"
42
43 // Information about the SGML declaration that is not syntax specific.
44
45 #ifdef SP_NAMESPACE
46 namespace SP_NAMESPACE {
47 #endif
48
49 class SP_API Sd : public Resource {
50 public:
51   // These must be in the same order as in the SGML declaration.
52   enum BooleanFeature {
53     fDATATAG,
54     fOMITTAG,
55     fRANK,
56     fSHORTTAG,
57     fIMPLICIT,
58     fFORMAL
59     };
60   enum { nBooleanFeature = fFORMAL + 1 };
61   // These must be in the same order as in the SGML declaration.
62   enum NumberFeature {
63     fSIMPLE,
64     fEXPLICIT,
65     fCONCUR,
66     fSUBDOC
67   };
68   enum { nNumberFeature = fSUBDOC + 1 };
69   // These are names used only in the SGML declaration.
70   enum ReservedName {
71     rAPPINFO,
72     rBASESET,
73     rCAPACITY,
74     rCHARSET,
75     rCONCUR,
76     rCONTROLS,
77     rDATATAG,
78     rDELIM,
79     rDESCSET,
80     rDOCUMENT,
81     rENTITY,
82     rEXPLICIT,
83     rFEATURES,
84     rFORMAL,
85     rFUNCHAR,
86     rFUNCTION,
87     rGENERAL,
88     rIMPLICIT,
89     rINSTANCE,
90     rLCNMCHAR,
91     rLCNMSTRT,
92     rLINK,
93     rMINIMIZE,
94     rMSICHAR,
95     rMSOCHAR,
96     rMSSCHAR,
97     rNAMECASE,
98     rNAMES,
99     rNAMING,
100     rNO,
101     rNONE,
102     rOMITTAG,
103     rOTHER,
104     rPUBLIC,
105     rQUANTITY,
106     rRANK,
107     rRE,
108     rRS,
109     rSCOPE,
110     rSEPCHAR,
111     rSGML,
112     rSGMLREF,
113     rSHORTREF,
114     rSHORTTAG,
115     rSHUNCHAR,
116     rSIMPLE,
117     rSPACE,
118     rSUBDOC,
119     rSWITCHES,
120     rSYNTAX,
121     rUCNMCHAR,
122     rUCNMSTRT,
123     rUNUSED,
124     rYES
125   };
126   enum Capacity {
127     TOTALCAP,
128     ENTCAP,
129     ENTCHCAP,
130     ELEMCAP,
131     GRPCAP,
132     EXGRPCAP,
133     EXNMCAP,
134     ATTCAP,
135     ATTCHCAP,
136     AVGRPCAP,
137     NOTCAP,
138     NOTCHCAP,
139     IDCAP,
140     IDREFCAP,
141     MAPCAP,
142     LKSETCAP,
143     LKNMCAP
144   };
145   enum { nCapacity = LKNMCAP + 1 };
146   Sd();
147   void setDocCharsetDesc(const UnivCharsetDesc &);
148   void setSgmlChar(const ISet<Char> &);
149   Boolean matchesReservedName(const StringC &, ReservedName) const;
150   int digitWeight(Char) const;
151   Boolean link() const;
152   Number simpleLink() const;
153   Boolean implicitLink() const;
154   Number explicitLink() const;
155   Boolean shorttag() const;
156   Number concur() const;
157   Boolean omittag() const;
158   Boolean rank() const;
159   Boolean datatag() const;
160   Boolean formal() const;
161   Number subdoc() const;
162   StringC reservedName(int) const;
163   Boolean lookupQuantityName(const StringC &, Syntax::Quantity &) const;
164   Boolean lookupGeneralDelimiterName(const StringC &, Syntax::DelimGeneral &)
165        const;
166   Boolean lookupCapacityName(const StringC &, Sd::Capacity &) const;
167   StringC quantityName(Syntax::Quantity) const;
168   const CharsetInfo &docCharset() const;
169   Char execToDoc(char) const;
170   StringC execToDoc(const char *) const;
171   Number capacity(int) const;
172   void setCapacity(int, Number);
173   StringC capacityName(int) const;
174   Boolean scopeInstance() const;
175   void setScopeInstance();
176   void setDocCharsetDecl(CharsetDecl &);
177   const CharsetDecl &docCharsetDecl() const;
178   void setBooleanFeature(BooleanFeature, Boolean);
179   void setNumberFeature(NumberFeature, Number);
180   StringC generalDelimiterName(Syntax::DelimGeneral) const;
181   UnivChar nameToUniv(const StringC &);
182 private:
183   enum { nFeature = fFORMAL + 1 };
184   PackedBoolean booleanFeature_[nBooleanFeature];
185   Number numberFeature_[nNumberFeature];
186   Number capacity_[nCapacity];
187   CharsetInfo docCharset_;
188   CharsetDecl docCharsetDecl_;
189   Boolean scopeInstance_;
190   HashTable<StringC,int> namedCharTable_;
191   static const char *const reservedName_[];
192   static const char *const generalDelimiterName_[];
193   static const char *const capacityName_[];
194   static const char *const quantityName_[];
195 };
196
197 inline
198 Boolean Sd::link() const
199 {
200   return (numberFeature_[fSIMPLE]
201           || booleanFeature_[fIMPLICIT]
202           || numberFeature_[fEXPLICIT]);
203 }
204
205 inline
206 Number Sd::explicitLink() const
207 {
208   return numberFeature_[fEXPLICIT];
209 }
210
211 inline
212 Boolean Sd::implicitLink() const
213 {
214   return booleanFeature_[fIMPLICIT];
215 }
216
217 inline
218 Number Sd::simpleLink() const
219 {
220   return numberFeature_[fSIMPLE];
221 }
222
223 inline
224 Boolean Sd::shorttag() const
225 {
226   return booleanFeature_[fSHORTTAG];
227 }
228
229 inline
230 Number Sd::concur() const
231 {
232   return numberFeature_[fCONCUR];
233 }
234
235 inline
236 Number Sd::subdoc() const
237 {
238   return numberFeature_[fSUBDOC];
239 }
240
241
242 inline
243 Boolean Sd::omittag() const
244 {
245   return booleanFeature_[fOMITTAG];
246 }
247
248 inline
249 Boolean Sd::rank() const
250 {
251   return booleanFeature_[fRANK];
252 }
253
254 inline
255 Boolean Sd::datatag() const
256 {
257   return booleanFeature_[fDATATAG];
258 }
259
260 inline
261 Boolean Sd::formal() const
262 {
263   return booleanFeature_[fFORMAL];
264 }
265
266 inline
267 Char Sd::execToDoc(char c) const
268 {
269   return docCharset_.execToDesc(c);
270 }
271
272 inline
273 StringC Sd::execToDoc(const char *s) const
274 {
275   return docCharset_.execToDesc(s);
276 }
277
278 inline
279 StringC Sd::reservedName(int i) const
280 {
281   return execToDoc(reservedName_[i]);
282 }
283
284 inline
285 const CharsetInfo &Sd::docCharset() const
286 {
287   return docCharset_;
288 }
289
290 inline
291 int Sd::digitWeight(Char c) const
292 {
293   return docCharset_.digitWeight(c);
294 }
295
296 inline
297 Number Sd::capacity(int i) const
298 {
299   return capacity_[i];
300 }
301
302 inline
303 void Sd::setCapacity(int i, Number n)
304 {
305   capacity_[i] = n;
306 }
307
308 inline
309 StringC Sd::capacityName(int i) const
310 {
311   return execToDoc(capacityName_[i]);
312 }
313
314 inline
315 Boolean Sd::scopeInstance() const
316 {
317   return scopeInstance_;
318 }
319
320 inline
321 void Sd::setScopeInstance()
322 {
323   scopeInstance_ = 1;
324 }
325
326 inline
327 void Sd::setDocCharsetDecl(CharsetDecl &decl)
328 {
329   decl.swap(docCharsetDecl_);
330 }
331
332 inline
333 const CharsetDecl &Sd::docCharsetDecl() const
334 {
335   return docCharsetDecl_;
336 }
337
338 inline
339 void Sd::setBooleanFeature(BooleanFeature i, Boolean b)
340 {
341   booleanFeature_[i] = b;
342 }
343
344 inline
345 void Sd::setNumberFeature(NumberFeature i, Number n)
346 {
347   numberFeature_[i] = n;
348 }
349
350 #ifdef SP_NAMESPACE
351 }
352 #endif
353
354 #endif /* Sd_INCLUDED */