Debian Codegraph @

src/utils/cst_val_const.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2001 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: January 2001 */
35 /*************************************************************************/
36 /* */
37 /* Without a real garbage collector we need some basic constant val */
38 /* to avoid having to create them on the fly */
39 /* */
40 /*************************************************************************/
41 #include "cst_val.h"
42 #include "cst_features.h"
43 #include "cst_string.h"
44
45 DEF_CONST_VAL_STRING(val_string_0,"0");
46 DEF_CONST_VAL_STRING(val_string_1,"1");
47 DEF_CONST_VAL_STRING(val_string_2,"2");
48 DEF_CONST_VAL_STRING(val_string_3,"3");
49 DEF_CONST_VAL_STRING(val_string_4,"4");
50 DEF_CONST_VAL_STRING(val_string_5,"5");
51 DEF_CONST_VAL_STRING(val_string_6,"6");
52 DEF_CONST_VAL_STRING(val_string_7,"7");
53 DEF_CONST_VAL_STRING(val_string_8,"8");
54 DEF_CONST_VAL_STRING(val_string_9,"9");
55 DEF_CONST_VAL_STRING(val_string_10,"10");
56 DEF_CONST_VAL_STRING(val_string_11,"11");
57 DEF_CONST_VAL_STRING(val_string_12,"12");
58 DEF_CONST_VAL_STRING(val_string_13,"13");
59 DEF_CONST_VAL_STRING(val_string_14,"14");
60 DEF_CONST_VAL_STRING(val_string_15,"15");
61 DEF_CONST_VAL_STRING(val_string_16,"16");
62 DEF_CONST_VAL_STRING(val_string_17,"17");
63 DEF_CONST_VAL_STRING(val_string_18,"18");
64 DEF_CONST_VAL_STRING(val_string_19,"19");
65 DEF_CONST_VAL_STRING(val_string_20,"20");
66 DEF_CONST_VAL_STRING(val_string_21,"21");
67 DEF_CONST_VAL_STRING(val_string_22,"22");
68 DEF_CONST_VAL_STRING(val_string_23,"23");
69 DEF_CONST_VAL_STRING(val_string_24,"24");
70
71 DEF_CONST_VAL_INT(val_int_0,0);
72 DEF_CONST_VAL_INT(val_int_1,1);
73 DEF_CONST_VAL_INT(val_int_2,2);
74 DEF_CONST_VAL_INT(val_int_3,3);
75 DEF_CONST_VAL_INT(val_int_4,4);
76 DEF_CONST_VAL_INT(val_int_5,5);
77 DEF_CONST_VAL_INT(val_int_6,6);
78 DEF_CONST_VAL_INT(val_int_7,7);
79 DEF_CONST_VAL_INT(val_int_8,8);
80 DEF_CONST_VAL_INT(val_int_9,9);
81 DEF_CONST_VAL_INT(val_int_10,10);
82 DEF_CONST_VAL_INT(val_int_11,11);
83 DEF_CONST_VAL_INT(val_int_12,12);
84 DEF_CONST_VAL_INT(val_int_13,13);
85 DEF_CONST_VAL_INT(val_int_14,14);
86 DEF_CONST_VAL_INT(val_int_15,15);
87 DEF_CONST_VAL_INT(val_int_16,16);
88 DEF_CONST_VAL_INT(val_int_17,17);
89 DEF_CONST_VAL_INT(val_int_18,18);
90 DEF_CONST_VAL_INT(val_int_19,19);
91 DEF_CONST_VAL_INT(val_int_20,20);
92 DEF_CONST_VAL_INT(val_int_21,21);
93 DEF_CONST_VAL_INT(val_int_22,22);
94 DEF_CONST_VAL_INT(val_int_23,23);
95 DEF_CONST_VAL_INT(val_int_24,24);
96
97 static const int val_int_const_max = 25;
98 static const cst_val * const val_int_const [] = {
99 VAL_INT_0,
100 VAL_INT_1,
101 VAL_INT_2,
102 VAL_INT_3,
103 VAL_INT_4,
104 VAL_INT_5,
105 VAL_INT_6,
106 VAL_INT_7,
107 VAL_INT_8,
108 VAL_INT_9,
109 VAL_INT_10,
110 VAL_INT_11,
111 VAL_INT_12,
112 VAL_INT_13,
113 VAL_INT_14,
114 VAL_INT_15,
115 VAL_INT_16,
116 VAL_INT_17,
117 VAL_INT_18,
118 VAL_INT_19,
119 VAL_INT_20,
120 VAL_INT_21,
121 VAL_INT_22,
122 VAL_INT_23,
123 VAL_INT_24};
124
125 static const cst_val * const val_string_const [] = {
126 VAL_STRING_0,
127 VAL_STRING_1,
128 VAL_STRING_2,
129 VAL_STRING_3,
130 VAL_STRING_4,
131 VAL_STRING_5,
132 VAL_STRING_6,
133 VAL_STRING_7,
134 VAL_STRING_8,
135 VAL_STRING_9,
136 VAL_STRING_10,
137 VAL_STRING_11,
138 VAL_STRING_12,
139 VAL_STRING_13,
140 VAL_STRING_14,
141 VAL_STRING_15,
142 VAL_STRING_16,
143 VAL_STRING_17,
144 VAL_STRING_18,
145 VAL_STRING_19,
146 VAL_STRING_20,
147 VAL_STRING_21,
148 VAL_STRING_22,
149 VAL_STRING_23,
150 VAL_STRING_24};
151
152 const cst_val *val_int_n(int n)
153 {
154 if (n < val_int_const_max)
155 return val_int_const[n];
156 else
157 return val_int_const[val_int_const_max-1];
158 }
159
160 /* carts are pretty confused about strings/ints, and some features */
161 /* are actually used as floats and as int/strings */
162 const cst_val *val_string_n(int n)
163 {
164 if (n < 0)
165 return val_string_const[0];
166 else if (n < val_int_const_max) /* yes I mean *int*, its the table size */
167 return val_string_const[n];
168 else
169 return val_string_const[val_int_const_max-1];
170 }
171
172 #if 0
173 /* This technique isn't thread safe, so I replaced it with val_consts */
174 static cst_features *val_string_consts = NULL;
175
176 const cst_val *val_string_x(const char *n)
177 {
178 const cst_val *v;
179
180 /* *BUG* This will have to be fixed soon */
181 if (val_string_consts == NULL)
182 val_string_consts = new_features();
183
184 v = feat_val(val_string_consts,n);
185 if (v)
186 return v;
187 else
188 {
189 feat_set_string(val_string_consts,n,n);
190 return feat_val(val_string_consts,n);
191 }
192 }
193 #endif