chiark / gitweb /
Generate, but do not use, composition mappings.
[disorder] / scripts / make-unidata
CommitLineData
61507e3c
RK
1#! /usr/bin/perl -w
2#
e5a5a138
RK
3# This file is part of DisOrder.
4# Copyright (C) 2007 Richard Kettlewell
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19# USA
20#
21#
22# Generate Unicode support tables
23#
24# This script will download data from unicode.org if the required files
25# aren't in the current directory.
26#
27# After modifying this script you should run:
28# make -C lib rebuild-unicode check
29#
30# Things not supported yet:
31# - SpecialCasing.txt data for case mapping
32# - Title case offsets
33# - Some kind of hinting for composition
e5a5a138
RK
34# - ...
35#
36# NB the generated files DO NOT offer a stable ABI and so are not immediately
37# suitable for use in a general-purpose library. Things that would need to
38# be done:
39# - Hide unidata.h from applications; it will never be ABI- or even API-stable.
40# - Stablized General_Category values
41# - Extend the unicode.h API to general utility rather than just what
42# DisOrder needs.
43# - ...
44#
61507e3c 45use strict;
35b651f0 46use File::Basename;
61507e3c
RK
47
48sub out {
49 print @_ or die "$!\n";
50}
51
52sub key {
53 my $d = shift;
54 local $_;
55
56 return join("-", map($d->{$_}, sort keys %$d));
57}
58
e5a5a138
RK
59# Size of a subtable
60#
61# This can be varied to trade off the number of subtables against their size.
c2e01e0a
RK
62# 16 gave the smallest results last time I checked (on a Mac with a 32-bit
63# build).
64our $modulus = 16;
65
66if(@ARGV) {
67 $modulus = shift;
68}
e5a5a138 69
1a05e381
RK
70# Where to break the table. There is a huge empty section of the Unicode
71# code space and we deal with this by simply leaving it out of the table.
72# This complicates the lookup function a little but should not affect
73# performance in the cases we care about.
74our $break_start = 0x30000;
75our $break_end = 0xE0000;
76
77# Similarly we simply omit the very top of the table and sort it out in the
78# lookup function.
79our $break_top = 0xE0200;
80
61507e3c
RK
81my %cats = (); # known general categories
82my %data = (); # mapping of codepoints to information
61507e3c 83my $max = 0; # maximum codepoint
e5a5a138
RK
84my $maxccc = 0; # maximum combining class
85my $maxud = 0;
86my $minud = 0; # max/min upper case offset
87my $maxld = 0;
88my $minld = 0; # max/min lower case offset
89
90# Make sure we have our desired input files. We explicitly specify a
91# Unicode standard version to make sure that a given version of DisOrder
92# supports a given version of Unicode.
0b7052da 93sub input {
35b651f0
RK
94 my $path = shift;
95 my $lpath = basename($path);
96 if(!-e $lpath) {
97 system("wget http://www.unicode.org/Public/5.0.0/ucd/$path");
98 chmod(0444, $lpath) or die "$lpath: $!\n";
e5a5a138 99 }
0b7052da 100 open(STDIN, "<$lpath") or die "$lpath: $!\n";
bcf9ed7f 101 print STDERR "Reading $lpath...\n";
e5a5a138 102}
61507e3c 103
e5a5a138
RK
104
105# Read the main data file
0b7052da 106input("UnicodeData.txt");
1a05e381 107my ($start, $end);
61507e3c
RK
108while(<>) {
109 my @f = split(/;/, $_);
110 my $c = hex($f[0]); # codepoint
61507e3c 111 my $name = $f[1];
1a05e381
RK
112 die "$f[0] $name is in the break\n"
113 if $c >= $break_start && $c < $break_end;
e5a5a138 114 my $gc = $f[2]; # General_Category
bcf9ed7f 115 # Variuos GCs we don't expect to see in UnicodeData.txt
0a4af692 116 $cats{$gc} = 1; # always record all GCs
1a05e381
RK
117 if($name =~ /first>/i) {
118 $start = $c;
119 next;
120 } elsif($name =~ /last>/i) {
121 $end = $c;
122 } else {
123 $start = $end = $c;
124 }
bcf9ed7f 125 die "unexpected Cn" if $gc eq 'Cn';
e5a5a138
RK
126 my $ccc = $f[3]; # Canonical_Combining_Class
127 my $dm = $f[5]; # Decomposition_Type + Decomposition_Mapping
128 my $sum = hex($f[12]) || $c; # Simple_Uppercase_Mapping
129 my $slm = hex($f[13]) || $c; # Simple_Lowercase_Mapping
61507e3c
RK
130 # recalculate the upper/lower case mappings as offsets
131 my $ud = $sum - $c;
132 my $ld = $slm - $c;
e5a5a138
RK
133 # update bounds on various values
134 $maxccc = $ccc if $ccc > $maxccc; # assumed never to be -ve
135 $minud = $ud if $ud < $minud;
136 $maxud = $ud if $ud > $maxud;
137 $minld = $ld if $ld < $minld;
138 $maxld = $ld if $ld > $maxld;
1a05e381 139 if($start != $end) {
0e843521 140 printf STDERR "> range %04X-%04X is %s\n", $start, $end, $gc;
1a05e381
RK
141 }
142 for($c = $start; $c <= $end; ++$c) {
0e843521
RK
143 my $d = {
144 "gc" => $gc,
145 "ccc" => $ccc,
146 "ud" => $ud,
147 "ld" => $ld,
148 };
149 if($dm ne '') {
f98fcddb
RK
150 if($dm =~ /</) {
151 # This is a compatibility decomposition
0e843521 152 $dm =~ s/^<.*>\s*//;
f98fcddb 153 $d->{compat} = 1;
0e843521 154 }
99695df9 155 $d->{decomp} = [map(hex($_), split(/\s+/, $dm))];
0e843521 156 }
1a05e381
RK
157 $data{$c} = $d;
158 }
61507e3c 159 $cats{$gc} = 1;
1a05e381 160 $max = $end if $end > $max;
61507e3c
RK
161}
162
0b7052da
RK
163sub read_prop_with_ranges {
164 my $path = shift;
165 my $propkey = shift;
166 input($path);
167 while(<>) {
168 chomp;
169 s/\s*\#.*//;
170 next if $_ eq '';
171 my ($range, $propval) = split(/\s*;\s*/, $_);
172 if($range =~ /(.*)\.\.(.*)/) {
173 for my $c (hex($1) .. hex($2)) {
0e843521 174 $data{$c}->{$propkey} = $propval;
0b7052da
RK
175 }
176 } else {
177 my $c = hex($range);
0e843521 178 $data{$c}->{$propkey} = $propval;
35b651f0 179 }
0b7052da
RK
180 }
181}
182
349b7b74 183# Grapheme_Break etc
0b7052da 184read_prop_with_ranges("auxiliary/GraphemeBreakProperty.txt", "gbreak");
0b7052da 185read_prop_with_ranges("auxiliary/WordBreakProperty.txt", "wbreak");
349b7b74 186read_prop_with_ranges("auxiliary/SentenceBreakProperty.txt", "sbreak");
0b7052da 187
349b7b74
RK
188# Compute the full list and fill in the Extend category properly
189my %gbreak = ();
190my %wbreak = ();
191my %sbreak = ();
0b7052da 192for my $c (keys %data) {
349b7b74
RK
193 if(!exists $data{$c}->{gbreak}) {
194 $data{$c}->{gbreak} = 'Other';
195 }
196 $gbreak{$data{$c}->{gbreak}} = 1;
197
0b7052da 198 if(!exists $data{$c}->{wbreak}) {
349b7b74 199 if($data{$c}->{gbreak} eq 'Extend') {
0b7052da
RK
200 $data{$c}->{wbreak} = 'Extend';
201 } else {
202 $data{$c}->{wbreak} = 'Other';
35b651f0
RK
203 }
204 }
349b7b74
RK
205 $wbreak{$data{$c}->{wbreak}} = 1;
206
207 if(!exists $data{$c}->{sbreak}) {
208 if($data{$c}->{gbreak} eq 'Extend') {
209 $data{$c}->{sbreak} = 'Extend';
210 } else {
211 $data{$c}->{sbreak} = 'Other';
212 }
213 }
214 $sbreak{$data{$c}->{sbreak}} = 1;
35b651f0
RK
215}
216
99695df9
RK
217# Various derived properties
218input("DerivedNormalizationProps.txt");
219while(<>) {
220 chomp;
221 s/\s*\#.*//;
222 next if $_ eq '';
223 my @f = split(/\s*;\s*/, $_);
224 if(@f == 2) {
225 push(@f, 1);
226 }
227 my ($range, $propkey, $propval) = @f;
228 if($range =~ /(.*)\.\.(.*)/) {
229 for my $c (hex($1) .. hex($2)) {
230 $data{$c}->{$propkey} = $propval
231 }
232 } else {
233 my $c = hex($range);
234 $data{$c}->{$propkey} = $propval
235 }
236}
237
e5a5a138
RK
238# Round up the maximum value to a whole number of subtables
239$max += ($modulus - 1) - ($max % $modulus);
61507e3c 240
bcf9ed7f
RK
241# Private use characters
242# We only fill in values below $max, utf32__unidata()
243my $Co = {
244 "gc" => "Co",
245 "ccc" => 0,
246 "ud" => 0,
247 "ld" => 0
248};
249for(my $c = 0xE000; $c <= 0xF8FF && $c <= $max; ++$c) {
250 $data{$c} = $Co;
251}
252for(my $c = 0xF0000; $c <= 0xFFFFD && $c <= $max; ++$c) {
253 $data{$c} = $Co;
254}
255for(my $c = 0x100000; $c <= 0x10FFFD && $c <= $max; ++$c) {
256 $data{$c} = $Co;
257}
258
259# Anything left is not assigned
260my $Cn = {
261 "gc" => "Cn", # not assigned
262 "ccc" => 0,
263 "ud" => 0,
264 "ld" => 0
265};
61507e3c
RK
266for(my $c = 0; $c <= $max; ++$c) {
267 if(!exists $data{$c}) {
bcf9ed7f
RK
268 $data{$c} = $Cn;
269 }
270 if(!exists $data{$c}->{wbreak}) {
271 $data{$c}->{wbreak} = 'Other';
272 }
273 if(!exists $data{$c}->{gbreak}) {
274 $data{$c}->{gbreak} = 'Other';
275 }
276 if(!exists $data{$c}->{sbreak}) {
277 $data{$c}->{sbreak} = 'Other';
61507e3c
RK
278 }
279}
280$cats{'Cn'} = 1;
281
e5a5a138 282# Read the casefolding data too
0b7052da 283input("CaseFolding.txt");
e5a5a138
RK
284while(<>) {
285 chomp;
286 next if /^\#/ or $_ eq '';
287 my @f = split(/\s*;\s*/, $_);
288 # Full case folding means use status C and F.
289 # We discard status T, Turkish users may wish to change this.
290 if($f[1] eq 'C' or $f[1] eq 'F') {
291 my $c = hex($f[0]);
292 $data{$c}->{casefold} = $f[2];
293 # We are particularly interest in combining characters that
294 # case-fold to non-combining characters, or characters that
295 # case-fold to sequences with combining characters in non-initial
296 # positions, as these required decomposiiton before case-folding
297 my @d = map(hex($_), split(/\s+/, $data{$c}->{casefold}));
298 if($data{$c}->{ccc} != 0) {
299 # This is a combining character
300 if($data{$d[0]}->{ccc} == 0) {
301 # The first character of its case-folded form is NOT
302 # a combining character. The field name is the example
303 # explicitly mentioned in the spec.
304 $data{$c}->{ypogegrammeni} = 1;
305 }
306 } else {
307 # This is a non-combining character; inspect the non-initial
308 # code points of the case-folded sequence
309 shift(@d);
310 if(grep($data{$_}->{ccc} != 0, @d)) {
311 # Some non-initial code point in the case-folded for is NOT a
312 # a combining character.
313 $data{$c}->{ypogegrammeni} = 1;
314 }
315 }
316 }
317}
318
319# Generate the header file
bcf9ed7f 320print STDERR "Generating unidata.h...\n";
61507e3c
RK
321open(STDOUT, ">unidata.h") or die "unidata.h: $!\n";
322
e5a5a138
RK
323out("/* Automatically generated file, see scripts/make-unidata */\n",
324 "#ifndef UNIDATA_H\n",
61507e3c
RK
325 "#define UNIDATA_H\n");
326
e5a5a138 327# TODO choose stable values for General_Category
14523635 328out("enum unicode_General_Category {\n",
61507e3c 329 join(",\n",
14523635 330 map(" unicode_General_Category_$_", sort keys %cats)), "\n};\n");
e5a5a138 331
349b7b74
RK
332out("enum unicode_Grapheme_Break {\n",
333 join(",\n",
334 map(" unicode_Grapheme_Break_$_", sort keys %gbreak)),
335 "\n};\n");
336out("extern const char *const unicode_Grapheme_Break_names[];\n");
337
0b7052da
RK
338out("enum unicode_Word_Break {\n",
339 join(",\n",
349b7b74 340 map(" unicode_Word_Break_$_", sort keys %wbreak)),
0b7052da 341 "\n};\n");
bb48024f 342out("extern const char *const unicode_Word_Break_names[];\n");
0b7052da 343
349b7b74
RK
344out("enum unicode_Sentence_Break {\n",
345 join(",\n",
346 map(" unicode_Sentence_Break_$_", sort keys %sbreak)),
347 "\n};\n");
348out("extern const char *const unicode_Sentence_Break_names[];\n");
349
e5a5a138 350out("enum unicode_flags {\n",
f98fcddb
RK
351 " unicode_normalize_before_casefold = 1,\n",
352 " unicode_compatibility_decomposition = 2\n",
e5a5a138
RK
353 "};\n",
354 "\n");
355
356# Choose the narrowest type that will fit the required values
357sub choosetype {
358 my ($min, $max) = @_;
359 if($min >= 0) {
360 return "char" if $max <= 127;
361 return "unsigned char" if $max <= 255;
362 return "int16_t" if $max < 32767;
363 return "uint16_t" if $max < 65535;
364 return "int32_t";
365 } else {
366 return "char" if $min >= -127 && $max <= 127;
367 return "int16_t" if $min >= -32767 && $max <= 32767;
368 return "int32_t";
369 }
370}
371
61507e3c 372out("struct unidata {\n",
99695df9
RK
373 # decomposition (canonical or compatibility;
374 # unicode_compatibility_decomposition distinguishes) or NULL
f98fcddb 375 " const uint32_t *decomp;\n",
99695df9
RK
376
377 # case-folded string or NULL
e5a5a138 378 " const uint32_t *casefold;\n",
99695df9
RK
379
380 # composed characters that start with this code point. This only
381 # includes primary composites, i.e. the decomposition mapping is
382 # canonical and this code point is not in the exclusion table.
383 " const uint32_t *composed;\n",
384
1a05e381
RK
385# " ".choosetype($minud, $maxud)." upper_offset;\n",
386# " ".choosetype($minld, $maxld)." lower_offset;\n",
99695df9
RK
387
388 # canonical combining class
e5a5a138 389 " ".choosetype(0, $maxccc)." ccc;\n",
14523635 390 " char general_category;\n",
99695df9
RK
391
392 # see unicode_flags enum
e5a5a138 393 " uint8_t flags;\n",
349b7b74 394 " char grapheme_break;\n",
0b7052da 395 " char word_break;\n",
349b7b74 396 " char sentence_break;\n",
61507e3c 397 "};\n");
f98fcddb 398# decomp and casefold do have have non-BMP characters, so we
e5a5a138
RK
399# can't use a simple 16-bit table. We could use UTF-8 or UTF-16
400# though, saving a bit of space (probably not that much...) at the
401# cost of marginally reduced performance and additional complexity
61507e3c
RK
402
403out("extern const struct unidata *const unidata[];\n");
404
18cda350
RK
405out("extern const struct unicode_utf8_row {\n",
406 " uint8_t count;\n",
407 " uint8_t min2, max2;\n",
408 "} unicode_utf8_valid[];\n");
409
61507e3c 410out("#define UNICODE_NCHARS ", ($max + 1), "\n");
e5a5a138 411out("#define UNICODE_MODULUS $modulus\n");
1a05e381
RK
412out("#define UNICODE_BREAK_START $break_start\n");
413out("#define UNICODE_BREAK_END $break_end\n");
414out("#define UNICODE_BREAK_TOP $break_top\n");
61507e3c
RK
415
416out("#endif\n");
417
418close STDOUT or die "unidata.h: $!\n";
419
bcf9ed7f 420print STDERR "Generating unidata.c...\n";
61507e3c
RK
421open(STDOUT, ">unidata.c") or die "unidata.c: $!\n";
422
e5a5a138
RK
423out("/* Automatically generated file, see scripts/make-unidata */\n",
424 "#include <config.h>\n",
425 "#include \"types.h\"\n",
426 "#include \"unidata.h\"\n");
427
349b7b74 428# Short aliases to keep .c file small
e5a5a138 429
14523635
RK
430out(map(sprintf("#define %s unicode_General_Category_%s\n", $_, $_),
431 sort keys %cats));
432out(map(sprintf("#define GB%s unicode_Grapheme_Break_%s\n", $_, $_),
433 sort keys %gbreak));
434out(map(sprintf("#define WB%s unicode_Word_Break_%s\n", $_, $_),
435 sort keys %wbreak));
436out(map(sprintf("#define SB%s unicode_Sentence_Break_%s\n", $_, $_),
437 sort keys %sbreak));
99695df9
RK
438out("#define NBC unicode_normalize_before_casefold\n");
439out("#define CD unicode_compatibility_decomposition\n");
e5a5a138 440
349b7b74
RK
441# Names for *_Break properties
442out("const char *const unicode_Grapheme_Break_names[] = {\n",
443 join(",\n",
444 map(" \"$_\"", sort keys %gbreak)),
445 "\n};\n");
bb48024f
RK
446out("const char *const unicode_Word_Break_names[] = {\n",
447 join(",\n",
349b7b74
RK
448 map(" \"$_\"", sort keys %wbreak)),
449 "\n};\n");
450out("const char *const unicode_Sentence_Break_names[] = {\n",
451 join(",\n",
452 map(" \"$_\"", sort keys %sbreak)),
bb48024f
RK
453 "\n};\n");
454
99695df9
RK
455our $ddnum = 0;
456our $ddsaved = 0;
457our %ddnums = ();
458my $ddfirst = 1;
459out("static const uint32_t ");
460sub dedupe {
461 my $s = join(",", @_);
462 if(!exists $ddnums{$s}) {
463 if($ddfirst) {
464 $ddfirst = 0;
465 } else {
466 out(",\n");
467 }
468 out("dd$ddnum\[]={$s}");
469 $ddnums{$s} = $ddnum++;
470 } else {
471 ++$ddsaved;
472 }
473 return "dd$ddnums{$s}";
474}
475
e5a5a138
RK
476# Generate the decomposition mapping tables. We look out for duplicates
477# in order to save space and report this as decompsaved at the end. In
478# Unicode 5.0.0 this saves 1795 entries, which is at least 14Kbytes.
99695df9 479print STDERR "> decomposition mappings\n";
e5a5a138 480for(my $c = 0; $c <= $max; ++$c) {
f98fcddb 481 if(exists $data{$c} && exists $data{$c}->{decomp}) {
99695df9
RK
482 $data{$c}->{decompsym} = dedupe(@{$data{$c}->{decomp}}, 0);
483 }
484}
485
486print STDERR "> composition mappings\n";
487# First we must generate the mapping of each code point to possible
488# compositions
489for(my $c = 0; $c <= $max; ++$c) {
490 if(exists $data{$c}
491 && exists $data{$c}->{decomp}
492 && !exists $data{$c}->{compat}
493 && !$data{$c}->{Full_Composition_Exclusion}) {
494 # $c has a non-excluded canonical decomposition, i.e. it is
495 # a primary composite. Find the first code point of the decomposition
496 my $first = ${$data{$c}->{decomp}}[0];
497 if(!exists $data{$first}->{compose}) {
498 $data{$first}->{compose} = [$first];
e5a5a138 499 } else {
99695df9 500 push(@{$data{$first}->{compose}}, $first);
e5a5a138 501 }
e5a5a138
RK
502 }
503}
99695df9
RK
504for(my $c = 0; $c <= $max; ++$c) {
505 if(exists $data{$c} && exists $data{$c}->{compose}) {
506 $data{$c}->{compsym} = dedupe(@{$data{$c}->{compose}}, 0);
507 }
508}
e5a5a138
RK
509
510# ...and the case folding table. Again we compress equal entries to save
511# space. In Unicode 5.0.0 this saves 51 entries or at least 408 bytes.
512# This doesns't seem as worthwhile as the decomposition mapping saving above.
99695df9 513print STDERR "> case-fold mappings\n";
e5a5a138 514for(my $c = 0; $c <= $max; ++$c) {
bcf9ed7f 515 if(exists $data{$c} && exists $data{$c}->{casefold}) {
99695df9
RK
516 $data{$c}->{cfsym} = dedupe(map(hex($_), split(/\s+/,
517 $data{$c}->{casefold})),
518 0);
e5a5a138
RK
519 }
520}
99695df9
RK
521
522# End of de-dupable arrays
e5a5a138
RK
523out(";\n");
524
525# Visit all the $modulus-character blocks in turn and generate the
526# required subtables. As above we spot duplicates to save space. In
527# Unicode 5.0.0 with $modulus=128 and current table data this saves
528# 1372 subtables or at least three and a half megabytes on 32-bit
529# platforms.
99695df9 530print STDERR "> subtables\n";
61507e3c
RK
531my %subtable = (); # base->subtable number
532my %subtableno = (); # subtable number -> content
533my $subtablecounter = 0; # counter for subtable numbers
e5a5a138
RK
534my $subtablessaved = 0; # number of tables saved
535for(my $base = 0; $base <= $max; $base += $modulus) {
1a05e381
RK
536 next if $base >= $break_start && $base < $break_end;
537 next if $base >= $break_top;
61507e3c 538 my @t;
e5a5a138 539 for(my $c = $base; $c < $base + $modulus; ++$c) {
61507e3c 540 my $d = $data{$c};
f98fcddb 541 my $decompsym = ($data{$c}->{decompsym} or "0");
e5a5a138 542 my $cfsym = ($data{$c}->{cfsym} or "0");
99695df9 543 my $compsym = ($data{$c}->{compsym} or "0");
35b651f0
RK
544 my @flags = ();
545 if($data{$c}->{ypogegrammeni}) {
99695df9 546 push(@flags, "NBC");
35b651f0 547 }
f98fcddb 548 if($data{$c}->{compat}) {
99695df9 549 push(@flags, "CD");
f98fcddb 550 }
35b651f0 551 my $flags = @flags ? join("|", @flags) : 0;
e5a5a138
RK
552 push(@t, "{".
553 join(",",
f98fcddb 554 $decompsym,
e5a5a138 555 $cfsym,
99695df9 556 $compsym,
1a05e381
RK
557# $d->{ud},
558# $d->{ld},
0b7052da
RK
559 $d->{ccc},
560 $d->{gc},
e5a5a138 561 $flags,
349b7b74
RK
562 "GB$d->{gbreak}",
563 "WB$d->{wbreak}",
564 "SB$d->{sbreak}",
e5a5a138 565 )."}");
61507e3c
RK
566 }
567 my $t = join(",\n", @t);
568 if(!exists $subtable{$t}) {
0e843521 569 out(sprintf("/* %04X-%04X */\n", $base, $base + $modulus - 1));
e5a5a138 570 out("static const struct unidata st$subtablecounter\[] = {\n",
61507e3c
RK
571 "$t\n",
572 "};\n");
573 $subtable{$t} = $subtablecounter++;
e5a5a138
RK
574 } else {
575 ++$subtablessaved;
61507e3c
RK
576 }
577 $subtableno{$base} = $subtable{$t};
578}
579
99695df9 580print STDERR "> main table\n";
bcf9ed7f 581out("const struct unidata *const unidata[]={\n");
e5a5a138 582for(my $base = 0; $base <= $max; $base += $modulus) {
1a05e381
RK
583 next if $base >= $break_start && $base < $break_end;
584 next if $base >= $break_top;
0a4af692 585 #out("st$subtableno{$base} /* ".sprintf("%04x", $base)." */,\n");
e5a5a138 586 out("st$subtableno{$base},\n");
61507e3c
RK
587}
588out("};\n");
589
99695df9 590print STDERR "> UTF-8 table\n";
18cda350
RK
591out("const struct unicode_utf8_row unicode_utf8_valid[] = {\n");
592for(my $c = 0; $c <= 0x7F; ++$c) {
593 out(" { 1, 0, 0 }, /* $c */\n");
594}
595for(my $c = 0x80; $c < 0xC2; ++$c) {
596 out(" { 0, 0, 0 }, /* $c */\n");
597}
598for(my $c = 0xC2; $c <= 0xDF; ++$c) {
599 out(" { 2, 0x80, 0xBF }, /* $c */\n");
600}
601for(my $c = 0xE0; $c <= 0xE0; ++$c) {
602 out(" { 3, 0xA0, 0xBF }, /* $c */\n");
603}
604for(my $c = 0xE1; $c <= 0xEC; ++$c) {
605 out(" { 3, 0x80, 0xBF }, /* $c */\n");
606}
607for(my $c = 0xED; $c <= 0xED; ++$c) {
608 out(" { 3, 0x80, 0x9F }, /* $c */\n");
609}
610for(my $c = 0xEE; $c <= 0xEF; ++$c) {
611 out(" { 3, 0x80, 0xBF }, /* $c */\n");
612}
613for(my $c = 0xF0; $c <= 0xF0; ++$c) {
614 out(" { 4, 0x90, 0xBF }, /* $c */\n");
615}
616for(my $c = 0xF1; $c <= 0xF3; ++$c) {
617 out(" { 4, 0x80, 0xBF }, /* $c */\n");
618}
619for(my $c = 0xF4; $c <= 0xF4; ++$c) {
620 out(" { 4, 0x80, 0x8F }, /* $c */\n");
621}
622for(my $c = 0xF5; $c <= 0xFF; ++$c) {
623 out(" { 0, 0, 0 }, /* $c */\n");
624}
625out("};\n");
626
61507e3c
RK
627close STDOUT or die "unidata.c: $!\n";
628
99695df9 629print STDERR "Done.\n\n";
c2e01e0a 630printf STDERR "modulus=%d\n", $modulus;
bcf9ed7f
RK
631printf STDERR "max=%04X\n", $max;
632print STDERR "subtables=$subtablecounter, subtablessaved=$subtablessaved\n";
99695df9 633print STDERR "ddsaved=$ddsaved\n";