2 * Copyright 1999 Computing Research Labs, New Mexico State University
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
20 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 static char rcsid[] __attribute__ ((unused)) = "$Id: ucgendat.c,v 1.3 1999/10/07 20:49:56 mleisher Exp $";
26 static char rcsid[] = "$Id: ucgendat.c,v 1.3 1999/10/07 20:49:56 mleisher Exp $";
34 #include <ac/string.h>
35 #include <ac/unistd.h>
37 #define ishdigit(cc) (((cc) >= '0' && (cc) <= '9') ||\
38 ((cc) >= 'A' && (cc) <= 'F') ||\
39 ((cc) >= 'a' && (cc) <= 'f'))
42 * A header written to the output file with the byte-order-mark and the number
45 static unsigned short hdr[2] = {0xfeff, 0};
48 #define NEEDPROPS (NUMPROPS + (4 - (NUMPROPS & 3)))
56 * List of properties expected to be found in the Unicode Character Database
57 * including some implementation specific properties.
59 * The implementation specific properties are:
60 * Cm = Composed (can be decomposed)
62 * Sy = Symmetric (has left and right forms)
67 * Cp = Defined character
69 static _prop_t props[NUMPROPS] = {
70 {"Mn", 2}, {"Mc", 2}, {"Me", 2}, {"Nd", 2}, {"Nl", 2}, {"No", 2},
71 {"Zs", 2}, {"Zl", 2}, {"Zp", 2}, {"Cc", 2}, {"Cf", 2}, {"Cs", 2},
72 {"Co", 2}, {"Cn", 2}, {"Lu", 2}, {"Ll", 2}, {"Lt", 2}, {"Lm", 2},
73 {"Lo", 2}, {"Pc", 2}, {"Pd", 2}, {"Ps", 2}, {"Pe", 2}, {"Po", 2},
74 {"Sm", 2}, {"Sc", 2}, {"Sk", 2}, {"So", 2}, {"L", 1}, {"R", 1},
75 {"EN", 2}, {"ES", 2}, {"ET", 2}, {"AN", 2}, {"CS", 2}, {"B", 1},
76 {"S", 1}, {"WS", 2}, {"ON", 2},
77 {"Cm", 2}, {"Nb", 2}, {"Sy", 2}, {"Hd", 2}, {"Qm", 2}, {"Mr", 2},
78 {"Ss", 2}, {"Cp", 2}, {"Pi", 2}, {"Pf", 2}
82 unsigned long *ranges;
87 static _ranges_t proptbl[NUMPROPS];
90 * Make sure this array is sized to be on a 4-byte boundary at compile time.
92 static unsigned short propcnt[NEEDPROPS];
95 * Array used to collect a decomposition before adding it to the decomposition
98 static unsigned long dectmp[64];
99 static unsigned long dectmp_size;
105 unsigned long *decomp;
109 * List of decomposition. Created and expanded in order as the characters are
112 static _decomp_t *decomps;
113 static unsigned long decomps_used;
114 static unsigned long decomps_size;
117 * Types and lists for handling lists of case mappings.
121 unsigned long other1;
122 unsigned long other2;
125 static _case_t *upper;
126 static _case_t *lower;
127 static _case_t *title;
128 static unsigned long upper_used;
129 static unsigned long upper_size;
130 static unsigned long lower_used;
131 static unsigned long lower_size;
132 static unsigned long title_used;
133 static unsigned long title_size;
136 * Array used to collect case mappings before adding them to a list.
138 static unsigned long cases[3];
141 * An array to hold ranges for combining classes.
143 static unsigned long *ccl;
144 static unsigned long ccl_used;
145 static unsigned long ccl_size;
148 * Structures for handling numbers.
161 * Arrays to hold the mapping of codes to numbers.
163 static _codeidx_t *ncodes;
164 static unsigned long ncodes_used;
165 static unsigned long ncodes_size;
168 static unsigned long nums_used;
169 static unsigned long nums_size;
172 * Array for holding numbers.
175 static unsigned long nums_used;
176 static unsigned long nums_size;
179 add_range(unsigned long start, unsigned long end, char *p1, char *p2)
185 for (k = 0; k < 2; k++) {
197 for (i = 0; i < NUMPROPS; i++) {
198 if (props[i].len == len && memcmp(props[i].name, name, len) == 0)
208 * Resize the range list if necessary.
210 if (rlp->used == rlp->size) {
212 rlp->ranges = (unsigned long *)
213 malloc(sizeof(unsigned long) << 3);
215 rlp->ranges = (unsigned long *)
216 realloc((char *) rlp->ranges,
217 sizeof(unsigned long) * (rlp->size + 8));
222 * If this is the first code for this property list, just add it
225 if (rlp->used == 0) {
226 rlp->ranges[0] = start;
227 rlp->ranges[1] = end;
233 * Optimize the case of adding the range to the end.
236 if (start > rlp->ranges[j]) {
238 rlp->ranges[j++] = start;
239 rlp->ranges[j++] = end;
245 * Need to locate the insertion point.
248 i < rlp->used && start > rlp->ranges[i + 1] + 1; i += 2) ;
251 * If the start value lies in the current range, then simply set the
252 * new end point of the range to the end value passed as a parameter.
254 if (rlp->ranges[i] <= start && start <= rlp->ranges[i + 1] + 1) {
255 rlp->ranges[i + 1] = end;
260 * Shift following values up by two.
262 for (j = rlp->used; j > i; j -= 2) {
263 rlp->ranges[j] = rlp->ranges[j - 2];
264 rlp->ranges[j + 1] = rlp->ranges[j - 1];
268 * Add the new range at the insertion point.
270 rlp->ranges[i] = start;
271 rlp->ranges[i + 1] = end;
277 ordered_range_insert(unsigned long c, char *name, int len)
287 * Deal with directionality codes introduced in Unicode 3.0.
290 if (memcmp(name, "AL", 2) == 0) {
292 * Mark the Arabic letters as having RTL directionality.
296 } else if (memcmp(name, "BN", 2) == 0) {
298 * Mark the control characters as being Other Neutrals.
303 } else if (len == 3 &&
304 (memcmp(name, "NSM", 3) == 0 || memcmp(name, "PDF", 3) == 0 ||
305 memcmp(name, "LRE", 3) == 0 || memcmp(name, "LRO", 3) == 0 ||
306 memcmp(name, "RLE", 3) == 0 || memcmp(name, "RLO", 3) == 0)) {
308 * Mark all of these as Other Neutral to preserve compatibility with
315 for (i = 0; i < NUMPROPS; i++) {
316 if (props[i].len == len && memcmp(props[i].name, name, len) == 0)
324 * Have a match, so insert the code in order.
329 * Resize the range list if necessary.
331 if (rlp->used == rlp->size) {
333 rlp->ranges = (unsigned long *)
334 malloc(sizeof(unsigned long) << 3);
336 rlp->ranges = (unsigned long *)
337 realloc((char *) rlp->ranges,
338 sizeof(unsigned long) * (rlp->size + 8));
343 * If this is the first code for this property list, just add it
346 if (rlp->used == 0) {
347 rlp->ranges[0] = rlp->ranges[1] = c;
353 * Optimize the cases of extending the last range and adding new ranges to
358 s = rlp->ranges[j - 1];
362 * Extend the last range.
370 * Start another range on the end.
373 rlp->ranges[j] = rlp->ranges[j + 1] = c;
380 * The code is a duplicate of a code in the last range, so just return.
385 * The code should be inserted somewhere before the last range in the
386 * list. Locate the insertion point.
389 i < rlp->used && c > rlp->ranges[i + 1] + 1; i += 2) ;
392 e = rlp->ranges[i + 1];
396 * Simply extend the current range.
398 rlp->ranges[i + 1] = c;
401 * Add a new entry before the current location. Shift all entries
402 * before the current one up by one to make room.
404 for (j = rlp->used; j > i; j -= 2) {
405 rlp->ranges[j] = rlp->ranges[j - 2];
406 rlp->ranges[j + 1] = rlp->ranges[j - 1];
408 rlp->ranges[i] = rlp->ranges[i + 1] = c;
415 add_decomp(unsigned long code)
417 unsigned long i, j, size;
420 * Add the code to the composite property.
422 ordered_range_insert(code, "Cm", 2);
425 * Locate the insertion point for the code.
427 for (i = 0; i < decomps_used && code > decomps[i].code; i++) ;
430 * Allocate space for a new decomposition.
432 if (decomps_used == decomps_size) {
433 if (decomps_size == 0)
434 decomps = (_decomp_t *) malloc(sizeof(_decomp_t) << 3);
436 decomps = (_decomp_t *)
437 realloc((char *) decomps,
438 sizeof(_decomp_t) * (decomps_size + 8));
439 (void) memset((char *) (decomps + decomps_size), 0,
440 sizeof(_decomp_t) << 3);
444 if (i < decomps_used && code != decomps[i].code) {
446 * Shift the decomps up by one if the codes don't match.
448 for (j = decomps_used; j > i; j--)
449 (void) memcpy((char *) &decomps[j], (char *) &decomps[j - 1],
454 * Insert or replace a decomposition.
456 size = dectmp_size + (4 - (dectmp_size & 3));
457 if (decomps[i].size < size) {
458 if (decomps[i].size == 0)
459 decomps[i].decomp = (unsigned long *)
460 malloc(sizeof(unsigned long) * size);
462 decomps[i].decomp = (unsigned long *)
463 realloc((char *) decomps[i].decomp,
464 sizeof(unsigned long) * size);
465 decomps[i].size = size;
468 if (decomps[i].code != code)
471 decomps[i].code = code;
472 decomps[i].used = dectmp_size;
473 (void) memcpy((char *) decomps[i].decomp, (char *) dectmp,
474 sizeof(unsigned long) * dectmp_size);
479 add_title(unsigned long code)
484 * Always map the code to itself.
488 if (title_used == title_size) {
490 title = (_case_t *) malloc(sizeof(_case_t) << 3);
492 title = (_case_t *) realloc((char *) title,
493 sizeof(_case_t) * (title_size + 8));
498 * Locate the insertion point.
500 for (i = 0; i < title_used && code > title[i].key; i++) ;
502 if (i < title_used) {
504 * Shift the array up by one.
506 for (j = title_used; j > i; j--)
507 (void) memcpy((char *) &title[j], (char *) &title[j - 1],
511 title[i].key = cases[2]; /* Title */
512 title[i].other1 = cases[0]; /* Upper */
513 title[i].other2 = cases[1]; /* Lower */
519 add_upper(unsigned long code)
524 * Always map the code to itself.
529 * If the title case character is not present, then make it the same as
535 if (upper_used == upper_size) {
537 upper = (_case_t *) malloc(sizeof(_case_t) << 3);
539 upper = (_case_t *) realloc((char *) upper,
540 sizeof(_case_t) * (upper_size + 8));
545 * Locate the insertion point.
547 for (i = 0; i < upper_used && code > upper[i].key; i++) ;
549 if (i < upper_used) {
551 * Shift the array up by one.
553 for (j = upper_used; j > i; j--)
554 (void) memcpy((char *) &upper[j], (char *) &upper[j - 1],
558 upper[i].key = cases[0]; /* Upper */
559 upper[i].other1 = cases[1]; /* Lower */
560 upper[i].other2 = cases[2]; /* Title */
566 add_lower(unsigned long code)
571 * Always map the code to itself.
576 * If the title case character is empty, then make it the same as the
582 if (lower_used == lower_size) {
584 lower = (_case_t *) malloc(sizeof(_case_t) << 3);
586 lower = (_case_t *) realloc((char *) lower,
587 sizeof(_case_t) * (lower_size + 8));
592 * Locate the insertion point.
594 for (i = 0; i < lower_used && code > lower[i].key; i++) ;
596 if (i < lower_used) {
598 * Shift the array up by one.
600 for (j = lower_used; j > i; j--)
601 (void) memcpy((char *) &lower[j], (char *) &lower[j - 1],
605 lower[i].key = cases[1]; /* Lower */
606 lower[i].other1 = cases[0]; /* Upper */
607 lower[i].other2 = cases[2]; /* Title */
613 ordered_ccl_insert(unsigned long c, unsigned long ccl_code)
617 if (ccl_used == ccl_size) {
619 ccl = (unsigned long *) malloc(sizeof(unsigned long) * 24);
621 ccl = (unsigned long *)
622 realloc((char *) ccl, sizeof(unsigned long) * (ccl_size + 24));
627 * Optimize adding the first item.
637 * Handle the special case of extending the range on the end. This
638 * requires that the combining class codes are the same.
640 if (ccl_code == ccl[ccl_used - 1] && c == ccl[ccl_used - 2] + 1) {
641 ccl[ccl_used - 2] = c;
646 * Handle the special case of adding another range on the end.
648 if (c > ccl[ccl_used - 2] + 1 ||
649 (c == ccl[ccl_used - 2] + 1 && ccl_code != ccl[ccl_used - 1])) {
652 ccl[ccl_used++] = ccl_code;
657 * Locate either the insertion point or range for the code.
659 for (i = 0; i < ccl_used && c > ccl[i + 1] + 1; i += 3) ;
661 if (ccl_code == ccl[i + 2] && c == ccl[i + 1] + 1) {
663 * Extend an existing range.
667 } else if (c < ccl[i]) {
669 * Start a new range before the current location.
671 for (j = ccl_used; j > i; j -= 3) {
673 ccl[j - 1] = ccl[j - 4];
674 ccl[j - 2] = ccl[j - 5];
676 ccl[i] = ccl[i + 1] = c;
677 ccl[i + 2] = ccl_code;
682 * Adds a number if it does not already exist and returns an index value
686 make_number(short num, short denom)
691 * Determine if the number already exists.
693 for (n = 0; n < nums_used; n++) {
694 if (nums[n].numerator == num && nums[n].denominator == denom)
698 if (nums_used == nums_size) {
700 nums = (_num_t *) malloc(sizeof(_num_t) << 3);
702 nums = (_num_t *) realloc((char *) nums,
703 sizeof(_num_t) * (nums_size + 8));
708 nums[n].numerator = num;
709 nums[n].denominator = denom;
715 add_number(unsigned long code, short num, short denom)
720 * Insert the code in order.
722 for (i = 0; i < ncodes_used && code > ncodes[i].code; i++) ;
725 * Handle the case of the codes matching and simply replace the number
726 * that was there before.
728 if (ncodes_used > 0 && code == ncodes[i].code) {
729 ncodes[i].idx = make_number(num, denom);
734 * Resize the array if necessary.
736 if (ncodes_used == ncodes_size) {
737 if (ncodes_size == 0)
738 ncodes = (_codeidx_t *) malloc(sizeof(_codeidx_t) << 3);
740 ncodes = (_codeidx_t *)
741 realloc((char *) ncodes, sizeof(_codeidx_t) * (ncodes_size + 8));
747 * Shift things around to insert the code if necessary.
749 if (i < ncodes_used) {
750 for (j = ncodes_used; j > i; j--) {
751 ncodes[j].code = ncodes[j - 1].code;
752 ncodes[j].idx = ncodes[j - 1].idx;
755 ncodes[i].code = code;
756 ncodes[i].idx = make_number(num, denom);
762 * This routine assumes that the line is a valid Unicode Character Database
768 unsigned long i, lineno, skip, code, ccl_code;
769 short wnum, neg, number[2];
770 char line[512], *s, *e;
773 while (fscanf(in, "%[^\n]\n", line) != EOF) {
777 * Skip blank lines and lines that start with a '#'.
779 if (line[0] == 0 || line[0] == '#')
783 * If lines need to be skipped, do it here.
791 * Collect the code. The code can be up to 6 hex digits in length to
792 * allow surrogates to be specified.
794 for (s = line, i = code = 0; *s != ';' && i < 6; i++, s++) {
796 if (*s >= '0' && *s <= '9')
798 else if (*s >= 'A' && *s <= 'F')
799 code += (*s - 'A') + 10;
800 else if (*s >= 'a' && *s <= 'f')
801 code += (*s - 'a') + 10;
805 * Handle the following special cases:
806 * 1. 4E00-9FA5 CJK Ideographs.
807 * 2. AC00-D7A3 Hangul Syllables.
808 * 3. D800-DFFF Surrogates.
809 * 4. E000-F8FF Private Use Area.
810 * 5. F900-FA2D Han compatibility.
815 * The Han ideographs.
817 add_range(0x4e00, 0x9fff, "Lo", "L");
820 * Add the characters to the defined category.
822 add_range(0x4e00, 0x9fa5, "Cp", 0);
828 * The Hangul syllables.
830 add_range(0xac00, 0xd7a3, "Lo", "L");
833 * Add the characters to the defined category.
835 add_range(0xac00, 0xd7a3, "Cp", 0);
841 * Make a range of all surrogates and assume some default
844 add_range(0x010000, 0x10ffff, "Cs", "L");
849 * The Private Use area. Add with a default set of properties.
851 add_range(0xe000, 0xf8ff, "Co", "L");
856 * The CJK compatibility area.
858 add_range(0xf900, 0xfaff, "Lo", "L");
861 * Add the characters to the defined category.
863 add_range(0xf900, 0xfaff, "Cp", 0);
872 * Add the code to the defined category.
874 ordered_range_insert(code, "Cp", 2);
877 * Locate the first character property field.
879 for (i = 0; *s != 0 && i < 2; s++) {
883 for (e = s; *e && *e != ';'; e++) ;
885 ordered_range_insert(code, s, e - s);
888 * Locate the combining class code.
890 for (s = e; *s != 0 && i < 3; s++) {
896 * Convert the combining class code from decimal.
898 for (ccl_code = 0, e = s; *e && *e != ';'; e++)
899 ccl_code = (ccl_code * 10) + (*e - '0');
902 * Add the code if it not 0.
905 ordered_ccl_insert(code, ccl_code);
908 * Locate the second character property field.
910 for (s = e; *s != 0 && i < 4; s++) {
914 for (e = s; *e && *e != ';'; e++) ;
916 ordered_range_insert(code, s, e - s);
919 * Check for a decomposition.
922 if (*s != ';' && *s != '<') {
924 * Collect the codes of the decomposition.
926 for (dectmp_size = 0; *s != ';'; ) {
928 * Skip all leading non-hex digits.
930 while (!ishdigit(*s))
933 for (dectmp[dectmp_size] = 0; ishdigit(*s); s++) {
934 dectmp[dectmp_size] <<= 4;
935 if (*s >= '0' && *s <= '9')
936 dectmp[dectmp_size] += *s - '0';
937 else if (*s >= 'A' && *s <= 'F')
938 dectmp[dectmp_size] += (*s - 'A') + 10;
939 else if (*s >= 'a' && *s <= 'f')
940 dectmp[dectmp_size] += (*s - 'a') + 10;
946 * If there is more than one code in the temporary decomposition
947 * array, then add the character with its decomposition.
954 * Skip to the number field.
956 for (i = 0; i < 3 && *s; s++) {
962 * Scan the number in.
964 number[0] = number[1] = 0;
965 for (e = s, neg = wnum = 0; *e && *e != ';'; e++) {
973 * Move the the denominator of the fraction.
981 number[wnum] = (number[wnum] * 10) + (*e - '0');
986 * Adjust the denominator in case of integers and add the number.
989 number[1] = number[0];
991 add_number(code, number[0], number[1]);
995 * Skip to the start of the possible case mappings.
997 for (s = e, i = 0; i < 4 && *s; s++) {
1003 * Collect the case mappings.
1005 cases[0] = cases[1] = cases[2] = 0;
1006 for (i = 0; i < 3; i++) {
1007 while (ishdigit(*s)) {
1009 if (*s >= '0' && *s <= '9')
1010 cases[i] += *s - '0';
1011 else if (*s >= 'A' && *s <= 'F')
1012 cases[i] += (*s - 'A') + 10;
1013 else if (*s >= 'a' && *s <= 'f')
1014 cases[i] += (*s - 'a') + 10;
1020 if (cases[0] && cases[1])
1022 * Add the upper and lower mappings for a title case character.
1027 * Add the lower and title case mappings for the upper case
1033 * Add the upper and title case mappings for the lower case
1041 find_decomp(unsigned long code)
1046 r = decomps_used - 1;
1049 if (code > decomps[m].code)
1051 else if (code < decomps[m].code)
1060 decomp_it(_decomp_t *d)
1065 for (i = 0; i < d->used; i++) {
1066 if ((dp = find_decomp(d->decomp[i])) != 0)
1069 dectmp[dectmp_size++] = d->decomp[i];
1074 * Expand all decompositions by recursively decomposing each character
1075 * in the decomposition.
1082 for (i = 0; i < decomps_used; i++) {
1084 decomp_it(&decomps[i]);
1085 if (dectmp_size > 0)
1086 add_decomp(decomps[i].code);
1091 write_cdata(char *opath)
1094 unsigned long i, idx, bytes, nprops;
1095 unsigned short casecnt[2];
1098 /*****************************************************************
1100 * Generate the ctype data.
1102 *****************************************************************/
1105 * Open the ctype.dat file.
1107 sprintf(path, "%s/ctype.dat", opath);
1108 if ((out = fopen(path, "wb")) == 0)
1112 * Collect the offsets for the properties. The offsets array is
1113 * on a 4-byte boundary to keep things efficient for architectures
1114 * that need such a thing.
1116 for (i = idx = 0; i < NUMPROPS; i++) {
1117 propcnt[i] = (proptbl[i].used != 0) ? idx : 0xffff;
1118 idx += proptbl[i].used;
1122 * Add the sentinel index which is used by the binary search as the upper
1123 * bound for a search.
1128 * Record the actual number of property lists. This may be different than
1129 * the number of offsets actually written because of aligning on a 4-byte
1135 * Calculate the byte count needed and pad the property counts array to a
1138 if ((bytes = sizeof(unsigned short) * (NUMPROPS + 1)) & 3)
1139 bytes += 4 - (bytes & 3);
1140 nprops = bytes / sizeof(unsigned short);
1141 bytes += sizeof(unsigned long) * idx;
1146 fwrite((char *) hdr, sizeof(unsigned short), 2, out);
1149 * Write the byte count.
1151 fwrite((char *) &bytes, sizeof(unsigned long), 1, out);
1154 * Write the property list counts.
1156 fwrite((char *) propcnt, sizeof(unsigned short), nprops, out);
1159 * Write the property lists.
1161 for (i = 0; i < NUMPROPS; i++) {
1162 if (proptbl[i].used > 0)
1163 fwrite((char *) proptbl[i].ranges, sizeof(unsigned long),
1164 proptbl[i].used, out);
1169 /*****************************************************************
1171 * Generate the case mapping data.
1173 *****************************************************************/
1176 * Open the case.dat file.
1178 sprintf(path, "%s/case.dat", opath);
1179 if ((out = fopen(path, "wb")) == 0)
1183 * Write the case mapping tables.
1185 hdr[1] = upper_used + lower_used + title_used;
1186 casecnt[0] = upper_used;
1187 casecnt[1] = lower_used;
1192 fwrite((char *) hdr, sizeof(unsigned short), 2, out);
1195 * Write the upper and lower case table sizes.
1197 fwrite((char *) casecnt, sizeof(unsigned short), 2, out);
1201 * Write the upper case table.
1203 fwrite((char *) upper, sizeof(_case_t), upper_used, out);
1207 * Write the lower case table.
1209 fwrite((char *) lower, sizeof(_case_t), lower_used, out);
1213 * Write the title case table.
1215 fwrite((char *) title, sizeof(_case_t), title_used, out);
1219 /*****************************************************************
1221 * Generate the decomposition data.
1223 *****************************************************************/
1226 * Fully expand all decompositions before generating the output file.
1231 * Open the decomp.dat file.
1233 sprintf(path, "%s/decomp.dat", opath);
1234 if ((out = fopen(path, "wb")) == 0)
1237 hdr[1] = decomps_used;
1242 fwrite((char *) hdr, sizeof(unsigned short), 2, out);
1245 * Write a temporary byte count which will be calculated as the
1246 * decompositions are written out.
1249 fwrite((char *) &bytes, sizeof(unsigned long), 1, out);
1253 * Write the list of decomp nodes.
1255 for (i = idx = 0; i < decomps_used; i++) {
1256 fwrite((char *) &decomps[i].code, sizeof(unsigned long), 1, out);
1257 fwrite((char *) &idx, sizeof(unsigned long), 1, out);
1258 idx += decomps[i].used;
1262 * Write the sentinel index as the last decomp node.
1264 fwrite((char *) &idx, sizeof(unsigned long), 1, out);
1267 * Write the decompositions themselves.
1269 for (i = 0; i < decomps_used; i++)
1270 fwrite((char *) decomps[i].decomp, sizeof(unsigned long),
1271 decomps[i].used, out);
1274 * Seek back to the beginning and write the byte count.
1276 bytes = (sizeof(unsigned long) * idx) +
1277 (sizeof(unsigned long) * ((hdr[1] << 1) + 1));
1278 fseek(out, sizeof(unsigned short) << 1, 0L);
1279 fwrite((char *) &bytes, sizeof(unsigned long), 1, out);
1284 /*****************************************************************
1286 * Generate the combining class data.
1288 *****************************************************************/
1291 * Open the cmbcl.dat file.
1293 sprintf(path, "%s/cmbcl.dat", opath);
1294 if ((out = fopen(path, "wb")) == 0)
1298 * Set the number of ranges used. Each range has a combining class which
1299 * means each entry is a 3-tuple.
1301 hdr[1] = ccl_used / 3;
1306 fwrite((char *) hdr, sizeof(unsigned short), 2, out);
1309 * Write out the byte count to maintain header size.
1311 bytes = ccl_used * sizeof(unsigned long);
1312 fwrite((char *) &bytes, sizeof(unsigned long), 1, out);
1316 * Write the combining class ranges out.
1318 fwrite((char *) ccl, sizeof(unsigned long), ccl_used, out);
1322 /*****************************************************************
1324 * Generate the number data.
1326 *****************************************************************/
1329 * Open the num.dat file.
1331 sprintf(path, "%s/num.dat", opath);
1332 if ((out = fopen(path, "wb")) == 0)
1336 * The count part of the header will be the total number of codes that
1339 hdr[1] = (unsigned short) (ncodes_used << 1);
1340 bytes = (ncodes_used * sizeof(_codeidx_t)) + (nums_used * sizeof(_num_t));
1345 fwrite((char *) hdr, sizeof(unsigned short), 2, out);
1348 * Write out the byte count to maintain header size.
1350 fwrite((char *) &bytes, sizeof(unsigned long), 1, out);
1353 * Now, if number mappings exist, write them out.
1355 if (ncodes_used > 0) {
1356 fwrite((char *) ncodes, sizeof(_codeidx_t), ncodes_used, out);
1357 fwrite((char *) nums, sizeof(_num_t), nums_used, out);
1364 main(int argc, char *argv[])
1369 if ((prog = strrchr(argv[0], '/')) != 0)
1381 if (argv[0][0] == '-' && argv[0][1] == 'o') {
1386 if (in != stdin && in != NULL)
1388 if ((in = fopen(argv[0], "rb")) == 0)
1389 fprintf(stderr, "%s: unable to open ctype file %s\n",