2 * Copyright 1996, 1997, 1998 Computing Research Labs,
3 * New Mexico State University
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
20 * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 static char rcsid
[] __attribute__ ((unused
)) = "$Id: ucgendat.c,v 1.1 1999/01/08 00:19:21 ftang%netscape.com Exp $";
27 static char rcsid
[] = "$Id: ucgendat.c,v 1.1 1999/01/08 00:19:21 ftang%netscape.com Exp $";
38 #define ishdigit(cc) (((cc) >= '0' && (cc) <= '9') ||\
39 ((cc) >= 'A' && (cc) <= 'F') ||\
40 ((cc) >= 'a' && (cc) <= 'f'))
43 * A header written to the output file with the byte-order-mark and the number
46 static unsigned short hdr
[2] = {0xfeff, 0};
49 #define NEEDPROPS (NUMPROPS + (4 - (NUMPROPS & 3)))
57 * List of properties expected to be found in the Unicode Character Database
58 * including some implementation specific properties.
60 * The implementation specific properties are:
61 * Cm = Composed (can be decomposed)
63 * Sy = Symmetric (has left and right forms)
68 * Cp = Defined character
70 static _prop_t props
[NUMPROPS
] = {
71 {"Mn", 2}, {"Mc", 2}, {"Me", 2}, {"Nd", 2}, {"Nl", 2}, {"No", 2},
72 {"Zs", 2}, {"Zl", 2}, {"Zp", 2}, {"Cc", 2}, {"Cf", 2}, {"Cs", 2},
73 {"Co", 2}, {"Cn", 2}, {"Lu", 2}, {"Ll", 2}, {"Lt", 2}, {"Lm", 2},
74 {"Lo", 2}, {"Pc", 2}, {"Pd", 2}, {"Ps", 2}, {"Pe", 2}, {"Po", 2},
75 {"Sm", 2}, {"Sc", 2}, {"Sk", 2}, {"So", 2}, {"L", 1}, {"R", 1},
76 {"EN", 2}, {"ES", 2}, {"ET", 2}, {"AN", 2}, {"CS", 2}, {"B", 1},
77 {"S", 1}, {"WS", 2}, {"ON", 2},
78 {"Cm", 2}, {"Nb", 2}, {"Sy", 2}, {"Hd", 2}, {"Qm", 2}, {"Mr", 2},
79 {"Ss", 2}, {"Cp", 2}, {"Pi", 2}, {"Pf", 2}
83 unsigned long *ranges
;
88 static _ranges_t proptbl
[NUMPROPS
];
91 * Make sure this array is sized to be on a 4-byte boundary at compile time.
93 static unsigned short propcnt
[NEEDPROPS
];
96 * Array used to collect a decomposition before adding it to the decomposition
99 static unsigned long dectmp
[64];
100 static unsigned long dectmp_size
;
106 unsigned long *decomp
;
110 * List of decomposition. Created and expanded in order as the characters are
113 static _decomp_t
*decomps
;
114 static unsigned long decomps_used
;
115 static unsigned long decomps_size
;
118 * Types and lists for handling lists of case mappings.
122 unsigned long other1
;
123 unsigned long other2
;
126 static _case_t
*upper
;
127 static _case_t
*lower
;
128 static _case_t
*title
;
129 static unsigned long upper_used
;
130 static unsigned long upper_size
;
131 static unsigned long lower_used
;
132 static unsigned long lower_size
;
133 static unsigned long title_used
;
134 static unsigned long title_size
;
137 * Array used to collect case mappings before adding them to a list.
139 static unsigned long cases
[3];
142 * An array to hold ranges for combining classes.
144 static unsigned long *ccl
;
145 static unsigned long ccl_used
;
146 static unsigned long ccl_size
;
149 * Structures for handling numbers.
162 * Arrays to hold the mapping of codes to numbers.
164 static _codeidx_t
*ncodes
;
165 static unsigned long ncodes_used
;
166 static unsigned long ncodes_size
;
169 static unsigned long nums_used
;
170 static unsigned long nums_size
;
173 * Array for holding numbers.
176 static unsigned long nums_used
;
177 static unsigned long nums_size
;
181 add_range(unsigned long start
, unsigned long end
, char *p1
, char *p2
)
183 add_range(start
, end
, p1
, p2
)
184 unsigned long start
, end
;
192 for (k
= 0; k
< 2; k
++) {
204 for (i
= 0; i
< NUMPROPS
; i
++) {
205 if (props
[i
].len
== len
&& memcmp(props
[i
].name
, name
, len
) == 0)
215 * Resize the range list if necessary.
217 if (rlp
->used
== rlp
->size
) {
219 rlp
->ranges
= (unsigned long *)
220 malloc(sizeof(unsigned long) << 3);
222 rlp
->ranges
= (unsigned long *)
223 realloc((char *) rlp
->ranges
,
224 sizeof(unsigned long) * (rlp
->size
+ 8));
229 * If this is the first code for this property list, just add it
232 if (rlp
->used
== 0) {
233 rlp
->ranges
[0] = start
;
234 rlp
->ranges
[1] = end
;
240 * Optimize the case of adding the range to the end.
243 if (start
> rlp
->ranges
[j
]) {
245 rlp
->ranges
[j
++] = start
;
246 rlp
->ranges
[j
++] = end
;
252 * Need to locate the insertion point.
255 i
< rlp
->used
&& start
> rlp
->ranges
[i
+ 1] + 1; i
+= 2) ;
258 * If the start value lies in the current range, then simply set the
259 * new end point of the range to the end value passed as a parameter.
261 if (rlp
->ranges
[i
] <= start
&& start
<= rlp
->ranges
[i
+ 1] + 1) {
262 rlp
->ranges
[i
+ 1] = end
;
267 * Shift following values up by two.
269 for (j
= rlp
->used
; j
> i
; j
-= 2) {
270 rlp
->ranges
[j
] = rlp
->ranges
[j
- 2];
271 rlp
->ranges
[j
+ 1] = rlp
->ranges
[j
- 1];
275 * Add the new range at the insertion point.
277 rlp
->ranges
[i
] = start
;
278 rlp
->ranges
[i
+ 1] = end
;
285 ordered_range_insert(unsigned long c
, char *name
, int len
)
287 ordered_range_insert(c
, name
, len
)
300 for (i
= 0; i
< NUMPROPS
; i
++) {
301 if (props
[i
].len
== len
&& memcmp(props
[i
].name
, name
, len
) == 0)
309 * Have a match, so insert the code in order.
314 * Resize the range list if necessary.
316 if (rlp
->used
== rlp
->size
) {
318 rlp
->ranges
= (unsigned long *)
319 malloc(sizeof(unsigned long) << 3);
321 rlp
->ranges
= (unsigned long *)
322 realloc((char *) rlp
->ranges
,
323 sizeof(unsigned long) * (rlp
->size
+ 8));
328 * If this is the first code for this property list, just add it
331 if (rlp
->used
== 0) {
332 rlp
->ranges
[0] = rlp
->ranges
[1] = c
;
338 * Optimize the cases of extending the last range and adding new ranges to
343 s
= rlp
->ranges
[j
- 1];
347 * Extend the last range.
355 * Start another range on the end.
358 rlp
->ranges
[j
] = rlp
->ranges
[j
+ 1] = c
;
365 * The code is a duplicate of a code in the last range, so just return.
370 * The code should be inserted somewhere before the last range in the
371 * list. Locate the insertion point.
374 i
< rlp
->used
&& c
> rlp
->ranges
[i
+ 1] + 1; i
+= 2) ;
377 e
= rlp
->ranges
[i
+ 1];
381 * Simply extend the current range.
383 rlp
->ranges
[i
+ 1] = c
;
386 * Add a new entry before the current location. Shift all entries
387 * before the current one up by one to make room.
389 for (j
= rlp
->used
; j
> i
; j
-= 2) {
390 rlp
->ranges
[j
] = rlp
->ranges
[j
- 2];
391 rlp
->ranges
[j
+ 1] = rlp
->ranges
[j
- 1];
393 rlp
->ranges
[i
] = rlp
->ranges
[i
+ 1] = c
;
401 add_decomp(unsigned long code
)
407 unsigned long i
, j
, size
;
410 * Add the code to the composite property.
412 ordered_range_insert(code
, "Cm", 2);
415 * Locate the insertion point for the code.
417 for (i
= 0; i
< decomps_used
&& code
> decomps
[i
].code
; i
++) ;
420 * Allocate space for a new decomposition.
422 if (decomps_used
== decomps_size
) {
423 if (decomps_size
== 0)
424 decomps
= (_decomp_t
*) malloc(sizeof(_decomp_t
) << 3);
426 decomps
= (_decomp_t
*)
427 realloc((char *) decomps
,
428 sizeof(_decomp_t
) * (decomps_size
+ 8));
429 (void) memset((char *) (decomps
+ decomps_size
), 0,
430 sizeof(_decomp_t
) << 3);
434 if (i
< decomps_used
&& code
!= decomps
[i
].code
) {
436 * Shift the decomps up by one if the codes don't match.
438 for (j
= decomps_used
; j
> i
; j
--)
439 (void) memcpy((char *) &decomps
[j
], (char *) &decomps
[j
- 1],
444 * Insert or replace a decomposition.
446 size
= dectmp_size
+ (4 - (dectmp_size
& 3));
447 if (decomps
[i
].size
< size
) {
448 if (decomps
[i
].size
== 0)
449 decomps
[i
].decomp
= (unsigned long *)
450 malloc(sizeof(unsigned long) * size
);
452 decomps
[i
].decomp
= (unsigned long *)
453 realloc((char *) decomps
[i
].decomp
,
454 sizeof(unsigned long) * size
);
455 decomps
[i
].size
= size
;
458 if (decomps
[i
].code
!= code
)
461 decomps
[i
].code
= code
;
462 decomps
[i
].used
= dectmp_size
;
463 (void) memcpy((char *) decomps
[i
].decomp
, (char *) dectmp
,
464 sizeof(unsigned long) * dectmp_size
);
470 add_title(unsigned long code
)
479 * Always map the code to itself.
483 if (title_used
== title_size
) {
485 title
= (_case_t
*) malloc(sizeof(_case_t
) << 3);
487 title
= (_case_t
*) realloc((char *) title
,
488 sizeof(_case_t
) * (title_size
+ 8));
493 * Locate the insertion point.
495 for (i
= 0; i
< title_used
&& code
> title
[i
].key
; i
++) ;
497 if (i
< title_used
) {
499 * Shift the array up by one.
501 for (j
= title_used
; j
> i
; j
--)
502 (void) memcpy((char *) &title
[j
], (char *) &title
[j
- 1],
506 title
[i
].key
= cases
[2]; /* Title */
507 title
[i
].other1
= cases
[0]; /* Upper */
508 title
[i
].other2
= cases
[1]; /* Lower */
515 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 */
567 add_lower(unsigned long code
)
576 * Always map the code to itself.
581 * If the title case character is empty, then make it the same as the
587 if (lower_used
== lower_size
) {
589 lower
= (_case_t
*) malloc(sizeof(_case_t
) << 3);
591 lower
= (_case_t
*) realloc((char *) lower
,
592 sizeof(_case_t
) * (lower_size
+ 8));
597 * Locate the insertion point.
599 for (i
= 0; i
< lower_used
&& code
> lower
[i
].key
; i
++) ;
601 if (i
< lower_used
) {
603 * Shift the array up by one.
605 for (j
= lower_used
; j
> i
; j
--)
606 (void) memcpy((char *) &lower
[j
], (char *) &lower
[j
- 1],
610 lower
[i
].key
= cases
[1]; /* Lower */
611 lower
[i
].other1
= cases
[0]; /* Upper */
612 lower
[i
].other2
= cases
[2]; /* Title */
619 ordered_ccl_insert(unsigned long c
, unsigned long ccl_code
)
621 ordered_ccl_insert(c
, ccl_code
)
622 unsigned long c
, ccl_code
;
627 if (ccl_used
== ccl_size
) {
629 ccl
= (unsigned long *) malloc(sizeof(unsigned long) * 24);
631 ccl
= (unsigned long *)
632 realloc((char *) ccl
, sizeof(unsigned long) * (ccl_size
+ 24));
637 * Optimize adding the first item.
647 * Handle the special case of extending the range on the end. This
648 * requires that the combining class codes are the same.
650 if (ccl_code
== ccl
[ccl_used
- 1] && c
== ccl
[ccl_used
- 2] + 1) {
651 ccl
[ccl_used
- 2] = c
;
656 * Handle the special case of adding another range on the end.
658 if (c
> ccl
[ccl_used
- 2] + 1 ||
659 (c
== ccl
[ccl_used
- 2] + 1 && ccl_code
!= ccl
[ccl_used
- 1])) {
662 ccl
[ccl_used
++] = ccl_code
;
667 * Locate either the insertion point or range for the code.
669 for (i
= 0; i
< ccl_used
&& c
> ccl
[i
+ 1] + 1; i
+= 3) ;
671 if (ccl_code
== ccl
[i
+ 2] && c
== ccl
[i
+ 1] + 1) {
673 * Extend an existing range.
677 } else if (c
< ccl
[i
]) {
679 * Start a new range before the current location.
681 for (j
= ccl_used
; j
> i
; j
-= 3) {
683 ccl
[j
- 1] = ccl
[j
- 4];
684 ccl
[j
- 2] = ccl
[j
- 5];
686 ccl
[i
] = ccl
[i
+ 1] = c
;
687 ccl
[i
+ 2] = ccl_code
;
692 * Adds a number if it does not already exist and returns an index value
697 make_number(short num
, short denom
)
699 make_number(num
, denom
)
706 * Determine if the number already exists.
708 for (n
= 0; n
< nums_used
; n
++) {
709 if (nums
[n
].numerator
== num
&& nums
[n
].denominator
== denom
)
713 if (nums_used
== nums_size
) {
715 nums
= (_num_t
*) malloc(sizeof(_num_t
) << 3);
717 nums
= (_num_t
*) realloc((char *) nums
,
718 sizeof(_num_t
) * (nums_size
+ 8));
723 nums
[n
].numerator
= num
;
724 nums
[n
].denominator
= denom
;
731 add_number(unsigned long code
, short num
, short denom
)
733 add_number(code
, num
, denom
)
741 * Insert the code in order.
743 for (i
= 0; i
< ncodes_used
&& code
> ncodes
[i
].code
; i
++) ;
746 * Handle the case of the codes matching and simply replace the number
747 * that was there before.
749 if (ncodes_used
> 0 && code
== ncodes
[i
].code
) {
750 ncodes
[i
].idx
= make_number(num
, denom
);
755 * Resize the array if necessary.
757 if (ncodes_used
== ncodes_size
) {
758 if (ncodes_size
== 0)
759 ncodes
= (_codeidx_t
*) malloc(sizeof(_codeidx_t
) << 3);
761 ncodes
= (_codeidx_t
*)
762 realloc((char *) ncodes
, sizeof(_codeidx_t
) * (ncodes_size
+ 8));
768 * Shift things around to insert the code if necessary.
770 if (i
< ncodes_used
) {
771 for (j
= ncodes_used
; j
> i
; j
--) {
772 ncodes
[j
].code
= ncodes
[j
- 1].code
;
773 ncodes
[j
].idx
= ncodes
[j
- 1].idx
;
776 ncodes
[i
].code
= code
;
777 ncodes
[i
].idx
= make_number(num
, denom
);
783 * This routine assumes that the line is a valid Unicode Character Database
794 unsigned long i
, lineno
, skip
, code
, ccl_code
;
795 short wnum
, neg
, number
[2];
796 char line
[512], *s
, *e
;
799 while (fscanf(in
, "%[^\n]\n", line
) != EOF
) {
803 * Skip blank lines and lines that start with a '#'.
805 if (line
[0] == 0 || line
[0] == '#')
809 * If lines need to be skipped, do it here.
817 * Collect the code. The code can be up to 6 hex digits in length to
818 * allow surrogates to be specified.
820 for (s
= line
, i
= code
= 0; *s
!= ';' && i
< 6; i
++, s
++) {
822 if (*s
>= '0' && *s
<= '9')
824 else if (*s
>= 'A' && *s
<= 'F')
825 code
+= (*s
- 'A') + 10;
826 else if (*s
>= 'a' && *s
<= 'f')
827 code
+= (*s
- 'a') + 10;
831 * Handle the following special cases:
832 * 1. 4E00-9FA5 CJK Ideographs.
833 * 2. AC00-D7A3 Hangul Syllables.
834 * 3. D800-DFFF Surrogates.
835 * 4. E000-F8FF Private Use Area.
836 * 5. F900-FA2D Han compatibility.
841 * The Han ideographs.
843 add_range(0x4e00, 0x9fff, "Lo", "L");
846 * Add the characters to the defined category.
848 add_range(0x4e00, 0x9fa5, "Cp", 0);
854 * The Hangul syllables.
856 add_range(0xac00, 0xd7a3, "Lo", "L");
859 * Add the characters to the defined category.
861 add_range(0xac00, 0xd7a3, "Cp", 0);
867 * Make a range of all surrogates and assume some default
870 add_range(0x010000, 0x10ffff, "Cs", "L");
875 * The Private Use area. Add with a default set of properties.
877 add_range(0xe000, 0xf8ff, "Co", "L");
882 * The CJK compatibility area.
884 add_range(0xf900, 0xfaff, "Lo", "L");
887 * Add the characters to the defined category.
889 add_range(0xf900, 0xfaff, "Cp", 0);
898 * Add the code to the defined category.
900 ordered_range_insert(code
, "Cp", 2);
903 * Locate the first character property field.
905 for (i
= 0; *s
!= 0 && i
< 2; s
++) {
909 for (e
= s
; *e
&& *e
!= ';'; e
++) ;
911 ordered_range_insert(code
, s
, e
- s
);
914 * Locate the combining class code.
916 for (s
= e
; *s
!= 0 && i
< 3; s
++) {
922 * Convert the combining class code from decimal.
924 for (ccl_code
= 0, e
= s
; *e
&& *e
!= ';'; e
++)
925 ccl_code
= (ccl_code
* 10) + (*e
- '0');
928 * Add the code if it not 0.
931 ordered_ccl_insert(code
, ccl_code
);
934 * Locate the second character property field.
936 for (s
= e
; *s
!= 0 && i
< 4; s
++) {
940 for (e
= s
; *e
&& *e
!= ';'; e
++) ;
942 ordered_range_insert(code
, s
, e
- s
);
945 * Check for a decomposition.
948 if (*s
!= ';' && *s
!= '<') {
950 * Collect the codes of the decomposition.
952 for (dectmp_size
= 0; *s
!= ';'; ) {
954 * Skip all leading non-hex digits.
956 while (!ishdigit(*s
))
959 for (dectmp
[dectmp_size
] = 0; ishdigit(*s
); s
++) {
960 dectmp
[dectmp_size
] <<= 4;
961 if (*s
>= '0' && *s
<= '9')
962 dectmp
[dectmp_size
] += *s
- '0';
963 else if (*s
>= 'A' && *s
<= 'F')
964 dectmp
[dectmp_size
] += (*s
- 'A') + 10;
965 else if (*s
>= 'a' && *s
<= 'f')
966 dectmp
[dectmp_size
] += (*s
- 'a') + 10;
972 * If there is more than one code in the temporary decomposition
973 * array, then add the character with its decomposition.
980 * Skip to the number field.
982 for (i
= 0; i
< 3 && *s
; s
++) {
988 * Scan the number in.
990 number
[0] = number
[1] = 0;
991 for (e
= s
, neg
= wnum
= 0; *e
&& *e
!= ';'; e
++) {
999 * Move the the denominator of the fraction.
1007 number
[wnum
] = (number
[wnum
] * 10) + (*e
- '0');
1012 * Adjust the denominator in case of integers and add the number.
1015 number
[1] = number
[0];
1017 add_number(code
, number
[0], number
[1]);
1021 * Skip to the start of the possible case mappings.
1023 for (s
= e
, i
= 0; i
< 4 && *s
; s
++) {
1029 * Collect the case mappings.
1031 cases
[0] = cases
[1] = cases
[2] = 0;
1032 for (i
= 0; i
< 3; i
++) {
1033 while (ishdigit(*s
)) {
1035 if (*s
>= '0' && *s
<= '9')
1036 cases
[i
] += *s
- '0';
1037 else if (*s
>= 'A' && *s
<= 'F')
1038 cases
[i
] += (*s
- 'A') + 10;
1039 else if (*s
>= 'a' && *s
<= 'f')
1040 cases
[i
] += (*s
- 'a') + 10;
1046 if (cases
[0] && cases
[1])
1048 * Add the upper and lower mappings for a title case character.
1053 * Add the lower and title case mappings for the upper case
1059 * Add the upper and title case mappings for the lower case
1068 find_decomp(unsigned long code
)
1077 r
= decomps_used
- 1;
1080 if (code
> decomps
[m
].code
)
1082 else if (code
< decomps
[m
].code
)
1092 decomp_it(_decomp_t
*d
)
1101 for (i
= 0; i
< d
->used
; i
++) {
1102 if ((dp
= find_decomp(d
->decomp
[i
])) != 0)
1105 dectmp
[dectmp_size
++] = d
->decomp
[i
];
1110 * Expand all decompositions by recursively decomposing each character
1111 * in the decomposition.
1122 for (i
= 0; i
< decomps_used
; i
++) {
1124 decomp_it(&decomps
[i
]);
1125 if (dectmp_size
> 0)
1126 add_decomp(decomps
[i
].code
);
1132 write_cdata(char *opath
)
1139 unsigned long i
, idx
, bytes
, nprops
;
1140 unsigned short casecnt
[2];
1143 /*****************************************************************
1145 * Generate the ctype data.
1147 *****************************************************************/
1150 * Open the ctype.dat file.
1152 sprintf(path
, "%s/ctype.dat", opath
);
1153 if ((out
= fopen(path
, "wb")) == 0)
1157 * Collect the offsets for the properties. The offsets array is
1158 * on a 4-byte boundary to keep things efficient for architectures
1159 * that need such a thing.
1161 for (i
= idx
= 0; i
< NUMPROPS
; i
++) {
1162 propcnt
[i
] = (proptbl
[i
].used
!= 0) ? idx
: 0xffff;
1163 idx
+= proptbl
[i
].used
;
1167 * Add the sentinel index which is used by the binary search as the upper
1168 * bound for a search.
1173 * Record the actual number of property lists. This may be different than
1174 * the number of offsets actually written because of aligning on a 4-byte
1180 * Calculate the byte count needed and pad the property counts array to a
1183 if ((bytes
= sizeof(unsigned short) * (NUMPROPS
+ 1)) & 3)
1184 bytes
+= 4 - (bytes
& 3);
1185 nprops
= bytes
/ sizeof(unsigned short);
1186 bytes
+= sizeof(unsigned long) * idx
;
1191 fwrite((char *) hdr
, sizeof(unsigned short), 2, out
);
1194 * Write the byte count.
1196 fwrite((char *) &bytes
, sizeof(unsigned long), 1, out
);
1199 * Write the property list counts.
1201 fwrite((char *) propcnt
, sizeof(unsigned short), nprops
, out
);
1204 * Write the property lists.
1206 for (i
= 0; i
< NUMPROPS
; i
++) {
1207 if (proptbl
[i
].used
> 0)
1208 fwrite((char *) proptbl
[i
].ranges
, sizeof(unsigned long),
1209 proptbl
[i
].used
, out
);
1214 /*****************************************************************
1216 * Generate the case mapping data.
1218 *****************************************************************/
1221 * Open the case.dat file.
1223 sprintf(path
, "%s/case.dat", opath
);
1224 if ((out
= fopen(path
, "wb")) == 0)
1228 * Write the case mapping tables.
1230 hdr
[1] = upper_used
+ lower_used
+ title_used
;
1231 casecnt
[0] = upper_used
;
1232 casecnt
[1] = lower_used
;
1237 fwrite((char *) hdr
, sizeof(unsigned short), 2, out
);
1240 * Write the upper and lower case table sizes.
1242 fwrite((char *) casecnt
, sizeof(unsigned short), 2, out
);
1246 * Write the upper case table.
1248 fwrite((char *) upper
, sizeof(_case_t
), upper_used
, out
);
1252 * Write the lower case table.
1254 fwrite((char *) lower
, sizeof(_case_t
), lower_used
, out
);
1258 * Write the title case table.
1260 fwrite((char *) title
, sizeof(_case_t
), title_used
, out
);
1264 /*****************************************************************
1266 * Generate the decomposition data.
1268 *****************************************************************/
1271 * Fully expand all decompositions before generating the output file.
1276 * Open the decomp.dat file.
1278 sprintf(path
, "%s/decomp.dat", opath
);
1279 if ((out
= fopen(path
, "wb")) == 0)
1282 hdr
[1] = decomps_used
;
1287 fwrite((char *) hdr
, sizeof(unsigned short), 2, out
);
1290 * Write a temporary byte count which will be calculated as the
1291 * decompositions are written out.
1294 fwrite((char *) &bytes
, sizeof(unsigned long), 1, out
);
1298 * Write the list of decomp nodes.
1300 for (i
= idx
= 0; i
< decomps_used
; i
++) {
1301 fwrite((char *) &decomps
[i
].code
, sizeof(unsigned long), 1, out
);
1302 fwrite((char *) &idx
, sizeof(unsigned long), 1, out
);
1303 idx
+= decomps
[i
].used
;
1307 * Write the sentinel index as the last decomp node.
1309 fwrite((char *) &idx
, sizeof(unsigned long), 1, out
);
1312 * Write the decompositions themselves.
1314 for (i
= 0; i
< decomps_used
; i
++)
1315 fwrite((char *) decomps
[i
].decomp
, sizeof(unsigned long),
1316 decomps
[i
].used
, out
);
1319 * Seek back to the beginning and write the byte count.
1321 bytes
= (sizeof(unsigned long) * idx
) +
1322 (sizeof(unsigned long) * ((hdr
[1] << 1) + 1));
1323 fseek(out
, sizeof(unsigned short) << 1, 0L);
1324 fwrite((char *) &bytes
, sizeof(unsigned long), 1, out
);
1329 /*****************************************************************
1331 * Generate the combining class data.
1333 *****************************************************************/
1336 * Open the cmbcl.dat file.
1338 sprintf(path
, "%s/cmbcl.dat", opath
);
1339 if ((out
= fopen(path
, "wb")) == 0)
1343 * Set the number of ranges used. Each range has a combining class which
1344 * means each entry is a 3-tuple.
1346 hdr
[1] = ccl_used
/ 3;
1351 fwrite((char *) hdr
, sizeof(unsigned short), 2, out
);
1354 * Write out the byte count to maintain header size.
1356 bytes
= ccl_used
* sizeof(unsigned long);
1357 fwrite((char *) &bytes
, sizeof(unsigned long), 1, out
);
1361 * Write the combining class ranges out.
1363 fwrite((char *) ccl
, sizeof(unsigned long), ccl_used
, out
);
1367 /*****************************************************************
1369 * Generate the number data.
1371 *****************************************************************/
1374 * Open the num.dat file.
1376 sprintf(path
, "%s/num.dat", opath
);
1377 if ((out
= fopen(path
, "wb")) == 0)
1381 * The count part of the header will be the total number of codes that
1384 hdr
[1] = (unsigned short) (ncodes_used
<< 1);
1385 bytes
= (ncodes_used
* sizeof(_codeidx_t
)) + (nums_used
* sizeof(_num_t
));
1390 fwrite((char *) hdr
, sizeof(unsigned short), 2, out
);
1393 * Write out the byte count to maintain header size.
1395 fwrite((char *) &bytes
, sizeof(unsigned long), 1, out
);
1398 * Now, if number mappings exist, write them out.
1400 if (ncodes_used
> 0) {
1401 fwrite((char *) ncodes
, sizeof(_codeidx_t
), ncodes_used
, out
);
1402 fwrite((char *) nums
, sizeof(_num_t
), nums_used
, out
);
1410 main(int argc
, char *argv
[])
1420 if ((prog
= strrchr(argv
[0], '/')) != 0)
1432 if (argv
[0][0] == '-' && argv
[0][1] == 'o') {
1439 if ((in
= fopen(argv
[0], "rb")) == 0)
1440 fprintf(stderr
, "%s: unable to open ctype file %s\n",