Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / feature.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: feature.cc /main/3 1996/06/11 17:10:23 cde-hal $
24 #include "StyleSheetExceptions.h"
25 #include "SymTab.h"
26 #include "Feature.h"
27 #include "FeatureValue.h"
28 #include "StyleSheet.h"
29
30
31
32
33 #include <stdlib.h>
34
35 void
36 styleerror(char *errorstr)
37 {
38   cerr << "Parse Error: " << errorstr << endl;
39 }
40
41 main(int argc, char **argv)
42 {
43   INIT_EXCEPTIONS();
44
45   Stack<FeatureSet*,dlist_array<FeatureSet> > *stack;
46   Stack<FeatureSet*,dlist_array<FeatureSet> > stack1 ;
47   Stack<FeatureSet*,dlist_array<FeatureSet> > stack2 ;
48
49   stack1.push(new FeatureSet());
50   stack2.push(new FeatureSet());
51
52   stack = &stack1 ;
53
54   StyleSheet ss ;
55
56   // make sure args are balanced 
57
58   /*
59   if (!(argc & 1))
60     cout << "feature  [<name> <value>]+" << endl;
61     */
62
63   for (int i = 1 ; i < argc ; )
64     {
65       switch (argv[i][0])
66         {
67         case '-':
68           // start a new feature set
69           stack = &stack2 ;
70           i++ ;
71           break;
72         case '{':
73           {
74             i++ ;
75             FeatureSet *newset = new FeatureSet();
76             stack->top()->add(new Feature(gSymTab->intern(argv[i++]),
77                                           new FeatureValueFeatureSet(newset)));
78             stack->push(newset);
79           }
80           break;
81           
82         case '}':
83           stack->pop();
84           i++;
85           break;
86
87         default:
88           {
89             char c = argv[i+1][0] ;
90             FeatureValue *value = 0; 
91
92             if (c >= '0' && c <= '9')
93               value = new FeatureValueInt(atoi(argv[i+1]));
94             else if ( c == '\'')
95               value = new FeatureValueSymbol(gSymTab->intern(argv[i+1]));
96             else
97               value = new FeatureValueString(argv[i+1]);
98
99             stack->top()->add(new Feature(gSymTab->intern(argv[i++]),
100                                           value));
101             i++;
102           }
103           break;
104         }
105     }
106
107   cout << "************** orig ****************" << endl;
108   cout << *stack1.top() << endl;
109   cout << "************** copy ****************" << endl;
110
111   FeatureSet *copy = new FeatureSet(*stack1.top());
112
113   cout << *copy << endl;
114   delete copy;
115
116   // now test merge 
117
118   FeatureSet *merged = new FeatureSet(*stack1.top(), *stack2.top());
119                       
120   // delete these and check for memory leaks
121   delete stack1.pop();
122   delete stack2.pop();
123
124   cout << "************** merged ****************" << endl;
125   cout << *merged << endl;
126
127
128   try {
129     const Feature *f = merged->deep_lookup("font", "size", 0);
130     cout << "deep_lookup(\"font\", \"size\"): " ;
131     if (f)
132       cout << *f << endl;
133     else
134       cout << "(nil)" << endl;
135     
136     // now try it with Symbols 
137     Symbol font (gSymTab->intern("font"));
138     Symbol size (gSymTab->intern("size"));
139     f = merged->deep_lookup(&font,
140                             &size, 0);
141     cout << "deep_lookup(\"font\", \"size\"): " ;
142     if (f)
143       cout << *f << endl;
144     else
145       cout << "(nil)" << endl;
146     
147   }
148   catch_any()
149     {
150       cout << "exception thrown" << endl;
151     }
152   end_try;
153
154   delete merged ;
155
156 }