Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / evaluate.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: evaluate.cc /main/3 1996/06/11 17:10:18 cde-hal $
24 #include "Types.h"
25 #include "Expression.h"
26 #include "Feature.h"
27 #include "FeatureValue.h"
28 #include "ResolverStack.h"
29 #include "StyleSheet.h"
30 #include "StyleSheetExceptions.h"
31 #include "SymTab.h"
32 #include "VariableTable.h"
33
34 extern const Element           *gCurrentElement ;
35 extern const FeatureSet        *gCurrentLocalSet;
36 extern const FeatureSet        *gParentCompleteSet;
37
38 // unused except by HardCopy 
39 Renderer *gRenderer = 0 ; 
40
41 void
42 styleerror(char *errorstr)
43 {
44   cerr << "Parse Error: " << errorstr << endl;
45 }
46 main(int argc, char **argv)
47 {
48   INIT_EXCEPTIONS();
49   
50   StyleSheet ss;
51
52   FeatureSet fs;
53
54   
55   FeatureValue *exp ;
56
57   /* -------- String  -------- */
58   fs.add(new Feature(gSymTab->intern("string"),
59                      new FeatureValueString("this is a string")));
60
61   /* -------- Symbol  -------- */
62   fs.add(new Feature(gSymTab->intern("symbol"),
63                      new FeatureValueSymbol(gSymTab->intern("Symbol"))));
64
65   /* -------- Integer  -------- */
66
67   fs.add(new Feature(gSymTab->intern("int"),
68                      new FeatureValueInt(17)));
69
70   /* -------- Real  -------- */
71
72   fs.add(new Feature(gSymTab->intern("real"),
73                      new FeatureValueReal(42.2)));
74
75
76   /* -------- Integer addition -------- */
77   exp = new FeatureValueExpression
78     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
79                                            new ConstantNode(new FeatureValueInt(10)),
80                                            new ConstantNode(new FeatureValueInt(10)))));
81
82
83   // check cloning
84   FeatureValueExpression ep(*(FeatureValueExpression*)exp);
85
86
87   fs.add(new Feature(gSymTab->intern("int + int"), exp));
88
89   /* -------- Integer subtraction -------- */
90   exp = new FeatureValueExpression
91     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::MINUS,
92                                            new ConstantNode(new FeatureValueInt(3)),
93                                            new ConstantNode(new FeatureValueInt(127)))));
94
95   fs.add(new Feature(gSymTab->intern("int - int"), exp));
96
97   /* -------- Integer division -------- */
98   exp = new FeatureValueExpression
99     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
100                                            new ConstantNode(new FeatureValueInt(10)),
101                                            new ConstantNode(new FeatureValueInt(2)))));
102
103   fs.add(new Feature(gSymTab->intern("int / int"), exp));
104
105   /* -------- Real division -------- */
106   exp = new FeatureValueExpression
107     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
108                                            new ConstantNode(new FeatureValueReal(5)),
109                                            new ConstantNode(new FeatureValueReal(2)))));
110
111   fs.add(new Feature(gSymTab->intern("real / real"), exp));
112
113   /* -------- Real multiplication -------- */
114   exp = new FeatureValueExpression
115     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::TIMES,
116                                            new ConstantNode(new FeatureValueReal(5.1)),
117                                            new ConstantNode(new FeatureValueReal(8.7)))));
118
119   fs.add(new Feature(gSymTab->intern("real * real"), exp));
120
121   /* -------- int + real -------- */
122   exp = new FeatureValueExpression
123     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
124                                            new ConstantNode(new FeatureValueInt(5)),
125                                            new ConstantNode(new FeatureValueReal(8.7)))));
126
127   fs.add(new Feature(gSymTab->intern("int + real"), exp));
128
129
130   /* -------- real + int -------- */
131   exp = new FeatureValueExpression
132     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
133                                            new ConstantNode(new FeatureValueReal(8.7)),
134                                            new ConstantNode(new FeatureValueInt(5)))));
135
136   fs.add(new Feature(gSymTab->intern("real + int"), exp));
137
138
139   /* -------- now do some variable stuff -------- */
140
141   // empty top of stack item 
142   // gTopOfStack = new ResolverStackElement(0,new FeatureSet(),new FeatureSet());
143
144   FeatureSet *localSet = new FeatureSet ;
145   gCurrentElement = 0 ;
146   gCurrentLocalSet = localSet ;
147   gParentCompleteSet = new FeatureSet ;
148
149   // add an element for variable lookup
150   localSet->add(new Feature(gSymTab->intern("size"),
151                             new FeatureValueInt(10)));
152
153   // make some variable entries
154   // insert a duplicate to check memory leaks 
155
156   gVariableTable->enter(gSymTab->intern("DEFAULT_FONT_FAMILY"),
157                         new Expression(new ConstantNode(new FeatureValueString("courier"))));
158   gVariableTable->enter(gSymTab->intern("DEFAULT_FONT_FAMILY"),
159                         new Expression(new ConstantNode(new FeatureValueString("helvetica"))));
160
161
162   fs.add(new Feature(gSymTab->intern("exp"),
163                      new FeatureValueExpression
164                      (new Expression (new VariableNode(gSymTab->intern("DEFAULT_FONT_FAMILY"))))));
165
166   CompositeVariableNode *cvn = new CompositeVariableNode;
167   cvn->appendItem(gSymTab->intern("size"));
168   fs.add(new Feature(gSymTab->intern("Xsize"),
169                      new FeatureValueExpression(new Expression (cvn))));
170
171   /* -------- dimensions -------- */
172   fs.add(new Feature(gSymTab->intern("dim"),
173                      new FeatureValueDimension(new FeatureValueInt(10),
174                                                FeatureValueDimension::INCH)));
175
176   exp = new FeatureValueExpression
177     (new Expression
178      (new BinaryOperatorNode(BinaryOperatorNode::PLUS,
179                              new ConstantNode(new FeatureValueInt(5)),
180                              new ConstantNode
181                              (new FeatureValueDimension
182                               (new FeatureValueInt(25),
183                                FeatureValueDimension::INCH)))));
184
185   fs.add(new Feature(gSymTab->intern("int + dim"), exp));
186
187   exp = new FeatureValueExpression
188     (new Expression
189      (new BinaryOperatorNode(BinaryOperatorNode::PLUS,
190                              new ConstantNode
191                              (new FeatureValueDimension
192                               (new FeatureValueInt(25),
193                                FeatureValueDimension::INCH)),
194                              new ConstantNode(new FeatureValueInt(5)))));
195
196   fs.add(new Feature(gSymTab->intern("dim + int"), exp));
197
198
199   exp = new FeatureValueExpression
200     (new Expression
201      (new BinaryOperatorNode(BinaryOperatorNode::PLUS,
202                              new ConstantNode
203                              (new FeatureValueDimension
204                               (new FeatureValueInt(25),
205                                FeatureValueDimension::POINT)),
206                              new ConstantNode
207                              (new FeatureValueDimension
208                               (new FeatureValueInt(5),
209                                FeatureValueDimension::INCH)))));
210
211
212   fs.add(new Feature(gSymTab->intern("dim + dim"), exp));
213
214   /* -------- real * dim -------- */
215   exp = new FeatureValueExpression
216     (new Expression
217      (new BinaryOperatorNode(BinaryOperatorNode::TIMES,
218                              new ConstantNode
219                              (new FeatureValueReal(2.2)),
220                              new ConstantNode
221                              (new FeatureValueDimension
222                               (new FeatureValueInt(11),
223                                FeatureValueDimension::POINT)))));
224
225
226   fs.add(new Feature(gSymTab->intern("real * dim"), exp));
227
228
229   /* -------- dim * real -------- */
230   exp = new FeatureValueExpression
231     (new Expression
232      (new BinaryOperatorNode(BinaryOperatorNode::TIMES,
233                              new ConstantNode
234                              (new FeatureValueDimension
235                               (new FeatureValueInt(11),
236                                FeatureValueDimension::POINT)),
237                              new ConstantNode
238                              (new FeatureValueReal(2.1)))));
239
240
241   fs.add(new Feature(gSymTab->intern("dim * real"), exp));
242
243
244   /* -------- dim / real -------- */
245   exp = new FeatureValueExpression
246     (new Expression
247      (new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
248                              new ConstantNode
249                              (new FeatureValueDimension
250                               (new FeatureValueInt(11),
251                                FeatureValueDimension::POINT)),
252                              new ConstantNode
253                              (new FeatureValueReal(2.0)))));
254
255
256   fs.add(new Feature(gSymTab->intern("dim / real"), exp));
257
258
259   /* -------- real / dim -------- */
260   exp = new FeatureValueExpression
261     (new Expression
262      (new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
263                              new ConstantNode
264                              (new FeatureValueReal(11)),
265                              new ConstantNode
266                              (new FeatureValueDimension
267                               (new FeatureValueInt(2),
268                                FeatureValueDimension::POINT)))));
269
270
271   fs.add(new Feature(gSymTab->intern("real / dim"), exp));
272
273
274   /* -------- dim * int -------- */
275   exp = new FeatureValueExpression
276     (new Expression
277      (new BinaryOperatorNode(BinaryOperatorNode::TIMES,
278                              new ConstantNode
279                              (new FeatureValueDimension
280                               (new FeatureValueInt(11),
281                                FeatureValueDimension::POINT)),
282                              new ConstantNode
283                              (new FeatureValueInt(2)))));
284
285
286   fs.add(new Feature(gSymTab->intern("dim * int"), exp));
287
288
289   /* -------- int * dim -------- */
290   exp = new FeatureValueExpression
291     (new Expression
292      (new BinaryOperatorNode(BinaryOperatorNode::TIMES,
293                              new ConstantNode
294                              (new FeatureValueInt(2)),
295                              new ConstantNode
296                              (new FeatureValueDimension
297                               (new FeatureValueInt(11),
298                                FeatureValueDimension::POINT)))));
299
300
301   fs.add(new Feature(gSymTab->intern("int * dim"), exp));
302
303
304   /* -------- dim / int -------- */
305   exp = new FeatureValueExpression
306     (new Expression
307      (new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
308                              new ConstantNode
309                              (new FeatureValueDimension
310                               (new FeatureValueInt(11),
311                                FeatureValueDimension::POINT)),
312                              new ConstantNode
313                              (new FeatureValueInt(2)))));
314
315
316   fs.add(new Feature(gSymTab->intern("dim / int"), exp));
317
318
319   /* -------- int / dim -------- */
320   exp = new FeatureValueExpression
321     (new Expression
322      (new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
323                              new ConstantNode
324                              (new FeatureValueInt(22)),
325                              new ConstantNode
326                              (new FeatureValueDimension
327                               (new FeatureValueInt(11),
328                                FeatureValueDimension::POINT)))));
329
330
331   fs.add(new Feature(gSymTab->intern("int / dim"), exp));
332
333
334   
335   /* -------- int - dim -------- */
336   exp = new FeatureValueExpression
337     (new Expression
338      (new BinaryOperatorNode(BinaryOperatorNode::MINUS,
339                              new ConstantNode
340                              (new FeatureValueInt(2)),
341                              new ConstantNode
342                              (new FeatureValueDimension
343                               (new FeatureValueInt(11),
344                                FeatureValueDimension::POINT)))));
345
346
347   fs.add(new Feature(gSymTab->intern("int - dim"), exp));
348
349
350   /* -------- dim - int -------- */
351   exp = new FeatureValueExpression
352     (new Expression
353      (new BinaryOperatorNode(BinaryOperatorNode::MINUS,
354                              new ConstantNode
355                              (new FeatureValueDimension
356                               (new FeatureValueInt(11),
357                                FeatureValueDimension::POINT)),
358                              new ConstantNode
359                              (new FeatureValueInt(2)))));
360
361
362   fs.add(new Feature(gSymTab->intern("dim - int"), exp));
363
364
365   /* -------- String + String -------- */
366   exp = new FeatureValueExpression
367     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
368                                            new ConstantNode(new FeatureValueString("foo")),
369                                            new ConstantNode(new FeatureValueString("bar")))));
370
371   fs.add(new Feature(gSymTab->intern("String + String"), exp));
372
373
374
375   /* -------- String + String + String-------- */
376   FeatureValueExpression *exp1 =
377     new FeatureValueExpression
378     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
379                                            new ConstantNode(new FeatureValueString("foo")),
380                                            new ConstantNode(new FeatureValueString("bar")))));
381
382
383   exp = new FeatureValueExpression
384     (new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
385                                            new ConstantNode(exp1),
386                                            new ConstantNode(new FeatureValueString("baz")))));
387
388   fs.add(new Feature(gSymTab->intern("String + String + String"), exp));
389
390
391
392 /* -------- print out our set -------- */
393
394   cout << fs << endl;
395
396   FeatureSet *evaluated = fs.evaluate();
397
398   cout << *evaluated << endl;
399
400   delete evaluated ;
401
402
403   cout << *gVariableTable << endl;
404
405   // write this guy out that we created at the top 
406   cout << ep << endl;
407
408   delete gCurrentLocalSet ;
409   delete gParentCompleteSet ;
410
411   FeatureValueDimension *dtest =
412     new FeatureValueDimension
413     (new FeatureValueDimension(new FeatureValueInt(72),
414                                FeatureValue::POINT),
415      FeatureValue::INCH);
416
417   cout << *dtest << endl;
418   cout << (float)*dtest << endl;
419   delete dtest ;
420
421 }