ucgendat.c revision 1.1.1.1.2.2 1 1.1.1.1.2.2 yamt /* $OpenLDAP: pkg/ldap/libraries/liblunicode/ucdata/ucgendat.c,v 1.39.2.3 2008/02/11 23:26:42 kurt Exp $ */
2 1.1.1.1.2.2 yamt /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 1.1.1.1.2.2 yamt *
4 1.1.1.1.2.2 yamt * Copyright 1998-2008 The OpenLDAP Foundation.
5 1.1.1.1.2.2 yamt * All rights reserved.
6 1.1.1.1.2.2 yamt *
7 1.1.1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.1.1.1.2.2 yamt * modification, are permitted only as authorized by the OpenLDAP
9 1.1.1.1.2.2 yamt * Public License.
10 1.1.1.1.2.2 yamt *
11 1.1.1.1.2.2 yamt * A copy of this license is available in file LICENSE in the
12 1.1.1.1.2.2 yamt * top-level directory of the distribution or, alternatively, at
13 1.1.1.1.2.2 yamt * <http://www.OpenLDAP.org/license.html>.
14 1.1.1.1.2.2 yamt */
15 1.1.1.1.2.2 yamt /* Copyright 2001 Computing Research Labs, New Mexico State University
16 1.1.1.1.2.2 yamt *
17 1.1.1.1.2.2 yamt * Permission is hereby granted, free of charge, to any person obtaining a
18 1.1.1.1.2.2 yamt * copy of this software and associated documentation files (the "Software"),
19 1.1.1.1.2.2 yamt * to deal in the Software without restriction, including without limitation
20 1.1.1.1.2.2 yamt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21 1.1.1.1.2.2 yamt * and/or sell copies of the Software, and to permit persons to whom the
22 1.1.1.1.2.2 yamt * Software is furnished to do so, subject to the following conditions:
23 1.1.1.1.2.2 yamt *
24 1.1.1.1.2.2 yamt * The above copyright notice and this permission notice shall be included in
25 1.1.1.1.2.2 yamt * all copies or substantial portions of the Software.
26 1.1.1.1.2.2 yamt *
27 1.1.1.1.2.2 yamt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 1.1.1.1.2.2 yamt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 1.1.1.1.2.2 yamt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 1.1.1.1.2.2 yamt * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
31 1.1.1.1.2.2 yamt * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
32 1.1.1.1.2.2 yamt * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
33 1.1.1.1.2.2 yamt * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 1.1.1.1.2.2 yamt */
35 1.1.1.1.2.2 yamt /* $Id: ucgendat.c,v 1.1.1.1.2.2 2008/06/04 02:04:01 yamt Exp $" */
36 1.1.1.1.2.2 yamt
37 1.1.1.1.2.2 yamt #include "portable.h"
38 1.1.1.1.2.2 yamt #include "ldap_config.h"
39 1.1.1.1.2.2 yamt
40 1.1.1.1.2.2 yamt #include <stdio.h>
41 1.1.1.1.2.2 yamt #include <ac/ctype.h>
42 1.1.1.1.2.2 yamt #include <ac/stdlib.h>
43 1.1.1.1.2.2 yamt #include <ac/string.h>
44 1.1.1.1.2.2 yamt #include <ac/unistd.h>
45 1.1.1.1.2.2 yamt
46 1.1.1.1.2.2 yamt #include <ac/bytes.h>
47 1.1.1.1.2.2 yamt
48 1.1.1.1.2.2 yamt #include <lutil.h>
49 1.1.1.1.2.2 yamt
50 1.1.1.1.2.2 yamt #ifndef HARDCODE_DATA
51 1.1.1.1.2.2 yamt #define HARDCODE_DATA 1
52 1.1.1.1.2.2 yamt #endif
53 1.1.1.1.2.2 yamt
54 1.1.1.1.2.2 yamt #undef ishdigit
55 1.1.1.1.2.2 yamt #define ishdigit(cc) (((cc) >= '0' && (cc) <= '9') ||\
56 1.1.1.1.2.2 yamt ((cc) >= 'A' && (cc) <= 'F') ||\
57 1.1.1.1.2.2 yamt ((cc) >= 'a' && (cc) <= 'f'))
58 1.1.1.1.2.2 yamt
59 1.1.1.1.2.2 yamt /*
60 1.1.1.1.2.2 yamt * A header written to the output file with the byte-order-mark and the number
61 1.1.1.1.2.2 yamt * of property nodes.
62 1.1.1.1.2.2 yamt */
63 1.1.1.1.2.2 yamt static ac_uint2 hdr[2] = {0xfeff, 0};
64 1.1.1.1.2.2 yamt
65 1.1.1.1.2.2 yamt #define NUMPROPS 50
66 1.1.1.1.2.2 yamt #define NEEDPROPS (NUMPROPS + (4 - (NUMPROPS & 3)))
67 1.1.1.1.2.2 yamt
68 1.1.1.1.2.2 yamt typedef struct {
69 1.1.1.1.2.2 yamt char *name;
70 1.1.1.1.2.2 yamt int len;
71 1.1.1.1.2.2 yamt } _prop_t;
72 1.1.1.1.2.2 yamt
73 1.1.1.1.2.2 yamt /*
74 1.1.1.1.2.2 yamt * List of properties expected to be found in the Unicode Character Database
75 1.1.1.1.2.2 yamt * including some implementation specific properties.
76 1.1.1.1.2.2 yamt *
77 1.1.1.1.2.2 yamt * The implementation specific properties are:
78 1.1.1.1.2.2 yamt * Cm = Composed (can be decomposed)
79 1.1.1.1.2.2 yamt * Nb = Non-breaking
80 1.1.1.1.2.2 yamt * Sy = Symmetric (has left and right forms)
81 1.1.1.1.2.2 yamt * Hd = Hex digit
82 1.1.1.1.2.2 yamt * Qm = Quote marks
83 1.1.1.1.2.2 yamt * Mr = Mirroring
84 1.1.1.1.2.2 yamt * Ss = Space, other
85 1.1.1.1.2.2 yamt * Cp = Defined character
86 1.1.1.1.2.2 yamt */
87 1.1.1.1.2.2 yamt static _prop_t props[NUMPROPS] = {
88 1.1.1.1.2.2 yamt {"Mn", 2}, {"Mc", 2}, {"Me", 2}, {"Nd", 2}, {"Nl", 2}, {"No", 2},
89 1.1.1.1.2.2 yamt {"Zs", 2}, {"Zl", 2}, {"Zp", 2}, {"Cc", 2}, {"Cf", 2}, {"Cs", 2},
90 1.1.1.1.2.2 yamt {"Co", 2}, {"Cn", 2}, {"Lu", 2}, {"Ll", 2}, {"Lt", 2}, {"Lm", 2},
91 1.1.1.1.2.2 yamt {"Lo", 2}, {"Pc", 2}, {"Pd", 2}, {"Ps", 2}, {"Pe", 2}, {"Po", 2},
92 1.1.1.1.2.2 yamt {"Sm", 2}, {"Sc", 2}, {"Sk", 2}, {"So", 2}, {"L", 1}, {"R", 1},
93 1.1.1.1.2.2 yamt {"EN", 2}, {"ES", 2}, {"ET", 2}, {"AN", 2}, {"CS", 2}, {"B", 1},
94 1.1.1.1.2.2 yamt {"S", 1}, {"WS", 2}, {"ON", 2},
95 1.1.1.1.2.2 yamt {"Cm", 2}, {"Nb", 2}, {"Sy", 2}, {"Hd", 2}, {"Qm", 2}, {"Mr", 2},
96 1.1.1.1.2.2 yamt {"Ss", 2}, {"Cp", 2}, {"Pi", 2}, {"Pf", 2}, {"AL", 2}
97 1.1.1.1.2.2 yamt };
98 1.1.1.1.2.2 yamt
99 1.1.1.1.2.2 yamt typedef struct {
100 1.1.1.1.2.2 yamt ac_uint4 *ranges;
101 1.1.1.1.2.2 yamt ac_uint2 used;
102 1.1.1.1.2.2 yamt ac_uint2 size;
103 1.1.1.1.2.2 yamt } _ranges_t;
104 1.1.1.1.2.2 yamt
105 1.1.1.1.2.2 yamt static _ranges_t proptbl[NUMPROPS];
106 1.1.1.1.2.2 yamt
107 1.1.1.1.2.2 yamt /*
108 1.1.1.1.2.2 yamt * Make sure this array is sized to be on a 4-byte boundary at compile time.
109 1.1.1.1.2.2 yamt */
110 1.1.1.1.2.2 yamt static ac_uint2 propcnt[NEEDPROPS];
111 1.1.1.1.2.2 yamt
112 1.1.1.1.2.2 yamt /*
113 1.1.1.1.2.2 yamt * Array used to collect a decomposition before adding it to the decomposition
114 1.1.1.1.2.2 yamt * table.
115 1.1.1.1.2.2 yamt */
116 1.1.1.1.2.2 yamt static ac_uint4 dectmp[64];
117 1.1.1.1.2.2 yamt static ac_uint4 dectmp_size;
118 1.1.1.1.2.2 yamt
119 1.1.1.1.2.2 yamt typedef struct {
120 1.1.1.1.2.2 yamt ac_uint4 code;
121 1.1.1.1.2.2 yamt ac_uint2 size;
122 1.1.1.1.2.2 yamt ac_uint2 used;
123 1.1.1.1.2.2 yamt ac_uint4 *decomp;
124 1.1.1.1.2.2 yamt } _decomp_t;
125 1.1.1.1.2.2 yamt
126 1.1.1.1.2.2 yamt /*
127 1.1.1.1.2.2 yamt * List of decomposition. Created and expanded in order as the characters are
128 1.1.1.1.2.2 yamt * encountered. First list contains canonical mappings, second also includes
129 1.1.1.1.2.2 yamt * compatibility mappings.
130 1.1.1.1.2.2 yamt */
131 1.1.1.1.2.2 yamt static _decomp_t *decomps;
132 1.1.1.1.2.2 yamt static ac_uint4 decomps_used;
133 1.1.1.1.2.2 yamt static ac_uint4 decomps_size;
134 1.1.1.1.2.2 yamt
135 1.1.1.1.2.2 yamt static _decomp_t *kdecomps;
136 1.1.1.1.2.2 yamt static ac_uint4 kdecomps_used;
137 1.1.1.1.2.2 yamt static ac_uint4 kdecomps_size;
138 1.1.1.1.2.2 yamt
139 1.1.1.1.2.2 yamt /*
140 1.1.1.1.2.2 yamt * Composition exclusion table stuff.
141 1.1.1.1.2.2 yamt */
142 1.1.1.1.2.2 yamt #define COMPEX_SET(c) (compexs[(c) >> 5] |= (1 << ((c) & 31)))
143 1.1.1.1.2.2 yamt #define COMPEX_TEST(c) (compexs[(c) >> 5] & (1 << ((c) & 31)))
144 1.1.1.1.2.2 yamt static ac_uint4 compexs[8192];
145 1.1.1.1.2.2 yamt
146 1.1.1.1.2.2 yamt /*
147 1.1.1.1.2.2 yamt * Struct for holding a composition pair, and array of composition pairs
148 1.1.1.1.2.2 yamt */
149 1.1.1.1.2.2 yamt typedef struct {
150 1.1.1.1.2.2 yamt ac_uint4 comp;
151 1.1.1.1.2.2 yamt ac_uint4 count;
152 1.1.1.1.2.2 yamt ac_uint4 code1;
153 1.1.1.1.2.2 yamt ac_uint4 code2;
154 1.1.1.1.2.2 yamt } _comp_t;
155 1.1.1.1.2.2 yamt
156 1.1.1.1.2.2 yamt static _comp_t *comps;
157 1.1.1.1.2.2 yamt static ac_uint4 comps_used;
158 1.1.1.1.2.2 yamt
159 1.1.1.1.2.2 yamt /*
160 1.1.1.1.2.2 yamt * Types and lists for handling lists of case mappings.
161 1.1.1.1.2.2 yamt */
162 1.1.1.1.2.2 yamt typedef struct {
163 1.1.1.1.2.2 yamt ac_uint4 key;
164 1.1.1.1.2.2 yamt ac_uint4 other1;
165 1.1.1.1.2.2 yamt ac_uint4 other2;
166 1.1.1.1.2.2 yamt } _case_t;
167 1.1.1.1.2.2 yamt
168 1.1.1.1.2.2 yamt static _case_t *upper;
169 1.1.1.1.2.2 yamt static _case_t *lower;
170 1.1.1.1.2.2 yamt static _case_t *title;
171 1.1.1.1.2.2 yamt static ac_uint4 upper_used;
172 1.1.1.1.2.2 yamt static ac_uint4 upper_size;
173 1.1.1.1.2.2 yamt static ac_uint4 lower_used;
174 1.1.1.1.2.2 yamt static ac_uint4 lower_size;
175 1.1.1.1.2.2 yamt static ac_uint4 title_used;
176 1.1.1.1.2.2 yamt static ac_uint4 title_size;
177 1.1.1.1.2.2 yamt
178 1.1.1.1.2.2 yamt /*
179 1.1.1.1.2.2 yamt * Array used to collect case mappings before adding them to a list.
180 1.1.1.1.2.2 yamt */
181 1.1.1.1.2.2 yamt static ac_uint4 cases[3];
182 1.1.1.1.2.2 yamt
183 1.1.1.1.2.2 yamt /*
184 1.1.1.1.2.2 yamt * An array to hold ranges for combining classes.
185 1.1.1.1.2.2 yamt */
186 1.1.1.1.2.2 yamt static ac_uint4 *ccl;
187 1.1.1.1.2.2 yamt static ac_uint4 ccl_used;
188 1.1.1.1.2.2 yamt static ac_uint4 ccl_size;
189 1.1.1.1.2.2 yamt
190 1.1.1.1.2.2 yamt /*
191 1.1.1.1.2.2 yamt * Structures for handling numbers.
192 1.1.1.1.2.2 yamt */
193 1.1.1.1.2.2 yamt typedef struct {
194 1.1.1.1.2.2 yamt ac_uint4 code;
195 1.1.1.1.2.2 yamt ac_uint4 idx;
196 1.1.1.1.2.2 yamt } _codeidx_t;
197 1.1.1.1.2.2 yamt
198 1.1.1.1.2.2 yamt typedef struct {
199 1.1.1.1.2.2 yamt short numerator;
200 1.1.1.1.2.2 yamt short denominator;
201 1.1.1.1.2.2 yamt } _num_t;
202 1.1.1.1.2.2 yamt
203 1.1.1.1.2.2 yamt /*
204 1.1.1.1.2.2 yamt * Arrays to hold the mapping of codes to numbers.
205 1.1.1.1.2.2 yamt */
206 1.1.1.1.2.2 yamt static _codeidx_t *ncodes;
207 1.1.1.1.2.2 yamt static ac_uint4 ncodes_used;
208 1.1.1.1.2.2 yamt static ac_uint4 ncodes_size;
209 1.1.1.1.2.2 yamt
210 1.1.1.1.2.2 yamt static _num_t *nums;
211 1.1.1.1.2.2 yamt static ac_uint4 nums_used;
212 1.1.1.1.2.2 yamt static ac_uint4 nums_size;
213 1.1.1.1.2.2 yamt
214 1.1.1.1.2.2 yamt /*
215 1.1.1.1.2.2 yamt * Array for holding numbers.
216 1.1.1.1.2.2 yamt */
217 1.1.1.1.2.2 yamt static _num_t *nums;
218 1.1.1.1.2.2 yamt static ac_uint4 nums_used;
219 1.1.1.1.2.2 yamt static ac_uint4 nums_size;
220 1.1.1.1.2.2 yamt
221 1.1.1.1.2.2 yamt static void
222 1.1.1.1.2.2 yamt add_range(ac_uint4 start, ac_uint4 end, char *p1, char *p2)
223 1.1.1.1.2.2 yamt {
224 1.1.1.1.2.2 yamt int i, j, k, len;
225 1.1.1.1.2.2 yamt _ranges_t *rlp;
226 1.1.1.1.2.2 yamt char *name;
227 1.1.1.1.2.2 yamt
228 1.1.1.1.2.2 yamt for (k = 0; k < 2; k++) {
229 1.1.1.1.2.2 yamt if (k == 0) {
230 1.1.1.1.2.2 yamt name = p1;
231 1.1.1.1.2.2 yamt len = 2;
232 1.1.1.1.2.2 yamt } else {
233 1.1.1.1.2.2 yamt if (p2 == 0)
234 1.1.1.1.2.2 yamt break;
235 1.1.1.1.2.2 yamt
236 1.1.1.1.2.2 yamt name = p2;
237 1.1.1.1.2.2 yamt len = 1;
238 1.1.1.1.2.2 yamt }
239 1.1.1.1.2.2 yamt
240 1.1.1.1.2.2 yamt for (i = 0; i < NUMPROPS; i++) {
241 1.1.1.1.2.2 yamt if (props[i].len == len && memcmp(props[i].name, name, len) == 0)
242 1.1.1.1.2.2 yamt break;
243 1.1.1.1.2.2 yamt }
244 1.1.1.1.2.2 yamt
245 1.1.1.1.2.2 yamt if (i == NUMPROPS)
246 1.1.1.1.2.2 yamt continue;
247 1.1.1.1.2.2 yamt
248 1.1.1.1.2.2 yamt rlp = &proptbl[i];
249 1.1.1.1.2.2 yamt
250 1.1.1.1.2.2 yamt /*
251 1.1.1.1.2.2 yamt * Resize the range list if necessary.
252 1.1.1.1.2.2 yamt */
253 1.1.1.1.2.2 yamt if (rlp->used == rlp->size) {
254 1.1.1.1.2.2 yamt if (rlp->size == 0)
255 1.1.1.1.2.2 yamt rlp->ranges = (ac_uint4 *)
256 1.1.1.1.2.2 yamt malloc(sizeof(ac_uint4) << 3);
257 1.1.1.1.2.2 yamt else
258 1.1.1.1.2.2 yamt rlp->ranges = (ac_uint4 *)
259 1.1.1.1.2.2 yamt realloc((char *) rlp->ranges,
260 1.1.1.1.2.2 yamt sizeof(ac_uint4) * (rlp->size + 8));
261 1.1.1.1.2.2 yamt rlp->size += 8;
262 1.1.1.1.2.2 yamt }
263 1.1.1.1.2.2 yamt
264 1.1.1.1.2.2 yamt /*
265 1.1.1.1.2.2 yamt * If this is the first code for this property list, just add it
266 1.1.1.1.2.2 yamt * and return.
267 1.1.1.1.2.2 yamt */
268 1.1.1.1.2.2 yamt if (rlp->used == 0) {
269 1.1.1.1.2.2 yamt rlp->ranges[0] = start;
270 1.1.1.1.2.2 yamt rlp->ranges[1] = end;
271 1.1.1.1.2.2 yamt rlp->used += 2;
272 1.1.1.1.2.2 yamt continue;
273 1.1.1.1.2.2 yamt }
274 1.1.1.1.2.2 yamt
275 1.1.1.1.2.2 yamt /*
276 1.1.1.1.2.2 yamt * Optimize the case of adding the range to the end.
277 1.1.1.1.2.2 yamt */
278 1.1.1.1.2.2 yamt j = rlp->used - 1;
279 1.1.1.1.2.2 yamt if (start > rlp->ranges[j]) {
280 1.1.1.1.2.2 yamt j = rlp->used;
281 1.1.1.1.2.2 yamt rlp->ranges[j++] = start;
282 1.1.1.1.2.2 yamt rlp->ranges[j++] = end;
283 1.1.1.1.2.2 yamt rlp->used = j;
284 1.1.1.1.2.2 yamt continue;
285 1.1.1.1.2.2 yamt }
286 1.1.1.1.2.2 yamt
287 1.1.1.1.2.2 yamt /*
288 1.1.1.1.2.2 yamt * Need to locate the insertion point.
289 1.1.1.1.2.2 yamt */
290 1.1.1.1.2.2 yamt for (i = 0;
291 1.1.1.1.2.2 yamt i < rlp->used && start > rlp->ranges[i + 1] + 1; i += 2) ;
292 1.1.1.1.2.2 yamt
293 1.1.1.1.2.2 yamt /*
294 1.1.1.1.2.2 yamt * If the start value lies in the current range, then simply set the
295 1.1.1.1.2.2 yamt * new end point of the range to the end value passed as a parameter.
296 1.1.1.1.2.2 yamt */
297 1.1.1.1.2.2 yamt if (rlp->ranges[i] <= start && start <= rlp->ranges[i + 1] + 1) {
298 1.1.1.1.2.2 yamt rlp->ranges[i + 1] = end;
299 1.1.1.1.2.2 yamt return;
300 1.1.1.1.2.2 yamt }
301 1.1.1.1.2.2 yamt
302 1.1.1.1.2.2 yamt /*
303 1.1.1.1.2.2 yamt * Shift following values up by two.
304 1.1.1.1.2.2 yamt */
305 1.1.1.1.2.2 yamt for (j = rlp->used; j > i; j -= 2) {
306 1.1.1.1.2.2 yamt rlp->ranges[j] = rlp->ranges[j - 2];
307 1.1.1.1.2.2 yamt rlp->ranges[j + 1] = rlp->ranges[j - 1];
308 1.1.1.1.2.2 yamt }
309 1.1.1.1.2.2 yamt
310 1.1.1.1.2.2 yamt /*
311 1.1.1.1.2.2 yamt * Add the new range at the insertion point.
312 1.1.1.1.2.2 yamt */
313 1.1.1.1.2.2 yamt rlp->ranges[i] = start;
314 1.1.1.1.2.2 yamt rlp->ranges[i + 1] = end;
315 1.1.1.1.2.2 yamt rlp->used += 2;
316 1.1.1.1.2.2 yamt }
317 1.1.1.1.2.2 yamt }
318 1.1.1.1.2.2 yamt
319 1.1.1.1.2.2 yamt static void
320 1.1.1.1.2.2 yamt ordered_range_insert(ac_uint4 c, char *name, int len)
321 1.1.1.1.2.2 yamt {
322 1.1.1.1.2.2 yamt int i, j;
323 1.1.1.1.2.2 yamt ac_uint4 s, e;
324 1.1.1.1.2.2 yamt _ranges_t *rlp;
325 1.1.1.1.2.2 yamt
326 1.1.1.1.2.2 yamt if (len == 0)
327 1.1.1.1.2.2 yamt return;
328 1.1.1.1.2.2 yamt
329 1.1.1.1.2.2 yamt /*
330 1.1.1.1.2.2 yamt * Deal with directionality codes introduced in Unicode 3.0.
331 1.1.1.1.2.2 yamt */
332 1.1.1.1.2.2 yamt if ((len == 2 && memcmp(name, "BN", 2) == 0) ||
333 1.1.1.1.2.2 yamt (len == 3 &&
334 1.1.1.1.2.2 yamt (memcmp(name, "NSM", 3) == 0 || memcmp(name, "PDF", 3) == 0 ||
335 1.1.1.1.2.2 yamt memcmp(name, "LRE", 3) == 0 || memcmp(name, "LRO", 3) == 0 ||
336 1.1.1.1.2.2 yamt memcmp(name, "RLE", 3) == 0 || memcmp(name, "RLO", 3) == 0))) {
337 1.1.1.1.2.2 yamt /*
338 1.1.1.1.2.2 yamt * Mark all of these as Other Neutral to preserve compatibility with
339 1.1.1.1.2.2 yamt * older versions.
340 1.1.1.1.2.2 yamt */
341 1.1.1.1.2.2 yamt len = 2;
342 1.1.1.1.2.2 yamt name = "ON";
343 1.1.1.1.2.2 yamt }
344 1.1.1.1.2.2 yamt
345 1.1.1.1.2.2 yamt for (i = 0; i < NUMPROPS; i++) {
346 1.1.1.1.2.2 yamt if (props[i].len == len && memcmp(props[i].name, name, len) == 0)
347 1.1.1.1.2.2 yamt break;
348 1.1.1.1.2.2 yamt }
349 1.1.1.1.2.2 yamt
350 1.1.1.1.2.2 yamt if (i == NUMPROPS)
351 1.1.1.1.2.2 yamt return;
352 1.1.1.1.2.2 yamt
353 1.1.1.1.2.2 yamt /*
354 1.1.1.1.2.2 yamt * Have a match, so insert the code in order.
355 1.1.1.1.2.2 yamt */
356 1.1.1.1.2.2 yamt rlp = &proptbl[i];
357 1.1.1.1.2.2 yamt
358 1.1.1.1.2.2 yamt /*
359 1.1.1.1.2.2 yamt * Resize the range list if necessary.
360 1.1.1.1.2.2 yamt */
361 1.1.1.1.2.2 yamt if (rlp->used == rlp->size) {
362 1.1.1.1.2.2 yamt if (rlp->size == 0)
363 1.1.1.1.2.2 yamt rlp->ranges = (ac_uint4 *)
364 1.1.1.1.2.2 yamt malloc(sizeof(ac_uint4) << 3);
365 1.1.1.1.2.2 yamt else
366 1.1.1.1.2.2 yamt rlp->ranges = (ac_uint4 *)
367 1.1.1.1.2.2 yamt realloc((char *) rlp->ranges,
368 1.1.1.1.2.2 yamt sizeof(ac_uint4) * (rlp->size + 8));
369 1.1.1.1.2.2 yamt rlp->size += 8;
370 1.1.1.1.2.2 yamt }
371 1.1.1.1.2.2 yamt
372 1.1.1.1.2.2 yamt /*
373 1.1.1.1.2.2 yamt * If this is the first code for this property list, just add it
374 1.1.1.1.2.2 yamt * and return.
375 1.1.1.1.2.2 yamt */
376 1.1.1.1.2.2 yamt if (rlp->used == 0) {
377 1.1.1.1.2.2 yamt rlp->ranges[0] = rlp->ranges[1] = c;
378 1.1.1.1.2.2 yamt rlp->used += 2;
379 1.1.1.1.2.2 yamt return;
380 1.1.1.1.2.2 yamt }
381 1.1.1.1.2.2 yamt
382 1.1.1.1.2.2 yamt /*
383 1.1.1.1.2.2 yamt * Optimize the cases of extending the last range and adding new ranges to
384 1.1.1.1.2.2 yamt * the end.
385 1.1.1.1.2.2 yamt */
386 1.1.1.1.2.2 yamt j = rlp->used - 1;
387 1.1.1.1.2.2 yamt e = rlp->ranges[j];
388 1.1.1.1.2.2 yamt s = rlp->ranges[j - 1];
389 1.1.1.1.2.2 yamt
390 1.1.1.1.2.2 yamt if (c == e + 1) {
391 1.1.1.1.2.2 yamt /*
392 1.1.1.1.2.2 yamt * Extend the last range.
393 1.1.1.1.2.2 yamt */
394 1.1.1.1.2.2 yamt rlp->ranges[j] = c;
395 1.1.1.1.2.2 yamt return;
396 1.1.1.1.2.2 yamt }
397 1.1.1.1.2.2 yamt
398 1.1.1.1.2.2 yamt if (c > e + 1) {
399 1.1.1.1.2.2 yamt /*
400 1.1.1.1.2.2 yamt * Start another range on the end.
401 1.1.1.1.2.2 yamt */
402 1.1.1.1.2.2 yamt j = rlp->used;
403 1.1.1.1.2.2 yamt rlp->ranges[j] = rlp->ranges[j + 1] = c;
404 1.1.1.1.2.2 yamt rlp->used += 2;
405 1.1.1.1.2.2 yamt return;
406 1.1.1.1.2.2 yamt }
407 1.1.1.1.2.2 yamt
408 1.1.1.1.2.2 yamt if (c >= s)
409 1.1.1.1.2.2 yamt /*
410 1.1.1.1.2.2 yamt * The code is a duplicate of a code in the last range, so just return.
411 1.1.1.1.2.2 yamt */
412 1.1.1.1.2.2 yamt return;
413 1.1.1.1.2.2 yamt
414 1.1.1.1.2.2 yamt /*
415 1.1.1.1.2.2 yamt * The code should be inserted somewhere before the last range in the
416 1.1.1.1.2.2 yamt * list. Locate the insertion point.
417 1.1.1.1.2.2 yamt */
418 1.1.1.1.2.2 yamt for (i = 0;
419 1.1.1.1.2.2 yamt i < rlp->used && c > rlp->ranges[i + 1] + 1; i += 2) ;
420 1.1.1.1.2.2 yamt
421 1.1.1.1.2.2 yamt s = rlp->ranges[i];
422 1.1.1.1.2.2 yamt e = rlp->ranges[i + 1];
423 1.1.1.1.2.2 yamt
424 1.1.1.1.2.2 yamt if (c == e + 1)
425 1.1.1.1.2.2 yamt /*
426 1.1.1.1.2.2 yamt * Simply extend the current range.
427 1.1.1.1.2.2 yamt */
428 1.1.1.1.2.2 yamt rlp->ranges[i + 1] = c;
429 1.1.1.1.2.2 yamt else if (c < s) {
430 1.1.1.1.2.2 yamt /*
431 1.1.1.1.2.2 yamt * Add a new entry before the current location. Shift all entries
432 1.1.1.1.2.2 yamt * before the current one up by one to make room.
433 1.1.1.1.2.2 yamt */
434 1.1.1.1.2.2 yamt for (j = rlp->used; j > i; j -= 2) {
435 1.1.1.1.2.2 yamt rlp->ranges[j] = rlp->ranges[j - 2];
436 1.1.1.1.2.2 yamt rlp->ranges[j + 1] = rlp->ranges[j - 1];
437 1.1.1.1.2.2 yamt }
438 1.1.1.1.2.2 yamt rlp->ranges[i] = rlp->ranges[i + 1] = c;
439 1.1.1.1.2.2 yamt
440 1.1.1.1.2.2 yamt rlp->used += 2;
441 1.1.1.1.2.2 yamt }
442 1.1.1.1.2.2 yamt }
443 1.1.1.1.2.2 yamt
444 1.1.1.1.2.2 yamt static void
445 1.1.1.1.2.2 yamt add_decomp(ac_uint4 code, short compat)
446 1.1.1.1.2.2 yamt {
447 1.1.1.1.2.2 yamt ac_uint4 i, j, size;
448 1.1.1.1.2.2 yamt _decomp_t **pdecomps;
449 1.1.1.1.2.2 yamt ac_uint4 *pdecomps_used;
450 1.1.1.1.2.2 yamt ac_uint4 *pdecomps_size;
451 1.1.1.1.2.2 yamt
452 1.1.1.1.2.2 yamt if (compat) {
453 1.1.1.1.2.2 yamt pdecomps = &kdecomps;
454 1.1.1.1.2.2 yamt pdecomps_used = &kdecomps_used;
455 1.1.1.1.2.2 yamt pdecomps_size = &kdecomps_size;
456 1.1.1.1.2.2 yamt } else {
457 1.1.1.1.2.2 yamt pdecomps = &decomps;
458 1.1.1.1.2.2 yamt pdecomps_used = &decomps_used;
459 1.1.1.1.2.2 yamt pdecomps_size = &decomps_size;
460 1.1.1.1.2.2 yamt }
461 1.1.1.1.2.2 yamt
462 1.1.1.1.2.2 yamt /*
463 1.1.1.1.2.2 yamt * Add the code to the composite property.
464 1.1.1.1.2.2 yamt */
465 1.1.1.1.2.2 yamt if (!compat) {
466 1.1.1.1.2.2 yamt ordered_range_insert(code, "Cm", 2);
467 1.1.1.1.2.2 yamt }
468 1.1.1.1.2.2 yamt
469 1.1.1.1.2.2 yamt /*
470 1.1.1.1.2.2 yamt * Locate the insertion point for the code.
471 1.1.1.1.2.2 yamt */
472 1.1.1.1.2.2 yamt for (i = 0; i < *pdecomps_used && code > (*pdecomps)[i].code; i++) ;
473 1.1.1.1.2.2 yamt
474 1.1.1.1.2.2 yamt /*
475 1.1.1.1.2.2 yamt * Allocate space for a new decomposition.
476 1.1.1.1.2.2 yamt */
477 1.1.1.1.2.2 yamt if (*pdecomps_used == *pdecomps_size) {
478 1.1.1.1.2.2 yamt if (*pdecomps_size == 0)
479 1.1.1.1.2.2 yamt *pdecomps = (_decomp_t *) malloc(sizeof(_decomp_t) << 3);
480 1.1.1.1.2.2 yamt else
481 1.1.1.1.2.2 yamt *pdecomps = (_decomp_t *)
482 1.1.1.1.2.2 yamt realloc((char *) *pdecomps,
483 1.1.1.1.2.2 yamt sizeof(_decomp_t) * (*pdecomps_size + 8));
484 1.1.1.1.2.2 yamt (void) memset((char *) (*pdecomps + *pdecomps_size), '\0',
485 1.1.1.1.2.2 yamt sizeof(_decomp_t) << 3);
486 1.1.1.1.2.2 yamt *pdecomps_size += 8;
487 1.1.1.1.2.2 yamt }
488 1.1.1.1.2.2 yamt
489 1.1.1.1.2.2 yamt if (i < *pdecomps_used && code != (*pdecomps)[i].code) {
490 1.1.1.1.2.2 yamt /*
491 1.1.1.1.2.2 yamt * Shift the decomps up by one if the codes don't match.
492 1.1.1.1.2.2 yamt */
493 1.1.1.1.2.2 yamt for (j = *pdecomps_used; j > i; j--)
494 1.1.1.1.2.2 yamt (void) AC_MEMCPY((char *) &(*pdecomps)[j], (char *) &(*pdecomps)[j - 1],
495 1.1.1.1.2.2 yamt sizeof(_decomp_t));
496 1.1.1.1.2.2 yamt }
497 1.1.1.1.2.2 yamt
498 1.1.1.1.2.2 yamt /*
499 1.1.1.1.2.2 yamt * Insert or replace a decomposition.
500 1.1.1.1.2.2 yamt */
501 1.1.1.1.2.2 yamt size = dectmp_size + (4 - (dectmp_size & 3));
502 1.1.1.1.2.2 yamt if ((*pdecomps)[i].size < size) {
503 1.1.1.1.2.2 yamt if ((*pdecomps)[i].size == 0)
504 1.1.1.1.2.2 yamt (*pdecomps)[i].decomp = (ac_uint4 *)
505 1.1.1.1.2.2 yamt malloc(sizeof(ac_uint4) * size);
506 1.1.1.1.2.2 yamt else
507 1.1.1.1.2.2 yamt (*pdecomps)[i].decomp = (ac_uint4 *)
508 1.1.1.1.2.2 yamt realloc((char *) (*pdecomps)[i].decomp,
509 1.1.1.1.2.2 yamt sizeof(ac_uint4) * size);
510 1.1.1.1.2.2 yamt (*pdecomps)[i].size = size;
511 1.1.1.1.2.2 yamt }
512 1.1.1.1.2.2 yamt
513 1.1.1.1.2.2 yamt if ((*pdecomps)[i].code != code)
514 1.1.1.1.2.2 yamt (*pdecomps_used)++;
515 1.1.1.1.2.2 yamt
516 1.1.1.1.2.2 yamt (*pdecomps)[i].code = code;
517 1.1.1.1.2.2 yamt (*pdecomps)[i].used = dectmp_size;
518 1.1.1.1.2.2 yamt (void) AC_MEMCPY((char *) (*pdecomps)[i].decomp, (char *) dectmp,
519 1.1.1.1.2.2 yamt sizeof(ac_uint4) * dectmp_size);
520 1.1.1.1.2.2 yamt
521 1.1.1.1.2.2 yamt /*
522 1.1.1.1.2.2 yamt * NOTICE: This needs changing later so it is more general than simply
523 1.1.1.1.2.2 yamt * pairs. This calculation is done here to simplify allocation elsewhere.
524 1.1.1.1.2.2 yamt */
525 1.1.1.1.2.2 yamt if (!compat && dectmp_size == 2)
526 1.1.1.1.2.2 yamt comps_used++;
527 1.1.1.1.2.2 yamt }
528 1.1.1.1.2.2 yamt
529 1.1.1.1.2.2 yamt static void
530 1.1.1.1.2.2 yamt add_title(ac_uint4 code)
531 1.1.1.1.2.2 yamt {
532 1.1.1.1.2.2 yamt ac_uint4 i, j;
533 1.1.1.1.2.2 yamt
534 1.1.1.1.2.2 yamt /*
535 1.1.1.1.2.2 yamt * Always map the code to itself.
536 1.1.1.1.2.2 yamt */
537 1.1.1.1.2.2 yamt cases[2] = code;
538 1.1.1.1.2.2 yamt
539 1.1.1.1.2.2 yamt if (title_used == title_size) {
540 1.1.1.1.2.2 yamt if (title_size == 0)
541 1.1.1.1.2.2 yamt title = (_case_t *) malloc(sizeof(_case_t) << 3);
542 1.1.1.1.2.2 yamt else
543 1.1.1.1.2.2 yamt title = (_case_t *) realloc((char *) title,
544 1.1.1.1.2.2 yamt sizeof(_case_t) * (title_size + 8));
545 1.1.1.1.2.2 yamt title_size += 8;
546 1.1.1.1.2.2 yamt }
547 1.1.1.1.2.2 yamt
548 1.1.1.1.2.2 yamt /*
549 1.1.1.1.2.2 yamt * Locate the insertion point.
550 1.1.1.1.2.2 yamt */
551 1.1.1.1.2.2 yamt for (i = 0; i < title_used && code > title[i].key; i++) ;
552 1.1.1.1.2.2 yamt
553 1.1.1.1.2.2 yamt if (i < title_used) {
554 1.1.1.1.2.2 yamt /*
555 1.1.1.1.2.2 yamt * Shift the array up by one.
556 1.1.1.1.2.2 yamt */
557 1.1.1.1.2.2 yamt for (j = title_used; j > i; j--)
558 1.1.1.1.2.2 yamt (void) AC_MEMCPY((char *) &title[j], (char *) &title[j - 1],
559 1.1.1.1.2.2 yamt sizeof(_case_t));
560 1.1.1.1.2.2 yamt }
561 1.1.1.1.2.2 yamt
562 1.1.1.1.2.2 yamt title[i].key = cases[2]; /* Title */
563 1.1.1.1.2.2 yamt title[i].other1 = cases[0]; /* Upper */
564 1.1.1.1.2.2 yamt title[i].other2 = cases[1]; /* Lower */
565 1.1.1.1.2.2 yamt
566 1.1.1.1.2.2 yamt title_used++;
567 1.1.1.1.2.2 yamt }
568 1.1.1.1.2.2 yamt
569 1.1.1.1.2.2 yamt static void
570 1.1.1.1.2.2 yamt add_upper(ac_uint4 code)
571 1.1.1.1.2.2 yamt {
572 1.1.1.1.2.2 yamt ac_uint4 i, j;
573 1.1.1.1.2.2 yamt
574 1.1.1.1.2.2 yamt /*
575 1.1.1.1.2.2 yamt * Always map the code to itself.
576 1.1.1.1.2.2 yamt */
577 1.1.1.1.2.2 yamt cases[0] = code;
578 1.1.1.1.2.2 yamt
579 1.1.1.1.2.2 yamt /*
580 1.1.1.1.2.2 yamt * If the title case character is not present, then make it the same as
581 1.1.1.1.2.2 yamt * the upper case.
582 1.1.1.1.2.2 yamt */
583 1.1.1.1.2.2 yamt if (cases[2] == 0)
584 1.1.1.1.2.2 yamt cases[2] = code;
585 1.1.1.1.2.2 yamt
586 1.1.1.1.2.2 yamt if (upper_used == upper_size) {
587 1.1.1.1.2.2 yamt if (upper_size == 0)
588 1.1.1.1.2.2 yamt upper = (_case_t *) malloc(sizeof(_case_t) << 3);
589 1.1.1.1.2.2 yamt else
590 1.1.1.1.2.2 yamt upper = (_case_t *) realloc((char *) upper,
591 1.1.1.1.2.2 yamt sizeof(_case_t) * (upper_size + 8));
592 1.1.1.1.2.2 yamt upper_size += 8;
593 1.1.1.1.2.2 yamt }
594 1.1.1.1.2.2 yamt
595 1.1.1.1.2.2 yamt /*
596 1.1.1.1.2.2 yamt * Locate the insertion point.
597 1.1.1.1.2.2 yamt */
598 1.1.1.1.2.2 yamt for (i = 0; i < upper_used && code > upper[i].key; i++) ;
599 1.1.1.1.2.2 yamt
600 1.1.1.1.2.2 yamt if (i < upper_used) {
601 1.1.1.1.2.2 yamt /*
602 1.1.1.1.2.2 yamt * Shift the array up by one.
603 1.1.1.1.2.2 yamt */
604 1.1.1.1.2.2 yamt for (j = upper_used; j > i; j--)
605 1.1.1.1.2.2 yamt (void) AC_MEMCPY((char *) &upper[j], (char *) &upper[j - 1],
606 1.1.1.1.2.2 yamt sizeof(_case_t));
607 1.1.1.1.2.2 yamt }
608 1.1.1.1.2.2 yamt
609 1.1.1.1.2.2 yamt upper[i].key = cases[0]; /* Upper */
610 1.1.1.1.2.2 yamt upper[i].other1 = cases[1]; /* Lower */
611 1.1.1.1.2.2 yamt upper[i].other2 = cases[2]; /* Title */
612 1.1.1.1.2.2 yamt
613 1.1.1.1.2.2 yamt upper_used++;
614 1.1.1.1.2.2 yamt }
615 1.1.1.1.2.2 yamt
616 1.1.1.1.2.2 yamt static void
617 1.1.1.1.2.2 yamt add_lower(ac_uint4 code)
618 1.1.1.1.2.2 yamt {
619 1.1.1.1.2.2 yamt ac_uint4 i, j;
620 1.1.1.1.2.2 yamt
621 1.1.1.1.2.2 yamt /*
622 1.1.1.1.2.2 yamt * Always map the code to itself.
623 1.1.1.1.2.2 yamt */
624 1.1.1.1.2.2 yamt cases[1] = code;
625 1.1.1.1.2.2 yamt
626 1.1.1.1.2.2 yamt /*
627 1.1.1.1.2.2 yamt * If the title case character is empty, then make it the same as the
628 1.1.1.1.2.2 yamt * upper case.
629 1.1.1.1.2.2 yamt */
630 1.1.1.1.2.2 yamt if (cases[2] == 0)
631 1.1.1.1.2.2 yamt cases[2] = cases[0];
632 1.1.1.1.2.2 yamt
633 1.1.1.1.2.2 yamt if (lower_used == lower_size) {
634 1.1.1.1.2.2 yamt if (lower_size == 0)
635 1.1.1.1.2.2 yamt lower = (_case_t *) malloc(sizeof(_case_t) << 3);
636 1.1.1.1.2.2 yamt else
637 1.1.1.1.2.2 yamt lower = (_case_t *) realloc((char *) lower,
638 1.1.1.1.2.2 yamt sizeof(_case_t) * (lower_size + 8));
639 1.1.1.1.2.2 yamt lower_size += 8;
640 1.1.1.1.2.2 yamt }
641 1.1.1.1.2.2 yamt
642 1.1.1.1.2.2 yamt /*
643 1.1.1.1.2.2 yamt * Locate the insertion point.
644 1.1.1.1.2.2 yamt */
645 1.1.1.1.2.2 yamt for (i = 0; i < lower_used && code > lower[i].key; i++) ;
646 1.1.1.1.2.2 yamt
647 1.1.1.1.2.2 yamt if (i < lower_used) {
648 1.1.1.1.2.2 yamt /*
649 1.1.1.1.2.2 yamt * Shift the array up by one.
650 1.1.1.1.2.2 yamt */
651 1.1.1.1.2.2 yamt for (j = lower_used; j > i; j--)
652 1.1.1.1.2.2 yamt (void) AC_MEMCPY((char *) &lower[j], (char *) &lower[j - 1],
653 1.1.1.1.2.2 yamt sizeof(_case_t));
654 1.1.1.1.2.2 yamt }
655 1.1.1.1.2.2 yamt
656 1.1.1.1.2.2 yamt lower[i].key = cases[1]; /* Lower */
657 1.1.1.1.2.2 yamt lower[i].other1 = cases[0]; /* Upper */
658 1.1.1.1.2.2 yamt lower[i].other2 = cases[2]; /* Title */
659 1.1.1.1.2.2 yamt
660 1.1.1.1.2.2 yamt lower_used++;
661 1.1.1.1.2.2 yamt }
662 1.1.1.1.2.2 yamt
663 1.1.1.1.2.2 yamt static void
664 1.1.1.1.2.2 yamt ordered_ccl_insert(ac_uint4 c, ac_uint4 ccl_code)
665 1.1.1.1.2.2 yamt {
666 1.1.1.1.2.2 yamt ac_uint4 i, j;
667 1.1.1.1.2.2 yamt
668 1.1.1.1.2.2 yamt if (ccl_used == ccl_size) {
669 1.1.1.1.2.2 yamt if (ccl_size == 0)
670 1.1.1.1.2.2 yamt ccl = (ac_uint4 *) malloc(sizeof(ac_uint4) * 24);
671 1.1.1.1.2.2 yamt else
672 1.1.1.1.2.2 yamt ccl = (ac_uint4 *)
673 1.1.1.1.2.2 yamt realloc((char *) ccl, sizeof(ac_uint4) * (ccl_size + 24));
674 1.1.1.1.2.2 yamt ccl_size += 24;
675 1.1.1.1.2.2 yamt }
676 1.1.1.1.2.2 yamt
677 1.1.1.1.2.2 yamt /*
678 1.1.1.1.2.2 yamt * Optimize adding the first item.
679 1.1.1.1.2.2 yamt */
680 1.1.1.1.2.2 yamt if (ccl_used == 0) {
681 1.1.1.1.2.2 yamt ccl[0] = ccl[1] = c;
682 1.1.1.1.2.2 yamt ccl[2] = ccl_code;
683 1.1.1.1.2.2 yamt ccl_used += 3;
684 1.1.1.1.2.2 yamt return;
685 1.1.1.1.2.2 yamt }
686 1.1.1.1.2.2 yamt
687 1.1.1.1.2.2 yamt /*
688 1.1.1.1.2.2 yamt * Handle the special case of extending the range on the end. This
689 1.1.1.1.2.2 yamt * requires that the combining class codes are the same.
690 1.1.1.1.2.2 yamt */
691 1.1.1.1.2.2 yamt if (ccl_code == ccl[ccl_used - 1] && c == ccl[ccl_used - 2] + 1) {
692 1.1.1.1.2.2 yamt ccl[ccl_used - 2] = c;
693 1.1.1.1.2.2 yamt return;
694 1.1.1.1.2.2 yamt }
695 1.1.1.1.2.2 yamt
696 1.1.1.1.2.2 yamt /*
697 1.1.1.1.2.2 yamt * Handle the special case of adding another range on the end.
698 1.1.1.1.2.2 yamt */
699 1.1.1.1.2.2 yamt if (c > ccl[ccl_used - 2] + 1 ||
700 1.1.1.1.2.2 yamt (c == ccl[ccl_used - 2] + 1 && ccl_code != ccl[ccl_used - 1])) {
701 1.1.1.1.2.2 yamt ccl[ccl_used++] = c;
702 1.1.1.1.2.2 yamt ccl[ccl_used++] = c;
703 1.1.1.1.2.2 yamt ccl[ccl_used++] = ccl_code;
704 1.1.1.1.2.2 yamt return;
705 1.1.1.1.2.2 yamt }
706 1.1.1.1.2.2 yamt
707 1.1.1.1.2.2 yamt /*
708 1.1.1.1.2.2 yamt * Locate either the insertion point or range for the code.
709 1.1.1.1.2.2 yamt */
710 1.1.1.1.2.2 yamt for (i = 0; i < ccl_used && c > ccl[i + 1] + 1; i += 3) ;
711 1.1.1.1.2.2 yamt
712 1.1.1.1.2.2 yamt if (ccl_code == ccl[i + 2] && c == ccl[i + 1] + 1) {
713 1.1.1.1.2.2 yamt /*
714 1.1.1.1.2.2 yamt * Extend an existing range.
715 1.1.1.1.2.2 yamt */
716 1.1.1.1.2.2 yamt ccl[i + 1] = c;
717 1.1.1.1.2.2 yamt return;
718 1.1.1.1.2.2 yamt } else if (c < ccl[i]) {
719 1.1.1.1.2.2 yamt /*
720 1.1.1.1.2.2 yamt * Start a new range before the current location.
721 1.1.1.1.2.2 yamt */
722 1.1.1.1.2.2 yamt for (j = ccl_used; j > i; j -= 3) {
723 1.1.1.1.2.2 yamt ccl[j] = ccl[j - 3];
724 1.1.1.1.2.2 yamt ccl[j - 1] = ccl[j - 4];
725 1.1.1.1.2.2 yamt ccl[j - 2] = ccl[j - 5];
726 1.1.1.1.2.2 yamt }
727 1.1.1.1.2.2 yamt ccl[i] = ccl[i + 1] = c;
728 1.1.1.1.2.2 yamt ccl[i + 2] = ccl_code;
729 1.1.1.1.2.2 yamt }
730 1.1.1.1.2.2 yamt }
731 1.1.1.1.2.2 yamt
732 1.1.1.1.2.2 yamt /*
733 1.1.1.1.2.2 yamt * Adds a number if it does not already exist and returns an index value
734 1.1.1.1.2.2 yamt * multiplied by 2.
735 1.1.1.1.2.2 yamt */
736 1.1.1.1.2.2 yamt static ac_uint4
737 1.1.1.1.2.2 yamt make_number(short num, short denom)
738 1.1.1.1.2.2 yamt {
739 1.1.1.1.2.2 yamt ac_uint4 n;
740 1.1.1.1.2.2 yamt
741 1.1.1.1.2.2 yamt /*
742 1.1.1.1.2.2 yamt * Determine if the number already exists.
743 1.1.1.1.2.2 yamt */
744 1.1.1.1.2.2 yamt for (n = 0; n < nums_used; n++) {
745 1.1.1.1.2.2 yamt if (nums[n].numerator == num && nums[n].denominator == denom)
746 1.1.1.1.2.2 yamt return n << 1;
747 1.1.1.1.2.2 yamt }
748 1.1.1.1.2.2 yamt
749 1.1.1.1.2.2 yamt if (nums_used == nums_size) {
750 1.1.1.1.2.2 yamt if (nums_size == 0)
751 1.1.1.1.2.2 yamt nums = (_num_t *) malloc(sizeof(_num_t) << 3);
752 1.1.1.1.2.2 yamt else
753 1.1.1.1.2.2 yamt nums = (_num_t *) realloc((char *) nums,
754 1.1.1.1.2.2 yamt sizeof(_num_t) * (nums_size + 8));
755 1.1.1.1.2.2 yamt nums_size += 8;
756 1.1.1.1.2.2 yamt }
757 1.1.1.1.2.2 yamt
758 1.1.1.1.2.2 yamt n = nums_used++;
759 1.1.1.1.2.2 yamt nums[n].numerator = num;
760 1.1.1.1.2.2 yamt nums[n].denominator = denom;
761 1.1.1.1.2.2 yamt
762 1.1.1.1.2.2 yamt return n << 1;
763 1.1.1.1.2.2 yamt }
764 1.1.1.1.2.2 yamt
765 1.1.1.1.2.2 yamt static void
766 1.1.1.1.2.2 yamt add_number(ac_uint4 code, short num, short denom)
767 1.1.1.1.2.2 yamt {
768 1.1.1.1.2.2 yamt ac_uint4 i, j;
769 1.1.1.1.2.2 yamt
770 1.1.1.1.2.2 yamt /*
771 1.1.1.1.2.2 yamt * Insert the code in order.
772 1.1.1.1.2.2 yamt */
773 1.1.1.1.2.2 yamt for (i = 0; i < ncodes_used && code > ncodes[i].code; i++) ;
774 1.1.1.1.2.2 yamt
775 1.1.1.1.2.2 yamt /*
776 1.1.1.1.2.2 yamt * Handle the case of the codes matching and simply replace the number
777 1.1.1.1.2.2 yamt * that was there before.
778 1.1.1.1.2.2 yamt */
779 1.1.1.1.2.2 yamt if (i < ncodes_used && code == ncodes[i].code) {
780 1.1.1.1.2.2 yamt ncodes[i].idx = make_number(num, denom);
781 1.1.1.1.2.2 yamt return;
782 1.1.1.1.2.2 yamt }
783 1.1.1.1.2.2 yamt
784 1.1.1.1.2.2 yamt /*
785 1.1.1.1.2.2 yamt * Resize the array if necessary.
786 1.1.1.1.2.2 yamt */
787 1.1.1.1.2.2 yamt if (ncodes_used == ncodes_size) {
788 1.1.1.1.2.2 yamt if (ncodes_size == 0)
789 1.1.1.1.2.2 yamt ncodes = (_codeidx_t *) malloc(sizeof(_codeidx_t) << 3);
790 1.1.1.1.2.2 yamt else
791 1.1.1.1.2.2 yamt ncodes = (_codeidx_t *)
792 1.1.1.1.2.2 yamt realloc((char *) ncodes, sizeof(_codeidx_t) * (ncodes_size + 8));
793 1.1.1.1.2.2 yamt
794 1.1.1.1.2.2 yamt ncodes_size += 8;
795 1.1.1.1.2.2 yamt }
796 1.1.1.1.2.2 yamt
797 1.1.1.1.2.2 yamt /*
798 1.1.1.1.2.2 yamt * Shift things around to insert the code if necessary.
799 1.1.1.1.2.2 yamt */
800 1.1.1.1.2.2 yamt if (i < ncodes_used) {
801 1.1.1.1.2.2 yamt for (j = ncodes_used; j > i; j--) {
802 1.1.1.1.2.2 yamt ncodes[j].code = ncodes[j - 1].code;
803 1.1.1.1.2.2 yamt ncodes[j].idx = ncodes[j - 1].idx;
804 1.1.1.1.2.2 yamt }
805 1.1.1.1.2.2 yamt }
806 1.1.1.1.2.2 yamt ncodes[i].code = code;
807 1.1.1.1.2.2 yamt ncodes[i].idx = make_number(num, denom);
808 1.1.1.1.2.2 yamt
809 1.1.1.1.2.2 yamt ncodes_used++;
810 1.1.1.1.2.2 yamt }
811 1.1.1.1.2.2 yamt
812 1.1.1.1.2.2 yamt /*
813 1.1.1.1.2.2 yamt * This routine assumes that the line is a valid Unicode Character Database
814 1.1.1.1.2.2 yamt * entry.
815 1.1.1.1.2.2 yamt */
816 1.1.1.1.2.2 yamt static void
817 1.1.1.1.2.2 yamt read_cdata(FILE *in)
818 1.1.1.1.2.2 yamt {
819 1.1.1.1.2.2 yamt ac_uint4 i, lineno, skip, code, ccl_code;
820 1.1.1.1.2.2 yamt short wnum, neg, number[2], compat;
821 1.1.1.1.2.2 yamt char line[512], *s, *e;
822 1.1.1.1.2.2 yamt
823 1.1.1.1.2.2 yamt lineno = skip = 0;
824 1.1.1.1.2.2 yamt while (fgets(line, sizeof(line), in)) {
825 1.1.1.1.2.2 yamt if( (s=strchr(line, '\n')) ) *s = '\0';
826 1.1.1.1.2.2 yamt lineno++;
827 1.1.1.1.2.2 yamt
828 1.1.1.1.2.2 yamt /*
829 1.1.1.1.2.2 yamt * Skip blank lines and lines that start with a '#'.
830 1.1.1.1.2.2 yamt */
831 1.1.1.1.2.2 yamt if (line[0] == 0 || line[0] == '#')
832 1.1.1.1.2.2 yamt continue;
833 1.1.1.1.2.2 yamt
834 1.1.1.1.2.2 yamt /*
835 1.1.1.1.2.2 yamt * If lines need to be skipped, do it here.
836 1.1.1.1.2.2 yamt */
837 1.1.1.1.2.2 yamt if (skip) {
838 1.1.1.1.2.2 yamt skip--;
839 1.1.1.1.2.2 yamt continue;
840 1.1.1.1.2.2 yamt }
841 1.1.1.1.2.2 yamt
842 1.1.1.1.2.2 yamt /*
843 1.1.1.1.2.2 yamt * Collect the code. The code can be up to 6 hex digits in length to
844 1.1.1.1.2.2 yamt * allow surrogates to be specified.
845 1.1.1.1.2.2 yamt */
846 1.1.1.1.2.2 yamt for (s = line, i = code = 0; *s != ';' && i < 6; i++, s++) {
847 1.1.1.1.2.2 yamt code <<= 4;
848 1.1.1.1.2.2 yamt if (*s >= '0' && *s <= '9')
849 1.1.1.1.2.2 yamt code += *s - '0';
850 1.1.1.1.2.2 yamt else if (*s >= 'A' && *s <= 'F')
851 1.1.1.1.2.2 yamt code += (*s - 'A') + 10;
852 1.1.1.1.2.2 yamt else if (*s >= 'a' && *s <= 'f')
853 1.1.1.1.2.2 yamt code += (*s - 'a') + 10;
854 1.1.1.1.2.2 yamt }
855 1.1.1.1.2.2 yamt
856 1.1.1.1.2.2 yamt /*
857 1.1.1.1.2.2 yamt * Handle the following special cases:
858 1.1.1.1.2.2 yamt * 1. 4E00-9FA5 CJK Ideographs.
859 1.1.1.1.2.2 yamt * 2. AC00-D7A3 Hangul Syllables.
860 1.1.1.1.2.2 yamt * 3. D800-DFFF Surrogates.
861 1.1.1.1.2.2 yamt * 4. E000-F8FF Private Use Area.
862 1.1.1.1.2.2 yamt * 5. F900-FA2D Han compatibility.
863 1.1.1.1.2.2 yamt * ...Plus additional ranges in newer Unicode versions...
864 1.1.1.1.2.2 yamt */
865 1.1.1.1.2.2 yamt switch (code) {
866 1.1.1.1.2.2 yamt case 0x3400:
867 1.1.1.1.2.2 yamt /* CJK Ideograph Extension A */
868 1.1.1.1.2.2 yamt add_range(0x3400, 0x4db5, "Lo", "L");
869 1.1.1.1.2.2 yamt
870 1.1.1.1.2.2 yamt add_range(0x3400, 0x4db5, "Cp", 0);
871 1.1.1.1.2.2 yamt
872 1.1.1.1.2.2 yamt skip = 1;
873 1.1.1.1.2.2 yamt break;
874 1.1.1.1.2.2 yamt case 0x4e00:
875 1.1.1.1.2.2 yamt /*
876 1.1.1.1.2.2 yamt * The Han ideographs.
877 1.1.1.1.2.2 yamt */
878 1.1.1.1.2.2 yamt add_range(0x4e00, 0x9fff, "Lo", "L");
879 1.1.1.1.2.2 yamt
880 1.1.1.1.2.2 yamt /*
881 1.1.1.1.2.2 yamt * Add the characters to the defined category.
882 1.1.1.1.2.2 yamt */
883 1.1.1.1.2.2 yamt add_range(0x4e00, 0x9fa5, "Cp", 0);
884 1.1.1.1.2.2 yamt
885 1.1.1.1.2.2 yamt skip = 1;
886 1.1.1.1.2.2 yamt break;
887 1.1.1.1.2.2 yamt case 0xac00:
888 1.1.1.1.2.2 yamt /*
889 1.1.1.1.2.2 yamt * The Hangul syllables.
890 1.1.1.1.2.2 yamt */
891 1.1.1.1.2.2 yamt add_range(0xac00, 0xd7a3, "Lo", "L");
892 1.1.1.1.2.2 yamt
893 1.1.1.1.2.2 yamt /*
894 1.1.1.1.2.2 yamt * Add the characters to the defined category.
895 1.1.1.1.2.2 yamt */
896 1.1.1.1.2.2 yamt add_range(0xac00, 0xd7a3, "Cp", 0);
897 1.1.1.1.2.2 yamt
898 1.1.1.1.2.2 yamt skip = 1;
899 1.1.1.1.2.2 yamt break;
900 1.1.1.1.2.2 yamt case 0xd800:
901 1.1.1.1.2.2 yamt /*
902 1.1.1.1.2.2 yamt * Make a range of all surrogates and assume some default
903 1.1.1.1.2.2 yamt * properties.
904 1.1.1.1.2.2 yamt */
905 1.1.1.1.2.2 yamt add_range(0x010000, 0x10ffff, "Cs", "L");
906 1.1.1.1.2.2 yamt skip = 5;
907 1.1.1.1.2.2 yamt break;
908 1.1.1.1.2.2 yamt case 0xe000:
909 1.1.1.1.2.2 yamt /*
910 1.1.1.1.2.2 yamt * The Private Use area. Add with a default set of properties.
911 1.1.1.1.2.2 yamt */
912 1.1.1.1.2.2 yamt add_range(0xe000, 0xf8ff, "Co", "L");
913 1.1.1.1.2.2 yamt skip = 1;
914 1.1.1.1.2.2 yamt break;
915 1.1.1.1.2.2 yamt case 0xf900:
916 1.1.1.1.2.2 yamt /*
917 1.1.1.1.2.2 yamt * The CJK compatibility area.
918 1.1.1.1.2.2 yamt */
919 1.1.1.1.2.2 yamt add_range(0xf900, 0xfaff, "Lo", "L");
920 1.1.1.1.2.2 yamt
921 1.1.1.1.2.2 yamt /*
922 1.1.1.1.2.2 yamt * Add the characters to the defined category.
923 1.1.1.1.2.2 yamt */
924 1.1.1.1.2.2 yamt add_range(0xf900, 0xfaff, "Cp", 0);
925 1.1.1.1.2.2 yamt
926 1.1.1.1.2.2 yamt skip = 1;
927 1.1.1.1.2.2 yamt break;
928 1.1.1.1.2.2 yamt case 0x20000:
929 1.1.1.1.2.2 yamt /* CJK Ideograph Extension B */
930 1.1.1.1.2.2 yamt add_range(0x20000, 0x2a6d6, "Lo", "L");
931 1.1.1.1.2.2 yamt
932 1.1.1.1.2.2 yamt add_range(0x20000, 0x2a6d6, "Cp", 0);
933 1.1.1.1.2.2 yamt
934 1.1.1.1.2.2 yamt skip = 1;
935 1.1.1.1.2.2 yamt break;
936 1.1.1.1.2.2 yamt case 0xf0000:
937 1.1.1.1.2.2 yamt /* Plane 15 private use */
938 1.1.1.1.2.2 yamt add_range(0xf0000, 0xffffd, "Co", "L");
939 1.1.1.1.2.2 yamt skip = 1;
940 1.1.1.1.2.2 yamt break;
941 1.1.1.1.2.2 yamt
942 1.1.1.1.2.2 yamt case 0x100000:
943 1.1.1.1.2.2 yamt /* Plane 16 private use */
944 1.1.1.1.2.2 yamt add_range(0x100000, 0x10fffd, "Co", "L");
945 1.1.1.1.2.2 yamt skip = 1;
946 1.1.1.1.2.2 yamt break;
947 1.1.1.1.2.2 yamt }
948 1.1.1.1.2.2 yamt
949 1.1.1.1.2.2 yamt if (skip)
950 1.1.1.1.2.2 yamt continue;
951 1.1.1.1.2.2 yamt
952 1.1.1.1.2.2 yamt /*
953 1.1.1.1.2.2 yamt * Add the code to the defined category.
954 1.1.1.1.2.2 yamt */
955 1.1.1.1.2.2 yamt ordered_range_insert(code, "Cp", 2);
956 1.1.1.1.2.2 yamt
957 1.1.1.1.2.2 yamt /*
958 1.1.1.1.2.2 yamt * Locate the first character property field.
959 1.1.1.1.2.2 yamt */
960 1.1.1.1.2.2 yamt for (i = 0; *s != 0 && i < 2; s++) {
961 1.1.1.1.2.2 yamt if (*s == ';')
962 1.1.1.1.2.2 yamt i++;
963 1.1.1.1.2.2 yamt }
964 1.1.1.1.2.2 yamt for (e = s; *e && *e != ';'; e++) ;
965 1.1.1.1.2.2 yamt
966 1.1.1.1.2.2 yamt ordered_range_insert(code, s, e - s);
967 1.1.1.1.2.2 yamt
968 1.1.1.1.2.2 yamt /*
969 1.1.1.1.2.2 yamt * Locate the combining class code.
970 1.1.1.1.2.2 yamt */
971 1.1.1.1.2.2 yamt for (s = e; *s != 0 && i < 3; s++) {
972 1.1.1.1.2.2 yamt if (*s == ';')
973 1.1.1.1.2.2 yamt i++;
974 1.1.1.1.2.2 yamt }
975 1.1.1.1.2.2 yamt
976 1.1.1.1.2.2 yamt /*
977 1.1.1.1.2.2 yamt * Convert the combining class code from decimal.
978 1.1.1.1.2.2 yamt */
979 1.1.1.1.2.2 yamt for (ccl_code = 0, e = s; *e && *e != ';'; e++)
980 1.1.1.1.2.2 yamt ccl_code = (ccl_code * 10) + (*e - '0');
981 1.1.1.1.2.2 yamt
982 1.1.1.1.2.2 yamt /*
983 1.1.1.1.2.2 yamt * Add the code if it not 0.
984 1.1.1.1.2.2 yamt */
985 1.1.1.1.2.2 yamt if (ccl_code != 0)
986 1.1.1.1.2.2 yamt ordered_ccl_insert(code, ccl_code);
987 1.1.1.1.2.2 yamt
988 1.1.1.1.2.2 yamt /*
989 1.1.1.1.2.2 yamt * Locate the second character property field.
990 1.1.1.1.2.2 yamt */
991 1.1.1.1.2.2 yamt for (s = e; *s != 0 && i < 4; s++) {
992 1.1.1.1.2.2 yamt if (*s == ';')
993 1.1.1.1.2.2 yamt i++;
994 1.1.1.1.2.2 yamt }
995 1.1.1.1.2.2 yamt for (e = s; *e && *e != ';'; e++) ;
996 1.1.1.1.2.2 yamt
997 1.1.1.1.2.2 yamt ordered_range_insert(code, s, e - s);
998 1.1.1.1.2.2 yamt
999 1.1.1.1.2.2 yamt /*
1000 1.1.1.1.2.2 yamt * Check for a decomposition.
1001 1.1.1.1.2.2 yamt */
1002 1.1.1.1.2.2 yamt s = ++e;
1003 1.1.1.1.2.2 yamt if (*s != ';') {
1004 1.1.1.1.2.2 yamt compat = *s == '<';
1005 1.1.1.1.2.2 yamt if (compat) {
1006 1.1.1.1.2.2 yamt /*
1007 1.1.1.1.2.2 yamt * Skip compatibility formatting tag.
1008 1.1.1.1.2.2 yamt */
1009 1.1.1.1.2.2 yamt while (*s++ != '>');
1010 1.1.1.1.2.2 yamt }
1011 1.1.1.1.2.2 yamt /*
1012 1.1.1.1.2.2 yamt * Collect the codes of the decomposition.
1013 1.1.1.1.2.2 yamt */
1014 1.1.1.1.2.2 yamt for (dectmp_size = 0; *s != ';'; ) {
1015 1.1.1.1.2.2 yamt /*
1016 1.1.1.1.2.2 yamt * Skip all leading non-hex digits.
1017 1.1.1.1.2.2 yamt */
1018 1.1.1.1.2.2 yamt while (!ishdigit(*s))
1019 1.1.1.1.2.2 yamt s++;
1020 1.1.1.1.2.2 yamt
1021 1.1.1.1.2.2 yamt for (dectmp[dectmp_size] = 0; ishdigit(*s); s++) {
1022 1.1.1.1.2.2 yamt dectmp[dectmp_size] <<= 4;
1023 1.1.1.1.2.2 yamt if (*s >= '0' && *s <= '9')
1024 1.1.1.1.2.2 yamt dectmp[dectmp_size] += *s - '0';
1025 1.1.1.1.2.2 yamt else if (*s >= 'A' && *s <= 'F')
1026 1.1.1.1.2.2 yamt dectmp[dectmp_size] += (*s - 'A') + 10;
1027 1.1.1.1.2.2 yamt else if (*s >= 'a' && *s <= 'f')
1028 1.1.1.1.2.2 yamt dectmp[dectmp_size] += (*s - 'a') + 10;
1029 1.1.1.1.2.2 yamt }
1030 1.1.1.1.2.2 yamt dectmp_size++;
1031 1.1.1.1.2.2 yamt }
1032 1.1.1.1.2.2 yamt
1033 1.1.1.1.2.2 yamt /*
1034 1.1.1.1.2.2 yamt * If there are any codes in the temporary decomposition array,
1035 1.1.1.1.2.2 yamt * then add the character with its decomposition.
1036 1.1.1.1.2.2 yamt */
1037 1.1.1.1.2.2 yamt if (dectmp_size > 0) {
1038 1.1.1.1.2.2 yamt if (!compat) {
1039 1.1.1.1.2.2 yamt add_decomp(code, 0);
1040 1.1.1.1.2.2 yamt }
1041 1.1.1.1.2.2 yamt add_decomp(code, 1);
1042 1.1.1.1.2.2 yamt }
1043 1.1.1.1.2.2 yamt }
1044 1.1.1.1.2.2 yamt
1045 1.1.1.1.2.2 yamt /*
1046 1.1.1.1.2.2 yamt * Skip to the number field.
1047 1.1.1.1.2.2 yamt */
1048 1.1.1.1.2.2 yamt for (i = 0; i < 3 && *s; s++) {
1049 1.1.1.1.2.2 yamt if (*s == ';')
1050 1.1.1.1.2.2 yamt i++;
1051 1.1.1.1.2.2 yamt }
1052 1.1.1.1.2.2 yamt
1053 1.1.1.1.2.2 yamt /*
1054 1.1.1.1.2.2 yamt * Scan the number in.
1055 1.1.1.1.2.2 yamt */
1056 1.1.1.1.2.2 yamt number[0] = number[1] = 0;
1057 1.1.1.1.2.2 yamt for (e = s, neg = wnum = 0; *e && *e != ';'; e++) {
1058 1.1.1.1.2.2 yamt if (*e == '-') {
1059 1.1.1.1.2.2 yamt neg = 1;
1060 1.1.1.1.2.2 yamt continue;
1061 1.1.1.1.2.2 yamt }
1062 1.1.1.1.2.2 yamt
1063 1.1.1.1.2.2 yamt if (*e == '/') {
1064 1.1.1.1.2.2 yamt /*
1065 1.1.1.1.2.2 yamt * Move the the denominator of the fraction.
1066 1.1.1.1.2.2 yamt */
1067 1.1.1.1.2.2 yamt if (neg)
1068 1.1.1.1.2.2 yamt number[wnum] *= -1;
1069 1.1.1.1.2.2 yamt neg = 0;
1070 1.1.1.1.2.2 yamt e++;
1071 1.1.1.1.2.2 yamt wnum++;
1072 1.1.1.1.2.2 yamt }
1073 1.1.1.1.2.2 yamt number[wnum] = (number[wnum] * 10) + (*e - '0');
1074 1.1.1.1.2.2 yamt }
1075 1.1.1.1.2.2 yamt
1076 1.1.1.1.2.2 yamt if (e > s) {
1077 1.1.1.1.2.2 yamt /*
1078 1.1.1.1.2.2 yamt * Adjust the denominator in case of integers and add the number.
1079 1.1.1.1.2.2 yamt */
1080 1.1.1.1.2.2 yamt if (wnum == 0)
1081 1.1.1.1.2.2 yamt number[1] = 1;
1082 1.1.1.1.2.2 yamt
1083 1.1.1.1.2.2 yamt add_number(code, number[0], number[1]);
1084 1.1.1.1.2.2 yamt }
1085 1.1.1.1.2.2 yamt
1086 1.1.1.1.2.2 yamt /*
1087 1.1.1.1.2.2 yamt * Skip to the start of the possible case mappings.
1088 1.1.1.1.2.2 yamt */
1089 1.1.1.1.2.2 yamt for (s = e, i = 0; i < 4 && *s; s++) {
1090 1.1.1.1.2.2 yamt if (*s == ';')
1091 1.1.1.1.2.2 yamt i++;
1092 1.1.1.1.2.2 yamt }
1093 1.1.1.1.2.2 yamt
1094 1.1.1.1.2.2 yamt /*
1095 1.1.1.1.2.2 yamt * Collect the case mappings.
1096 1.1.1.1.2.2 yamt */
1097 1.1.1.1.2.2 yamt cases[0] = cases[1] = cases[2] = 0;
1098 1.1.1.1.2.2 yamt for (i = 0; i < 3; i++) {
1099 1.1.1.1.2.2 yamt while (ishdigit(*s)) {
1100 1.1.1.1.2.2 yamt cases[i] <<= 4;
1101 1.1.1.1.2.2 yamt if (*s >= '0' && *s <= '9')
1102 1.1.1.1.2.2 yamt cases[i] += *s - '0';
1103 1.1.1.1.2.2 yamt else if (*s >= 'A' && *s <= 'F')
1104 1.1.1.1.2.2 yamt cases[i] += (*s - 'A') + 10;
1105 1.1.1.1.2.2 yamt else if (*s >= 'a' && *s <= 'f')
1106 1.1.1.1.2.2 yamt cases[i] += (*s - 'a') + 10;
1107 1.1.1.1.2.2 yamt s++;
1108 1.1.1.1.2.2 yamt }
1109 1.1.1.1.2.2 yamt if (*s == ';')
1110 1.1.1.1.2.2 yamt s++;
1111 1.1.1.1.2.2 yamt }
1112 1.1.1.1.2.2 yamt if (cases[0] && cases[1])
1113 1.1.1.1.2.2 yamt /*
1114 1.1.1.1.2.2 yamt * Add the upper and lower mappings for a title case character.
1115 1.1.1.1.2.2 yamt */
1116 1.1.1.1.2.2 yamt add_title(code);
1117 1.1.1.1.2.2 yamt else if (cases[1])
1118 1.1.1.1.2.2 yamt /*
1119 1.1.1.1.2.2 yamt * Add the lower and title case mappings for the upper case
1120 1.1.1.1.2.2 yamt * character.
1121 1.1.1.1.2.2 yamt */
1122 1.1.1.1.2.2 yamt add_upper(code);
1123 1.1.1.1.2.2 yamt else if (cases[0])
1124 1.1.1.1.2.2 yamt /*
1125 1.1.1.1.2.2 yamt * Add the upper and title case mappings for the lower case
1126 1.1.1.1.2.2 yamt * character.
1127 1.1.1.1.2.2 yamt */
1128 1.1.1.1.2.2 yamt add_lower(code);
1129 1.1.1.1.2.2 yamt }
1130 1.1.1.1.2.2 yamt }
1131 1.1.1.1.2.2 yamt
1132 1.1.1.1.2.2 yamt static _decomp_t *
1133 1.1.1.1.2.2 yamt find_decomp(ac_uint4 code, short compat)
1134 1.1.1.1.2.2 yamt {
1135 1.1.1.1.2.2 yamt long l, r, m;
1136 1.1.1.1.2.2 yamt _decomp_t *decs;
1137 1.1.1.1.2.2 yamt
1138 1.1.1.1.2.2 yamt l = 0;
1139 1.1.1.1.2.2 yamt r = (compat ? kdecomps_used : decomps_used) - 1;
1140 1.1.1.1.2.2 yamt decs = compat ? kdecomps : decomps;
1141 1.1.1.1.2.2 yamt while (l <= r) {
1142 1.1.1.1.2.2 yamt m = (l + r) >> 1;
1143 1.1.1.1.2.2 yamt if (code > decs[m].code)
1144 1.1.1.1.2.2 yamt l = m + 1;
1145 1.1.1.1.2.2 yamt else if (code < decs[m].code)
1146 1.1.1.1.2.2 yamt r = m - 1;
1147 1.1.1.1.2.2 yamt else
1148 1.1.1.1.2.2 yamt return &decs[m];
1149 1.1.1.1.2.2 yamt }
1150 1.1.1.1.2.2 yamt return 0;
1151 1.1.1.1.2.2 yamt }
1152 1.1.1.1.2.2 yamt
1153 1.1.1.1.2.2 yamt static void
1154 1.1.1.1.2.2 yamt decomp_it(_decomp_t *d, short compat)
1155 1.1.1.1.2.2 yamt {
1156 1.1.1.1.2.2 yamt ac_uint4 i;
1157 1.1.1.1.2.2 yamt _decomp_t *dp;
1158 1.1.1.1.2.2 yamt
1159 1.1.1.1.2.2 yamt for (i = 0; i < d->used; i++) {
1160 1.1.1.1.2.2 yamt if ((dp = find_decomp(d->decomp[i], compat)) != 0)
1161 1.1.1.1.2.2 yamt decomp_it(dp, compat);
1162 1.1.1.1.2.2 yamt else
1163 1.1.1.1.2.2 yamt dectmp[dectmp_size++] = d->decomp[i];
1164 1.1.1.1.2.2 yamt }
1165 1.1.1.1.2.2 yamt }
1166 1.1.1.1.2.2 yamt
1167 1.1.1.1.2.2 yamt /*
1168 1.1.1.1.2.2 yamt * Expand all decompositions by recursively decomposing each character
1169 1.1.1.1.2.2 yamt * in the decomposition.
1170 1.1.1.1.2.2 yamt */
1171 1.1.1.1.2.2 yamt static void
1172 1.1.1.1.2.2 yamt expand_decomp(void)
1173 1.1.1.1.2.2 yamt {
1174 1.1.1.1.2.2 yamt ac_uint4 i;
1175 1.1.1.1.2.2 yamt
1176 1.1.1.1.2.2 yamt for (i = 0; i < decomps_used; i++) {
1177 1.1.1.1.2.2 yamt dectmp_size = 0;
1178 1.1.1.1.2.2 yamt decomp_it(&decomps[i], 0);
1179 1.1.1.1.2.2 yamt if (dectmp_size > 0)
1180 1.1.1.1.2.2 yamt add_decomp(decomps[i].code, 0);
1181 1.1.1.1.2.2 yamt }
1182 1.1.1.1.2.2 yamt
1183 1.1.1.1.2.2 yamt for (i = 0; i < kdecomps_used; i++) {
1184 1.1.1.1.2.2 yamt dectmp_size = 0;
1185 1.1.1.1.2.2 yamt decomp_it(&kdecomps[i], 1);
1186 1.1.1.1.2.2 yamt if (dectmp_size > 0)
1187 1.1.1.1.2.2 yamt add_decomp(kdecomps[i].code, 1);
1188 1.1.1.1.2.2 yamt }
1189 1.1.1.1.2.2 yamt }
1190 1.1.1.1.2.2 yamt
1191 1.1.1.1.2.2 yamt static int
1192 1.1.1.1.2.2 yamt cmpcomps(const void *v_comp1, const void *v_comp2)
1193 1.1.1.1.2.2 yamt {
1194 1.1.1.1.2.2 yamt const _comp_t *comp1 = v_comp1, *comp2 = v_comp2;
1195 1.1.1.1.2.2 yamt long diff = comp1->code1 - comp2->code1;
1196 1.1.1.1.2.2 yamt
1197 1.1.1.1.2.2 yamt if (!diff)
1198 1.1.1.1.2.2 yamt diff = comp1->code2 - comp2->code2;
1199 1.1.1.1.2.2 yamt return (int) diff;
1200 1.1.1.1.2.2 yamt }
1201 1.1.1.1.2.2 yamt
1202 1.1.1.1.2.2 yamt /*
1203 1.1.1.1.2.2 yamt * Load composition exclusion data
1204 1.1.1.1.2.2 yamt */
1205 1.1.1.1.2.2 yamt static void
1206 1.1.1.1.2.2 yamt read_compexdata(FILE *in)
1207 1.1.1.1.2.2 yamt {
1208 1.1.1.1.2.2 yamt ac_uint2 i;
1209 1.1.1.1.2.2 yamt ac_uint4 code;
1210 1.1.1.1.2.2 yamt char line[512], *s;
1211 1.1.1.1.2.2 yamt
1212 1.1.1.1.2.2 yamt (void) memset((char *) compexs, 0, sizeof(compexs));
1213 1.1.1.1.2.2 yamt
1214 1.1.1.1.2.2 yamt while (fgets(line, sizeof(line), in)) {
1215 1.1.1.1.2.2 yamt if( (s=strchr(line, '\n')) ) *s = '\0';
1216 1.1.1.1.2.2 yamt /*
1217 1.1.1.1.2.2 yamt * Skip blank lines and lines that start with a '#'.
1218 1.1.1.1.2.2 yamt */
1219 1.1.1.1.2.2 yamt if (line[0] == 0 || line[0] == '#')
1220 1.1.1.1.2.2 yamt continue;
1221 1.1.1.1.2.2 yamt
1222 1.1.1.1.2.2 yamt /*
1223 1.1.1.1.2.2 yamt * Collect the code. Assume max 6 digits
1224 1.1.1.1.2.2 yamt */
1225 1.1.1.1.2.2 yamt
1226 1.1.1.1.2.2 yamt for (s = line, i = code = 0; *s != '#' && i < 6; i++, s++) {
1227 1.1.1.1.2.2 yamt if (isspace((unsigned char)*s)) break;
1228 1.1.1.1.2.2 yamt code <<= 4;
1229 1.1.1.1.2.2 yamt if (*s >= '0' && *s <= '9')
1230 1.1.1.1.2.2 yamt code += *s - '0';
1231 1.1.1.1.2.2 yamt else if (*s >= 'A' && *s <= 'F')
1232 1.1.1.1.2.2 yamt code += (*s - 'A') + 10;
1233 1.1.1.1.2.2 yamt else if (*s >= 'a' && *s <= 'f')
1234 1.1.1.1.2.2 yamt code += (*s - 'a') + 10;
1235 1.1.1.1.2.2 yamt }
1236 1.1.1.1.2.2 yamt COMPEX_SET(code);
1237 1.1.1.1.2.2 yamt }
1238 1.1.1.1.2.2 yamt }
1239 1.1.1.1.2.2 yamt
1240 1.1.1.1.2.2 yamt /*
1241 1.1.1.1.2.2 yamt * Creates array of compositions from decomposition array
1242 1.1.1.1.2.2 yamt */
1243 1.1.1.1.2.2 yamt static void
1244 1.1.1.1.2.2 yamt create_comps(void)
1245 1.1.1.1.2.2 yamt {
1246 1.1.1.1.2.2 yamt ac_uint4 i, cu;
1247 1.1.1.1.2.2 yamt
1248 1.1.1.1.2.2 yamt comps = (_comp_t *) malloc(comps_used * sizeof(_comp_t));
1249 1.1.1.1.2.2 yamt
1250 1.1.1.1.2.2 yamt for (i = cu = 0; i < decomps_used; i++) {
1251 1.1.1.1.2.2 yamt if (decomps[i].used != 2 || COMPEX_TEST(decomps[i].code))
1252 1.1.1.1.2.2 yamt continue;
1253 1.1.1.1.2.2 yamt comps[cu].comp = decomps[i].code;
1254 1.1.1.1.2.2 yamt comps[cu].count = 2;
1255 1.1.1.1.2.2 yamt comps[cu].code1 = decomps[i].decomp[0];
1256 1.1.1.1.2.2 yamt comps[cu].code2 = decomps[i].decomp[1];
1257 1.1.1.1.2.2 yamt cu++;
1258 1.1.1.1.2.2 yamt }
1259 1.1.1.1.2.2 yamt comps_used = cu;
1260 1.1.1.1.2.2 yamt qsort(comps, comps_used, sizeof(_comp_t), cmpcomps);
1261 1.1.1.1.2.2 yamt }
1262 1.1.1.1.2.2 yamt
1263 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1264 1.1.1.1.2.2 yamt static void
1265 1.1.1.1.2.2 yamt write_case(FILE *out, _case_t *tab, int num, int first)
1266 1.1.1.1.2.2 yamt {
1267 1.1.1.1.2.2 yamt int i;
1268 1.1.1.1.2.2 yamt
1269 1.1.1.1.2.2 yamt for (i=0; i<num; i++) {
1270 1.1.1.1.2.2 yamt if (first) first = 0;
1271 1.1.1.1.2.2 yamt else fprintf(out, ",");
1272 1.1.1.1.2.2 yamt fprintf(out, "\n\t0x%08lx, 0x%08lx, 0x%08lx",
1273 1.1.1.1.2.2 yamt (unsigned long) tab[i].key, (unsigned long) tab[i].other1,
1274 1.1.1.1.2.2 yamt (unsigned long) tab[i].other2);
1275 1.1.1.1.2.2 yamt }
1276 1.1.1.1.2.2 yamt }
1277 1.1.1.1.2.2 yamt
1278 1.1.1.1.2.2 yamt #define PREF "static const "
1279 1.1.1.1.2.2 yamt
1280 1.1.1.1.2.2 yamt #endif
1281 1.1.1.1.2.2 yamt
1282 1.1.1.1.2.2 yamt static void
1283 1.1.1.1.2.2 yamt write_cdata(char *opath)
1284 1.1.1.1.2.2 yamt {
1285 1.1.1.1.2.2 yamt FILE *out;
1286 1.1.1.1.2.2 yamt ac_uint4 bytes;
1287 1.1.1.1.2.2 yamt ac_uint4 i, idx, nprops;
1288 1.1.1.1.2.2 yamt #if !(HARDCODE_DATA)
1289 1.1.1.1.2.2 yamt ac_uint2 casecnt[2];
1290 1.1.1.1.2.2 yamt #endif
1291 1.1.1.1.2.2 yamt char path[BUFSIZ];
1292 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1293 1.1.1.1.2.2 yamt int j, k;
1294 1.1.1.1.2.2 yamt
1295 1.1.1.1.2.2 yamt /*****************************************************************
1296 1.1.1.1.2.2 yamt *
1297 1.1.1.1.2.2 yamt * Generate the ctype data.
1298 1.1.1.1.2.2 yamt *
1299 1.1.1.1.2.2 yamt *****************************************************************/
1300 1.1.1.1.2.2 yamt
1301 1.1.1.1.2.2 yamt /*
1302 1.1.1.1.2.2 yamt * Open the output file.
1303 1.1.1.1.2.2 yamt */
1304 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "uctable.h", opath);
1305 1.1.1.1.2.2 yamt if ((out = fopen(path, "w")) == 0)
1306 1.1.1.1.2.2 yamt return;
1307 1.1.1.1.2.2 yamt #else
1308 1.1.1.1.2.2 yamt /*
1309 1.1.1.1.2.2 yamt * Open the ctype.dat file.
1310 1.1.1.1.2.2 yamt */
1311 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "ctype.dat", opath);
1312 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1313 1.1.1.1.2.2 yamt return;
1314 1.1.1.1.2.2 yamt #endif
1315 1.1.1.1.2.2 yamt
1316 1.1.1.1.2.2 yamt /*
1317 1.1.1.1.2.2 yamt * Collect the offsets for the properties. The offsets array is
1318 1.1.1.1.2.2 yamt * on a 4-byte boundary to keep things efficient for architectures
1319 1.1.1.1.2.2 yamt * that need such a thing.
1320 1.1.1.1.2.2 yamt */
1321 1.1.1.1.2.2 yamt for (i = idx = 0; i < NUMPROPS; i++) {
1322 1.1.1.1.2.2 yamt propcnt[i] = (proptbl[i].used != 0) ? idx : 0xffff;
1323 1.1.1.1.2.2 yamt idx += proptbl[i].used;
1324 1.1.1.1.2.2 yamt }
1325 1.1.1.1.2.2 yamt
1326 1.1.1.1.2.2 yamt /*
1327 1.1.1.1.2.2 yamt * Add the sentinel index which is used by the binary search as the upper
1328 1.1.1.1.2.2 yamt * bound for a search.
1329 1.1.1.1.2.2 yamt */
1330 1.1.1.1.2.2 yamt propcnt[i] = idx;
1331 1.1.1.1.2.2 yamt
1332 1.1.1.1.2.2 yamt /*
1333 1.1.1.1.2.2 yamt * Record the actual number of property lists. This may be different than
1334 1.1.1.1.2.2 yamt * the number of offsets actually written because of aligning on a 4-byte
1335 1.1.1.1.2.2 yamt * boundary.
1336 1.1.1.1.2.2 yamt */
1337 1.1.1.1.2.2 yamt hdr[1] = NUMPROPS;
1338 1.1.1.1.2.2 yamt
1339 1.1.1.1.2.2 yamt /*
1340 1.1.1.1.2.2 yamt * Calculate the byte count needed and pad the property counts array to a
1341 1.1.1.1.2.2 yamt * 4-byte boundary.
1342 1.1.1.1.2.2 yamt */
1343 1.1.1.1.2.2 yamt if ((bytes = sizeof(ac_uint2) * (NUMPROPS + 1)) & 3)
1344 1.1.1.1.2.2 yamt bytes += 4 - (bytes & 3);
1345 1.1.1.1.2.2 yamt nprops = bytes / sizeof(ac_uint2);
1346 1.1.1.1.2.2 yamt bytes += sizeof(ac_uint4) * idx;
1347 1.1.1.1.2.2 yamt
1348 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1349 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucprop_size = %d;\n\n", NUMPROPS);
1350 1.1.1.1.2.2 yamt
1351 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint2 _ucprop_offsets[] = {");
1352 1.1.1.1.2.2 yamt
1353 1.1.1.1.2.2 yamt for (i = 0; i<nprops; i++) {
1354 1.1.1.1.2.2 yamt if (i) fprintf(out, ",");
1355 1.1.1.1.2.2 yamt if (!(i&7)) fprintf(out, "\n\t");
1356 1.1.1.1.2.2 yamt else fprintf(out, " ");
1357 1.1.1.1.2.2 yamt fprintf(out, "0x%04x", propcnt[i]);
1358 1.1.1.1.2.2 yamt }
1359 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1360 1.1.1.1.2.2 yamt
1361 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucprop_ranges[] = {");
1362 1.1.1.1.2.2 yamt
1363 1.1.1.1.2.2 yamt k = 0;
1364 1.1.1.1.2.2 yamt for (i = 0; i < NUMPROPS; i++) {
1365 1.1.1.1.2.2 yamt if (proptbl[i].used > 0) {
1366 1.1.1.1.2.2 yamt for (j=0; j<proptbl[i].used; j++) {
1367 1.1.1.1.2.2 yamt if (k) fprintf(out, ",");
1368 1.1.1.1.2.2 yamt if (!(k&3)) fprintf(out,"\n\t");
1369 1.1.1.1.2.2 yamt else fprintf(out, " ");
1370 1.1.1.1.2.2 yamt k++;
1371 1.1.1.1.2.2 yamt fprintf(out, "0x%08lx", (unsigned long) proptbl[i].ranges[j]);
1372 1.1.1.1.2.2 yamt }
1373 1.1.1.1.2.2 yamt }
1374 1.1.1.1.2.2 yamt }
1375 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1376 1.1.1.1.2.2 yamt #else
1377 1.1.1.1.2.2 yamt /*
1378 1.1.1.1.2.2 yamt * Write the header.
1379 1.1.1.1.2.2 yamt */
1380 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1381 1.1.1.1.2.2 yamt
1382 1.1.1.1.2.2 yamt /*
1383 1.1.1.1.2.2 yamt * Write the byte count.
1384 1.1.1.1.2.2 yamt */
1385 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1386 1.1.1.1.2.2 yamt
1387 1.1.1.1.2.2 yamt /*
1388 1.1.1.1.2.2 yamt * Write the property list counts.
1389 1.1.1.1.2.2 yamt */
1390 1.1.1.1.2.2 yamt fwrite((char *) propcnt, sizeof(ac_uint2), nprops, out);
1391 1.1.1.1.2.2 yamt
1392 1.1.1.1.2.2 yamt /*
1393 1.1.1.1.2.2 yamt * Write the property lists.
1394 1.1.1.1.2.2 yamt */
1395 1.1.1.1.2.2 yamt for (i = 0; i < NUMPROPS; i++) {
1396 1.1.1.1.2.2 yamt if (proptbl[i].used > 0)
1397 1.1.1.1.2.2 yamt fwrite((char *) proptbl[i].ranges, sizeof(ac_uint4),
1398 1.1.1.1.2.2 yamt proptbl[i].used, out);
1399 1.1.1.1.2.2 yamt }
1400 1.1.1.1.2.2 yamt
1401 1.1.1.1.2.2 yamt fclose(out);
1402 1.1.1.1.2.2 yamt #endif
1403 1.1.1.1.2.2 yamt
1404 1.1.1.1.2.2 yamt /*****************************************************************
1405 1.1.1.1.2.2 yamt *
1406 1.1.1.1.2.2 yamt * Generate the case mapping data.
1407 1.1.1.1.2.2 yamt *
1408 1.1.1.1.2.2 yamt *****************************************************************/
1409 1.1.1.1.2.2 yamt
1410 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1411 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uccase_size = %ld;\n\n",
1412 1.1.1.1.2.2 yamt (long) (upper_used + lower_used + title_used));
1413 1.1.1.1.2.2 yamt
1414 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint2 _uccase_len[2] = {%ld, %ld};\n\n",
1415 1.1.1.1.2.2 yamt (long) upper_used, (long) lower_used);
1416 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uccase_map[] = {");
1417 1.1.1.1.2.2 yamt
1418 1.1.1.1.2.2 yamt if (upper_used > 0)
1419 1.1.1.1.2.2 yamt /*
1420 1.1.1.1.2.2 yamt * Write the upper case table.
1421 1.1.1.1.2.2 yamt */
1422 1.1.1.1.2.2 yamt write_case(out, upper, upper_used, 1);
1423 1.1.1.1.2.2 yamt
1424 1.1.1.1.2.2 yamt if (lower_used > 0)
1425 1.1.1.1.2.2 yamt /*
1426 1.1.1.1.2.2 yamt * Write the lower case table.
1427 1.1.1.1.2.2 yamt */
1428 1.1.1.1.2.2 yamt write_case(out, lower, lower_used, !upper_used);
1429 1.1.1.1.2.2 yamt
1430 1.1.1.1.2.2 yamt if (title_used > 0)
1431 1.1.1.1.2.2 yamt /*
1432 1.1.1.1.2.2 yamt * Write the title case table.
1433 1.1.1.1.2.2 yamt */
1434 1.1.1.1.2.2 yamt write_case(out, title, title_used, !(upper_used||lower_used));
1435 1.1.1.1.2.2 yamt
1436 1.1.1.1.2.2 yamt if (!(upper_used || lower_used || title_used))
1437 1.1.1.1.2.2 yamt fprintf(out, "\t0");
1438 1.1.1.1.2.2 yamt
1439 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1440 1.1.1.1.2.2 yamt #else
1441 1.1.1.1.2.2 yamt /*
1442 1.1.1.1.2.2 yamt * Open the case.dat file.
1443 1.1.1.1.2.2 yamt */
1444 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "case.dat", opath);
1445 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1446 1.1.1.1.2.2 yamt return;
1447 1.1.1.1.2.2 yamt
1448 1.1.1.1.2.2 yamt /*
1449 1.1.1.1.2.2 yamt * Write the case mapping tables.
1450 1.1.1.1.2.2 yamt */
1451 1.1.1.1.2.2 yamt hdr[1] = upper_used + lower_used + title_used;
1452 1.1.1.1.2.2 yamt casecnt[0] = upper_used;
1453 1.1.1.1.2.2 yamt casecnt[1] = lower_used;
1454 1.1.1.1.2.2 yamt
1455 1.1.1.1.2.2 yamt /*
1456 1.1.1.1.2.2 yamt * Write the header.
1457 1.1.1.1.2.2 yamt */
1458 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1459 1.1.1.1.2.2 yamt
1460 1.1.1.1.2.2 yamt /*
1461 1.1.1.1.2.2 yamt * Write the upper and lower case table sizes.
1462 1.1.1.1.2.2 yamt */
1463 1.1.1.1.2.2 yamt fwrite((char *) casecnt, sizeof(ac_uint2), 2, out);
1464 1.1.1.1.2.2 yamt
1465 1.1.1.1.2.2 yamt if (upper_used > 0)
1466 1.1.1.1.2.2 yamt /*
1467 1.1.1.1.2.2 yamt * Write the upper case table.
1468 1.1.1.1.2.2 yamt */
1469 1.1.1.1.2.2 yamt fwrite((char *) upper, sizeof(_case_t), upper_used, out);
1470 1.1.1.1.2.2 yamt
1471 1.1.1.1.2.2 yamt if (lower_used > 0)
1472 1.1.1.1.2.2 yamt /*
1473 1.1.1.1.2.2 yamt * Write the lower case table.
1474 1.1.1.1.2.2 yamt */
1475 1.1.1.1.2.2 yamt fwrite((char *) lower, sizeof(_case_t), lower_used, out);
1476 1.1.1.1.2.2 yamt
1477 1.1.1.1.2.2 yamt if (title_used > 0)
1478 1.1.1.1.2.2 yamt /*
1479 1.1.1.1.2.2 yamt * Write the title case table.
1480 1.1.1.1.2.2 yamt */
1481 1.1.1.1.2.2 yamt fwrite((char *) title, sizeof(_case_t), title_used, out);
1482 1.1.1.1.2.2 yamt
1483 1.1.1.1.2.2 yamt fclose(out);
1484 1.1.1.1.2.2 yamt #endif
1485 1.1.1.1.2.2 yamt
1486 1.1.1.1.2.2 yamt /*****************************************************************
1487 1.1.1.1.2.2 yamt *
1488 1.1.1.1.2.2 yamt * Generate the composition data.
1489 1.1.1.1.2.2 yamt *
1490 1.1.1.1.2.2 yamt *****************************************************************/
1491 1.1.1.1.2.2 yamt
1492 1.1.1.1.2.2 yamt /*
1493 1.1.1.1.2.2 yamt * Create compositions from decomposition data
1494 1.1.1.1.2.2 yamt */
1495 1.1.1.1.2.2 yamt create_comps();
1496 1.1.1.1.2.2 yamt
1497 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1498 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uccomp_size = %ld;\n\n",
1499 1.1.1.1.2.2 yamt comps_used * 4L);
1500 1.1.1.1.2.2 yamt
1501 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uccomp_data[] = {");
1502 1.1.1.1.2.2 yamt
1503 1.1.1.1.2.2 yamt /*
1504 1.1.1.1.2.2 yamt * Now, if comps exist, write them out.
1505 1.1.1.1.2.2 yamt */
1506 1.1.1.1.2.2 yamt if (comps_used > 0) {
1507 1.1.1.1.2.2 yamt for (i=0; i<comps_used; i++) {
1508 1.1.1.1.2.2 yamt if (i) fprintf(out, ",");
1509 1.1.1.1.2.2 yamt fprintf(out, "\n\t0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx",
1510 1.1.1.1.2.2 yamt (unsigned long) comps[i].comp, (unsigned long) comps[i].count,
1511 1.1.1.1.2.2 yamt (unsigned long) comps[i].code1, (unsigned long) comps[i].code2);
1512 1.1.1.1.2.2 yamt }
1513 1.1.1.1.2.2 yamt } else {
1514 1.1.1.1.2.2 yamt fprintf(out, "\t0");
1515 1.1.1.1.2.2 yamt }
1516 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1517 1.1.1.1.2.2 yamt #else
1518 1.1.1.1.2.2 yamt /*
1519 1.1.1.1.2.2 yamt * Open the comp.dat file.
1520 1.1.1.1.2.2 yamt */
1521 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "comp.dat", opath);
1522 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1523 1.1.1.1.2.2 yamt return;
1524 1.1.1.1.2.2 yamt
1525 1.1.1.1.2.2 yamt /*
1526 1.1.1.1.2.2 yamt * Write the header.
1527 1.1.1.1.2.2 yamt */
1528 1.1.1.1.2.2 yamt hdr[1] = (ac_uint2) comps_used * 4;
1529 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1530 1.1.1.1.2.2 yamt
1531 1.1.1.1.2.2 yamt /*
1532 1.1.1.1.2.2 yamt * Write out the byte count to maintain header size.
1533 1.1.1.1.2.2 yamt */
1534 1.1.1.1.2.2 yamt bytes = comps_used * sizeof(_comp_t);
1535 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1536 1.1.1.1.2.2 yamt
1537 1.1.1.1.2.2 yamt /*
1538 1.1.1.1.2.2 yamt * Now, if comps exist, write them out.
1539 1.1.1.1.2.2 yamt */
1540 1.1.1.1.2.2 yamt if (comps_used > 0)
1541 1.1.1.1.2.2 yamt fwrite((char *) comps, sizeof(_comp_t), comps_used, out);
1542 1.1.1.1.2.2 yamt
1543 1.1.1.1.2.2 yamt fclose(out);
1544 1.1.1.1.2.2 yamt #endif
1545 1.1.1.1.2.2 yamt
1546 1.1.1.1.2.2 yamt /*****************************************************************
1547 1.1.1.1.2.2 yamt *
1548 1.1.1.1.2.2 yamt * Generate the decomposition data.
1549 1.1.1.1.2.2 yamt *
1550 1.1.1.1.2.2 yamt *****************************************************************/
1551 1.1.1.1.2.2 yamt
1552 1.1.1.1.2.2 yamt /*
1553 1.1.1.1.2.2 yamt * Fully expand all decompositions before generating the output file.
1554 1.1.1.1.2.2 yamt */
1555 1.1.1.1.2.2 yamt expand_decomp();
1556 1.1.1.1.2.2 yamt
1557 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1558 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucdcmp_size = %ld;\n\n",
1559 1.1.1.1.2.2 yamt decomps_used * 2L);
1560 1.1.1.1.2.2 yamt
1561 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucdcmp_nodes[] = {");
1562 1.1.1.1.2.2 yamt
1563 1.1.1.1.2.2 yamt if (decomps_used) {
1564 1.1.1.1.2.2 yamt /*
1565 1.1.1.1.2.2 yamt * Write the list of decomp nodes.
1566 1.1.1.1.2.2 yamt */
1567 1.1.1.1.2.2 yamt for (i = idx = 0; i < decomps_used; i++) {
1568 1.1.1.1.2.2 yamt fprintf(out, "\n\t0x%08lx, 0x%08lx,",
1569 1.1.1.1.2.2 yamt (unsigned long) decomps[i].code, (unsigned long) idx);
1570 1.1.1.1.2.2 yamt idx += decomps[i].used;
1571 1.1.1.1.2.2 yamt }
1572 1.1.1.1.2.2 yamt
1573 1.1.1.1.2.2 yamt /*
1574 1.1.1.1.2.2 yamt * Write the sentinel index as the last decomp node.
1575 1.1.1.1.2.2 yamt */
1576 1.1.1.1.2.2 yamt fprintf(out, "\n\t0x%08lx\n};\n\n", (unsigned long) idx);
1577 1.1.1.1.2.2 yamt
1578 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucdcmp_decomp[] = {");
1579 1.1.1.1.2.2 yamt /*
1580 1.1.1.1.2.2 yamt * Write the decompositions themselves.
1581 1.1.1.1.2.2 yamt */
1582 1.1.1.1.2.2 yamt k = 0;
1583 1.1.1.1.2.2 yamt for (i = 0; i < decomps_used; i++)
1584 1.1.1.1.2.2 yamt for (j=0; j<decomps[i].used; j++) {
1585 1.1.1.1.2.2 yamt if (k) fprintf(out, ",");
1586 1.1.1.1.2.2 yamt if (!(k&3)) fprintf(out,"\n\t");
1587 1.1.1.1.2.2 yamt else fprintf(out, " ");
1588 1.1.1.1.2.2 yamt k++;
1589 1.1.1.1.2.2 yamt fprintf(out, "0x%08lx", (unsigned long) decomps[i].decomp[j]);
1590 1.1.1.1.2.2 yamt }
1591 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1592 1.1.1.1.2.2 yamt }
1593 1.1.1.1.2.2 yamt #else
1594 1.1.1.1.2.2 yamt /*
1595 1.1.1.1.2.2 yamt * Open the decomp.dat file.
1596 1.1.1.1.2.2 yamt */
1597 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "decomp.dat", opath);
1598 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1599 1.1.1.1.2.2 yamt return;
1600 1.1.1.1.2.2 yamt
1601 1.1.1.1.2.2 yamt hdr[1] = decomps_used;
1602 1.1.1.1.2.2 yamt
1603 1.1.1.1.2.2 yamt /*
1604 1.1.1.1.2.2 yamt * Write the header.
1605 1.1.1.1.2.2 yamt */
1606 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1607 1.1.1.1.2.2 yamt
1608 1.1.1.1.2.2 yamt /*
1609 1.1.1.1.2.2 yamt * Write a temporary byte count which will be calculated as the
1610 1.1.1.1.2.2 yamt * decompositions are written out.
1611 1.1.1.1.2.2 yamt */
1612 1.1.1.1.2.2 yamt bytes = 0;
1613 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1614 1.1.1.1.2.2 yamt
1615 1.1.1.1.2.2 yamt if (decomps_used) {
1616 1.1.1.1.2.2 yamt /*
1617 1.1.1.1.2.2 yamt * Write the list of decomp nodes.
1618 1.1.1.1.2.2 yamt */
1619 1.1.1.1.2.2 yamt for (i = idx = 0; i < decomps_used; i++) {
1620 1.1.1.1.2.2 yamt fwrite((char *) &decomps[i].code, sizeof(ac_uint4), 1, out);
1621 1.1.1.1.2.2 yamt fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
1622 1.1.1.1.2.2 yamt idx += decomps[i].used;
1623 1.1.1.1.2.2 yamt }
1624 1.1.1.1.2.2 yamt
1625 1.1.1.1.2.2 yamt /*
1626 1.1.1.1.2.2 yamt * Write the sentinel index as the last decomp node.
1627 1.1.1.1.2.2 yamt */
1628 1.1.1.1.2.2 yamt fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
1629 1.1.1.1.2.2 yamt
1630 1.1.1.1.2.2 yamt /*
1631 1.1.1.1.2.2 yamt * Write the decompositions themselves.
1632 1.1.1.1.2.2 yamt */
1633 1.1.1.1.2.2 yamt for (i = 0; i < decomps_used; i++)
1634 1.1.1.1.2.2 yamt fwrite((char *) decomps[i].decomp, sizeof(ac_uint4),
1635 1.1.1.1.2.2 yamt decomps[i].used, out);
1636 1.1.1.1.2.2 yamt
1637 1.1.1.1.2.2 yamt /*
1638 1.1.1.1.2.2 yamt * Seek back to the beginning and write the byte count.
1639 1.1.1.1.2.2 yamt */
1640 1.1.1.1.2.2 yamt bytes = (sizeof(ac_uint4) * idx) +
1641 1.1.1.1.2.2 yamt (sizeof(ac_uint4) * ((hdr[1] << 1) + 1));
1642 1.1.1.1.2.2 yamt fseek(out, sizeof(ac_uint2) << 1, 0L);
1643 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1644 1.1.1.1.2.2 yamt
1645 1.1.1.1.2.2 yamt fclose(out);
1646 1.1.1.1.2.2 yamt }
1647 1.1.1.1.2.2 yamt #endif
1648 1.1.1.1.2.2 yamt
1649 1.1.1.1.2.2 yamt #ifdef HARDCODE_DATA
1650 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uckdcmp_size = %ld;\n\n",
1651 1.1.1.1.2.2 yamt kdecomps_used * 2L);
1652 1.1.1.1.2.2 yamt
1653 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uckdcmp_nodes[] = {");
1654 1.1.1.1.2.2 yamt
1655 1.1.1.1.2.2 yamt if (kdecomps_used) {
1656 1.1.1.1.2.2 yamt /*
1657 1.1.1.1.2.2 yamt * Write the list of kdecomp nodes.
1658 1.1.1.1.2.2 yamt */
1659 1.1.1.1.2.2 yamt for (i = idx = 0; i < kdecomps_used; i++) {
1660 1.1.1.1.2.2 yamt fprintf(out, "\n\t0x%08lx, 0x%08lx,",
1661 1.1.1.1.2.2 yamt (unsigned long) kdecomps[i].code, (unsigned long) idx);
1662 1.1.1.1.2.2 yamt idx += kdecomps[i].used;
1663 1.1.1.1.2.2 yamt }
1664 1.1.1.1.2.2 yamt
1665 1.1.1.1.2.2 yamt /*
1666 1.1.1.1.2.2 yamt * Write the sentinel index as the last decomp node.
1667 1.1.1.1.2.2 yamt */
1668 1.1.1.1.2.2 yamt fprintf(out, "\n\t0x%08lx\n};\n\n", (unsigned long) idx);
1669 1.1.1.1.2.2 yamt
1670 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uckdcmp_decomp[] = {");
1671 1.1.1.1.2.2 yamt
1672 1.1.1.1.2.2 yamt /*
1673 1.1.1.1.2.2 yamt * Write the decompositions themselves.
1674 1.1.1.1.2.2 yamt */
1675 1.1.1.1.2.2 yamt k = 0;
1676 1.1.1.1.2.2 yamt for (i = 0; i < kdecomps_used; i++)
1677 1.1.1.1.2.2 yamt for (j=0; j<kdecomps[i].used; j++) {
1678 1.1.1.1.2.2 yamt if (k) fprintf(out, ",");
1679 1.1.1.1.2.2 yamt if (!(k&3)) fprintf(out,"\n\t");
1680 1.1.1.1.2.2 yamt else fprintf(out, " ");
1681 1.1.1.1.2.2 yamt k++;
1682 1.1.1.1.2.2 yamt fprintf(out, "0x%08lx", (unsigned long) kdecomps[i].decomp[j]);
1683 1.1.1.1.2.2 yamt }
1684 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1685 1.1.1.1.2.2 yamt }
1686 1.1.1.1.2.2 yamt #else
1687 1.1.1.1.2.2 yamt /*
1688 1.1.1.1.2.2 yamt * Open the kdecomp.dat file.
1689 1.1.1.1.2.2 yamt */
1690 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "kdecomp.dat", opath);
1691 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1692 1.1.1.1.2.2 yamt return;
1693 1.1.1.1.2.2 yamt
1694 1.1.1.1.2.2 yamt hdr[1] = kdecomps_used;
1695 1.1.1.1.2.2 yamt
1696 1.1.1.1.2.2 yamt /*
1697 1.1.1.1.2.2 yamt * Write the header.
1698 1.1.1.1.2.2 yamt */
1699 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1700 1.1.1.1.2.2 yamt
1701 1.1.1.1.2.2 yamt /*
1702 1.1.1.1.2.2 yamt * Write a temporary byte count which will be calculated as the
1703 1.1.1.1.2.2 yamt * decompositions are written out.
1704 1.1.1.1.2.2 yamt */
1705 1.1.1.1.2.2 yamt bytes = 0;
1706 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1707 1.1.1.1.2.2 yamt
1708 1.1.1.1.2.2 yamt if (kdecomps_used) {
1709 1.1.1.1.2.2 yamt /*
1710 1.1.1.1.2.2 yamt * Write the list of kdecomp nodes.
1711 1.1.1.1.2.2 yamt */
1712 1.1.1.1.2.2 yamt for (i = idx = 0; i < kdecomps_used; i++) {
1713 1.1.1.1.2.2 yamt fwrite((char *) &kdecomps[i].code, sizeof(ac_uint4), 1, out);
1714 1.1.1.1.2.2 yamt fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
1715 1.1.1.1.2.2 yamt idx += kdecomps[i].used;
1716 1.1.1.1.2.2 yamt }
1717 1.1.1.1.2.2 yamt
1718 1.1.1.1.2.2 yamt /*
1719 1.1.1.1.2.2 yamt * Write the sentinel index as the last decomp node.
1720 1.1.1.1.2.2 yamt */
1721 1.1.1.1.2.2 yamt fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
1722 1.1.1.1.2.2 yamt
1723 1.1.1.1.2.2 yamt /*
1724 1.1.1.1.2.2 yamt * Write the decompositions themselves.
1725 1.1.1.1.2.2 yamt */
1726 1.1.1.1.2.2 yamt for (i = 0; i < kdecomps_used; i++)
1727 1.1.1.1.2.2 yamt fwrite((char *) kdecomps[i].decomp, sizeof(ac_uint4),
1728 1.1.1.1.2.2 yamt kdecomps[i].used, out);
1729 1.1.1.1.2.2 yamt
1730 1.1.1.1.2.2 yamt /*
1731 1.1.1.1.2.2 yamt * Seek back to the beginning and write the byte count.
1732 1.1.1.1.2.2 yamt */
1733 1.1.1.1.2.2 yamt bytes = (sizeof(ac_uint4) * idx) +
1734 1.1.1.1.2.2 yamt (sizeof(ac_uint4) * ((hdr[1] << 1) + 1));
1735 1.1.1.1.2.2 yamt fseek(out, sizeof(ac_uint2) << 1, 0L);
1736 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1737 1.1.1.1.2.2 yamt
1738 1.1.1.1.2.2 yamt fclose(out);
1739 1.1.1.1.2.2 yamt }
1740 1.1.1.1.2.2 yamt #endif
1741 1.1.1.1.2.2 yamt
1742 1.1.1.1.2.2 yamt /*****************************************************************
1743 1.1.1.1.2.2 yamt *
1744 1.1.1.1.2.2 yamt * Generate the combining class data.
1745 1.1.1.1.2.2 yamt *
1746 1.1.1.1.2.2 yamt *****************************************************************/
1747 1.1.1.1.2.2 yamt #ifdef HARDCODE_DATA
1748 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uccmcl_size = %ld;\n\n", (long) ccl_used);
1749 1.1.1.1.2.2 yamt
1750 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _uccmcl_nodes[] = {");
1751 1.1.1.1.2.2 yamt
1752 1.1.1.1.2.2 yamt if (ccl_used > 0) {
1753 1.1.1.1.2.2 yamt /*
1754 1.1.1.1.2.2 yamt * Write the combining class ranges out.
1755 1.1.1.1.2.2 yamt */
1756 1.1.1.1.2.2 yamt for (i = 0; i<ccl_used; i++) {
1757 1.1.1.1.2.2 yamt if (i) fprintf(out, ",");
1758 1.1.1.1.2.2 yamt if (!(i&3)) fprintf(out, "\n\t");
1759 1.1.1.1.2.2 yamt else fprintf(out, " ");
1760 1.1.1.1.2.2 yamt fprintf(out, "0x%08lx", (unsigned long) ccl[i]);
1761 1.1.1.1.2.2 yamt }
1762 1.1.1.1.2.2 yamt } else {
1763 1.1.1.1.2.2 yamt fprintf(out, "\t0");
1764 1.1.1.1.2.2 yamt }
1765 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1766 1.1.1.1.2.2 yamt #else
1767 1.1.1.1.2.2 yamt /*
1768 1.1.1.1.2.2 yamt * Open the cmbcl.dat file.
1769 1.1.1.1.2.2 yamt */
1770 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "cmbcl.dat", opath);
1771 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1772 1.1.1.1.2.2 yamt return;
1773 1.1.1.1.2.2 yamt
1774 1.1.1.1.2.2 yamt /*
1775 1.1.1.1.2.2 yamt * Set the number of ranges used. Each range has a combining class which
1776 1.1.1.1.2.2 yamt * means each entry is a 3-tuple.
1777 1.1.1.1.2.2 yamt */
1778 1.1.1.1.2.2 yamt hdr[1] = ccl_used / 3;
1779 1.1.1.1.2.2 yamt
1780 1.1.1.1.2.2 yamt /*
1781 1.1.1.1.2.2 yamt * Write the header.
1782 1.1.1.1.2.2 yamt */
1783 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1784 1.1.1.1.2.2 yamt
1785 1.1.1.1.2.2 yamt /*
1786 1.1.1.1.2.2 yamt * Write out the byte count to maintain header size.
1787 1.1.1.1.2.2 yamt */
1788 1.1.1.1.2.2 yamt bytes = ccl_used * sizeof(ac_uint4);
1789 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1790 1.1.1.1.2.2 yamt
1791 1.1.1.1.2.2 yamt if (ccl_used > 0)
1792 1.1.1.1.2.2 yamt /*
1793 1.1.1.1.2.2 yamt * Write the combining class ranges out.
1794 1.1.1.1.2.2 yamt */
1795 1.1.1.1.2.2 yamt fwrite((char *) ccl, sizeof(ac_uint4), ccl_used, out);
1796 1.1.1.1.2.2 yamt
1797 1.1.1.1.2.2 yamt fclose(out);
1798 1.1.1.1.2.2 yamt #endif
1799 1.1.1.1.2.2 yamt
1800 1.1.1.1.2.2 yamt /*****************************************************************
1801 1.1.1.1.2.2 yamt *
1802 1.1.1.1.2.2 yamt * Generate the number data.
1803 1.1.1.1.2.2 yamt *
1804 1.1.1.1.2.2 yamt *****************************************************************/
1805 1.1.1.1.2.2 yamt
1806 1.1.1.1.2.2 yamt #if HARDCODE_DATA
1807 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucnum_size = %lu;\n\n",
1808 1.1.1.1.2.2 yamt (unsigned long)ncodes_used<<1);
1809 1.1.1.1.2.2 yamt
1810 1.1.1.1.2.2 yamt fprintf(out, PREF "ac_uint4 _ucnum_nodes[] = {");
1811 1.1.1.1.2.2 yamt
1812 1.1.1.1.2.2 yamt /*
1813 1.1.1.1.2.2 yamt * Now, if number mappings exist, write them out.
1814 1.1.1.1.2.2 yamt */
1815 1.1.1.1.2.2 yamt if (ncodes_used > 0) {
1816 1.1.1.1.2.2 yamt for (i = 0; i<ncodes_used; i++) {
1817 1.1.1.1.2.2 yamt if (i) fprintf(out, ",");
1818 1.1.1.1.2.2 yamt if (!(i&1)) fprintf(out, "\n\t");
1819 1.1.1.1.2.2 yamt else fprintf(out, " ");
1820 1.1.1.1.2.2 yamt fprintf(out, "0x%08lx, 0x%08lx",
1821 1.1.1.1.2.2 yamt (unsigned long) ncodes[i].code, (unsigned long) ncodes[i].idx);
1822 1.1.1.1.2.2 yamt }
1823 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1824 1.1.1.1.2.2 yamt
1825 1.1.1.1.2.2 yamt fprintf(out, PREF "short _ucnum_vals[] = {");
1826 1.1.1.1.2.2 yamt for (i = 0; i<nums_used; i++) {
1827 1.1.1.1.2.2 yamt if (i) fprintf(out, ",");
1828 1.1.1.1.2.2 yamt if (!(i&3)) fprintf(out, "\n\t");
1829 1.1.1.1.2.2 yamt else fprintf(out, " ");
1830 1.1.1.1.2.2 yamt if (nums[i].numerator < 0) {
1831 1.1.1.1.2.2 yamt fprintf(out, "%6d, 0x%04x",
1832 1.1.1.1.2.2 yamt nums[i].numerator, nums[i].denominator);
1833 1.1.1.1.2.2 yamt } else {
1834 1.1.1.1.2.2 yamt fprintf(out, "0x%04x, 0x%04x",
1835 1.1.1.1.2.2 yamt nums[i].numerator, nums[i].denominator);
1836 1.1.1.1.2.2 yamt }
1837 1.1.1.1.2.2 yamt }
1838 1.1.1.1.2.2 yamt fprintf(out, "\n};\n\n");
1839 1.1.1.1.2.2 yamt }
1840 1.1.1.1.2.2 yamt #else
1841 1.1.1.1.2.2 yamt /*
1842 1.1.1.1.2.2 yamt * Open the num.dat file.
1843 1.1.1.1.2.2 yamt */
1844 1.1.1.1.2.2 yamt snprintf(path, sizeof path, "%s" LDAP_DIRSEP "num.dat", opath);
1845 1.1.1.1.2.2 yamt if ((out = fopen(path, "wb")) == 0)
1846 1.1.1.1.2.2 yamt return;
1847 1.1.1.1.2.2 yamt
1848 1.1.1.1.2.2 yamt /*
1849 1.1.1.1.2.2 yamt * The count part of the header will be the total number of codes that
1850 1.1.1.1.2.2 yamt * have numbers.
1851 1.1.1.1.2.2 yamt */
1852 1.1.1.1.2.2 yamt hdr[1] = (ac_uint2) (ncodes_used << 1);
1853 1.1.1.1.2.2 yamt bytes = (ncodes_used * sizeof(_codeidx_t)) + (nums_used * sizeof(_num_t));
1854 1.1.1.1.2.2 yamt
1855 1.1.1.1.2.2 yamt /*
1856 1.1.1.1.2.2 yamt * Write the header.
1857 1.1.1.1.2.2 yamt */
1858 1.1.1.1.2.2 yamt fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
1859 1.1.1.1.2.2 yamt
1860 1.1.1.1.2.2 yamt /*
1861 1.1.1.1.2.2 yamt * Write out the byte count to maintain header size.
1862 1.1.1.1.2.2 yamt */
1863 1.1.1.1.2.2 yamt fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
1864 1.1.1.1.2.2 yamt
1865 1.1.1.1.2.2 yamt /*
1866 1.1.1.1.2.2 yamt * Now, if number mappings exist, write them out.
1867 1.1.1.1.2.2 yamt */
1868 1.1.1.1.2.2 yamt if (ncodes_used > 0) {
1869 1.1.1.1.2.2 yamt fwrite((char *) ncodes, sizeof(_codeidx_t), ncodes_used, out);
1870 1.1.1.1.2.2 yamt fwrite((char *) nums, sizeof(_num_t), nums_used, out);
1871 1.1.1.1.2.2 yamt }
1872 1.1.1.1.2.2 yamt #endif
1873 1.1.1.1.2.2 yamt
1874 1.1.1.1.2.2 yamt fclose(out);
1875 1.1.1.1.2.2 yamt }
1876 1.1.1.1.2.2 yamt
1877 1.1.1.1.2.2 yamt static void
1878 1.1.1.1.2.2 yamt usage(char *prog)
1879 1.1.1.1.2.2 yamt {
1880 1.1.1.1.2.2 yamt fprintf(stderr,
1881 1.1.1.1.2.2 yamt "Usage: %s [-o output-directory|-x composition-exclusions]", prog);
1882 1.1.1.1.2.2 yamt fprintf(stderr, " datafile1 datafile2 ...\n\n");
1883 1.1.1.1.2.2 yamt fprintf(stderr,
1884 1.1.1.1.2.2 yamt "-o output-directory\n\t\tWrite the output files to a different");
1885 1.1.1.1.2.2 yamt fprintf(stderr, " directory (default: .).\n");
1886 1.1.1.1.2.2 yamt fprintf(stderr,
1887 1.1.1.1.2.2 yamt "-x composition-exclusion\n\t\tFile of composition codes");
1888 1.1.1.1.2.2 yamt fprintf(stderr, " that should be excluded.\n");
1889 1.1.1.1.2.2 yamt exit(1);
1890 1.1.1.1.2.2 yamt }
1891 1.1.1.1.2.2 yamt
1892 1.1.1.1.2.2 yamt int
1893 1.1.1.1.2.2 yamt main(int argc, char *argv[])
1894 1.1.1.1.2.2 yamt {
1895 1.1.1.1.2.2 yamt FILE *in;
1896 1.1.1.1.2.2 yamt char *prog, *opath;
1897 1.1.1.1.2.2 yamt
1898 1.1.1.1.2.2 yamt prog = lutil_progname( "ucgendat", argc, argv );
1899 1.1.1.1.2.2 yamt
1900 1.1.1.1.2.2 yamt opath = 0;
1901 1.1.1.1.2.2 yamt in = stdin;
1902 1.1.1.1.2.2 yamt
1903 1.1.1.1.2.2 yamt argc--;
1904 1.1.1.1.2.2 yamt argv++;
1905 1.1.1.1.2.2 yamt
1906 1.1.1.1.2.2 yamt while (argc > 0) {
1907 1.1.1.1.2.2 yamt if (argv[0][0] == '-') {
1908 1.1.1.1.2.2 yamt switch (argv[0][1]) {
1909 1.1.1.1.2.2 yamt case 'o':
1910 1.1.1.1.2.2 yamt argc--;
1911 1.1.1.1.2.2 yamt argv++;
1912 1.1.1.1.2.2 yamt opath = argv[0];
1913 1.1.1.1.2.2 yamt break;
1914 1.1.1.1.2.2 yamt case 'x':
1915 1.1.1.1.2.2 yamt argc--;
1916 1.1.1.1.2.2 yamt argv++;
1917 1.1.1.1.2.2 yamt if ((in = fopen(argv[0], "r")) == 0)
1918 1.1.1.1.2.2 yamt fprintf(stderr,
1919 1.1.1.1.2.2 yamt "%s: unable to open composition exclusion file %s\n",
1920 1.1.1.1.2.2 yamt prog, argv[0]);
1921 1.1.1.1.2.2 yamt else {
1922 1.1.1.1.2.2 yamt read_compexdata(in);
1923 1.1.1.1.2.2 yamt fclose(in);
1924 1.1.1.1.2.2 yamt in = 0;
1925 1.1.1.1.2.2 yamt }
1926 1.1.1.1.2.2 yamt break;
1927 1.1.1.1.2.2 yamt default:
1928 1.1.1.1.2.2 yamt usage(prog);
1929 1.1.1.1.2.2 yamt }
1930 1.1.1.1.2.2 yamt } else {
1931 1.1.1.1.2.2 yamt if (in != stdin && in != NULL)
1932 1.1.1.1.2.2 yamt fclose(in);
1933 1.1.1.1.2.2 yamt if ((in = fopen(argv[0], "r")) == 0)
1934 1.1.1.1.2.2 yamt fprintf(stderr, "%s: unable to open ctype file %s\n",
1935 1.1.1.1.2.2 yamt prog, argv[0]);
1936 1.1.1.1.2.2 yamt else {
1937 1.1.1.1.2.2 yamt read_cdata(in);
1938 1.1.1.1.2.2 yamt fclose(in);
1939 1.1.1.1.2.2 yamt in = 0;
1940 1.1.1.1.2.2 yamt }
1941 1.1.1.1.2.2 yamt }
1942 1.1.1.1.2.2 yamt argc--;
1943 1.1.1.1.2.2 yamt argv++;
1944 1.1.1.1.2.2 yamt }
1945 1.1.1.1.2.2 yamt
1946 1.1.1.1.2.2 yamt if (opath == 0)
1947 1.1.1.1.2.2 yamt opath = ".";
1948 1.1.1.1.2.2 yamt write_cdata(opath);
1949 1.1.1.1.2.2 yamt
1950 1.1.1.1.2.2 yamt return 0;
1951 1.1.1.1.2.2 yamt }
1952