Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / UAS / DtSR / Tml_TextRenderer.C
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: Tml_TextRenderer.C /main/7 1996/09/10 16:03:56 cde-hal $
24 /*      Copyright (c) 1995,1996 FUJITSU LIMITED         */
25 /*      All Rights Reserved                             */
26
27 #include <assert.h>
28
29 #include "Tml_TextRenderer.hh"
30 #include "DtSR_SearchZones.hh"
31
32 #include "StyleSheet/FeatureValue.h"
33
34 Tml_TextRenderer::Tml_TextRenderer(ostrstream &ostr, UAS_SearchZones &zones) :
35         f_ostr(ostr), f_zones(zones)
36 {
37 }
38
39 Tml_TextRenderer::~Tml_TextRenderer()
40 {
41 }
42
43 FeatureSet *
44 Tml_TextRenderer::initialize()
45 {
46     // NOTE: You don't have to keep track of default_features.
47     //       Resolver will take care of the rest (i.e. delete).
48     FeatureSet* default_features = new FeatureSet;
49
50     default_features->add(new Feature(gSymTab->intern("IGNORE"),
51                                         new FeatureValueInt(0)));
52
53     return default_features;
54 }
55
56 void
57 Tml_TextRenderer::Begin()
58 {
59     f_current_level = 0;
60
61     for (; f_marked_level.entries(); f_marked_level.pop());
62     f_marked_level.push(f_current_level);
63
64     for (; f_effect.entries(); f_effect.pop());
65
66     char base_effect;
67     if (effective_zone(DtSR_SearchZones::uas_bodies))
68         base_effect = ShiftIn;
69     else
70         base_effect = ShiftOut;
71
72     f_effect.push(base_effect);
73     f_ostr << f_effect.top();
74
75     f_ignore_stack.push(0);
76 }
77
78 void
79 Tml_TextRenderer::End()
80 {
81     f_ostr << flush;
82
83     if (f_ignore_stack.entries())
84         f_ignore_stack.pop();
85 }
86
87 int
88 Tml_TextRenderer::effective_zone(UAS_SearchZones::uas_zones zone)
89 {
90     switch (zone) {
91         case UAS_SearchZones::uas_titles :
92             return f_zones.titles();
93             break;
94         case UAS_SearchZones::uas_bodies :
95             return f_zones.bodies();
96             break;
97         case UAS_SearchZones::uas_examples :
98             return f_zones.examples();
99             break;
100         case UAS_SearchZones::uas_indexes :
101             return f_zones.indexes();
102             break;
103         case UAS_SearchZones::uas_tables :
104             return f_zones.tables();
105             break;
106         case UAS_SearchZones::uas_graphics :
107             return f_zones.graphics();
108             break;
109         default:
110             fprintf(stderr, "(ERROR) unknown zone found\n");
111             break;
112     }
113
114     return False;
115 }
116
117 unsigned int
118 Tml_TextRenderer::BeginElement(const Element    &element,
119                   const FeatureSet&, const FeatureSet& complete,
120                   const FeatureSet&)
121 {
122     f_current_level++;
123
124     const Attribute *scope_attr =
125         element.get_attribute(gSymTab->intern("OLIAS.SCOPE"));
126
127     if (scope_attr) { // scope attribute specified
128
129         f_marked_level.push(f_current_level);
130
131 #ifdef DEBUG
132         fprintf(stderr, "(DEBUG) %s specifies OLIAS.SCOPE=\"%s\"\n",
133                         element.gi().name(), scope_attr->value());
134 #endif
135         char effect;
136         if (effective_zone(DtSR_SearchZones::
137                                         zonename2zone(scope_attr->value()))) {
138             effect = ShiftIn;
139         }
140         else {
141             effect = ShiftOut;
142         }
143
144         f_effect.push(effect);
145         f_ostr << f_effect.top();
146     }
147
148     const Attribute *terms_attr =
149         element.get_olias_attribute(gSymTab->intern("TERMS"));
150
151     CC_TPtrSlistIterator<Feature> iter(*(FeatureSet*)&complete);
152     while (++iter) {
153         const Symbol &feature = iter.key()->name();
154         if (feature == gSymTab->intern("IGNORE")) {
155             Feature *ignore = iter.key();
156             f_ignore_stack.push((int)*(ignore->value()));
157         }
158     }
159
160     if (terms_attr) {
161         const char* terms = terms_attr->value();
162         f_ostr << terms << '\n';
163         return True;
164     }
165
166     return False;
167 }
168
169 void
170 Tml_TextRenderer::EndElement(const Symbol &)
171 {
172     f_ostr << '\n';
173
174     if (f_current_level == f_marked_level.top()) {
175
176         f_effect.pop();
177         f_ostr << f_effect.top();
178
179         f_marked_level.pop();
180     }
181
182     f_current_level--;
183
184     if (f_ignore_stack.entries())
185         f_ignore_stack.pop();
186 }
187
188 void
189 Tml_TextRenderer::data(const char *data, unsigned int)
190 {
191     if (! f_ignore_stack.top())
192         f_ostr << data;
193 }
194