From 575a979610045a8c80b54ae688be2045b56b97ad Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 9 Feb 2016 16:39:54 +0900 Subject: [PATCH] make_unicode: Support sparse arrays for character tables. Signed-off-by: Alexandre Julliard --- tools/make_unicode | 52 +++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/tools/make_unicode b/tools/make_unicode index 1c81a7e82ce..27d23bffb0e 100755 --- a/tools/make_unicode +++ b/tools/make_unicode @@ -351,8 +351,8 @@ my @tolower_table = (); my @toupper_table = (); my @digitmap_table = (); my @compatmap_table = (); -my @category_table = (0) x 65536; -my @joining_table = (0) x 65536; +my @category_table = (); +my @joining_table = (); my @direction_table = (); my @decomp_table = (); my @compose_table = (); @@ -1176,7 +1176,7 @@ sub get_lb_ranges() sub dump_indic($) { my $filename = shift; - my @indic_table = ($indic_types{'Other'}) x 65536; + my @indic_table; my $INPUT = open_data_file( $UNIDATA, "IndicSyllabicCategory.txt" ); while (<$INPUT>) @@ -1245,7 +1245,7 @@ sub dump_indic($) print OUTPUT "/* and from $UNIDATA/IndicPositionalCategory.txt */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "indic_syllabic_table", @indic_table); + dump_two_level_mapping( "indic_syllabic_table", $indic_types{'Other'}, @indic_table ); close OUTPUT; save_file($filename); @@ -1256,7 +1256,7 @@ sub dump_indic($) sub dump_linebreak($) { my $filename = shift; - my @break_table = ($break_types{'XX'}) x 65536; + my @break_table; my $next_group = 0; my $INPUT = open_data_file( $UNIDATA, "LineBreak.txt" ); @@ -1292,7 +1292,7 @@ sub dump_linebreak($) print OUTPUT "/* generated from $UNIDATA/LineBreak.txt */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "wine_linebreak_table", @break_table); + dump_two_level_mapping( "wine_linebreak_table", $break_types{'XX'}, @break_table ); close OUTPUT; save_file($filename); @@ -1304,7 +1304,7 @@ sub dump_scripts($) { my $filename = shift; my $header = $filename; - my @scripts_table = (0) x 65536; # 0 means unknown script + my @scripts_table; my $script_index; my %scripts; my $i; @@ -1406,7 +1406,7 @@ sub dump_scripts($) print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "wine_scripts_table", @scripts_table); + dump_two_level_mapping( "wine_scripts_table", 0, @scripts_table ); close OUTPUT; save_file($filename); } @@ -1449,7 +1449,7 @@ sub dump_mirroring($) sub dump_bracket($) { my $filename = shift; - my @bracket_table = (0) x 65536; + my @bracket_table; my $INPUT = open_data_file( $UNIDATA, "BidiBrackets.txt" ); while (<$INPUT>) @@ -1476,7 +1476,7 @@ sub dump_bracket($) print OUTPUT "/* generated from $UNIDATA/BidiBrackets.txt */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "bidi_bracket_table", @bracket_table); + dump_two_level_mapping( "bidi_bracket_table", 0, @bracket_table ); close OUTPUT; save_file($filename); @@ -1516,7 +1516,7 @@ sub dump_shaping($) print OUTPUT "/* generated from $UNIDATA/ArabicShaping.txt */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "wine_shaping_table", @joining_table ); + dump_two_level_mapping( "wine_shaping_table", 0, @joining_table ); print OUTPUT "\nconst unsigned short wine_shaping_forms[256][4] =\n{\n"; for (my $i = 0x600; $i <= 0x6ff; $i++) @@ -1538,7 +1538,7 @@ sub dump_shaping($) sub dump_vertical($) { my $filename = shift; - my @vertical_table = ($vertical_types{'R'}) x 65536; + my @vertical_table; my $INPUT = open_data_file( $VERTICALDATA, "VerticalOrientation-11.txt" ); while (<$INPUT>) @@ -1576,7 +1576,7 @@ sub dump_vertical($) print OUTPUT "/* generated from $VERTICALDATA/VerticalOrientation-11.txt */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "vertical_orientation_table", @vertical_table); + dump_two_level_mapping( "vertical_orientation_table", $vertical_types{'R'}, @vertical_table ); close OUTPUT; save_file($filename); @@ -1672,9 +1672,10 @@ sub DUMP_CASE_TABLE($@) ################################################################ # compress a mapping table by removing identical rows -sub compress_array($@) +sub compress_array($$@) { my $rows = shift; + my $def = shift; my @table = @_; my $len = @table / $rows; my @array = (0) x $rows; @@ -1683,7 +1684,8 @@ sub compress_array($@) # try to merge table rows for (my $row = 0; $row < $rows; $row++) { - my $rowtxt = pack "S*", @table[($row * $len)..($row * $len + $len - 1)]; + my @table_row = map { defined($_) ? $_ : $def; } @table[($row * $len)..($row * $len + $len - 1)]; + my $rowtxt = pack "S*", @table_row; if (defined($sequences{$rowtxt})) { # reuse an existing row @@ -1693,7 +1695,7 @@ sub compress_array($@) { # create a new row $sequences{$rowtxt} = $array[$row] = $#array + 1; - push @array, @table[$row * $len..$row * $len + $len - 1]; + push @array, @table_row; } } return @array; @@ -1701,10 +1703,11 @@ sub compress_array($@) ################################################################ # dump a simple char -> 16-bit value mapping table -sub dump_simple_mapping($@) +sub dump_simple_mapping($$@) { my $name = shift; - my @array = compress_array( 256, @_[0..65535] ); + my $def = shift; + my @array = compress_array( 256, $def, @_[0..65535] ); printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, $#array+1; printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] ); @@ -1713,11 +1716,12 @@ sub dump_simple_mapping($@) ################################################################ # dump a char -> 16-bit value mapping table using two-level tables -sub dump_two_level_mapping($@) +sub dump_two_level_mapping($$@) { my $name = shift; - my @row_array = compress_array( 4096, @_[0..65535] ); - my @array = compress_array( 256, @row_array[0..4095] ); + my $def = shift; + my @row_array = compress_array( 4096, $def, @_[0..65535] ); + my @array = compress_array( 256, 0, @row_array[0..4095] ); for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; } @@ -1880,7 +1884,7 @@ sub dump_nameprep($) { my $filename = shift; my @mapping_table = (); - my @flags_table = (0) x 65536; + my @flags_table; my $INPUT = open_data_file( $RFCS, $STRINGPREP ); while (<$INPUT>) @@ -1911,7 +1915,7 @@ sub dump_nameprep($) print OUTPUT "/* generated from $RFCS/$STRINGPREP */\n"; print OUTPUT "/* DO NOT EDIT!! */\n\n"; - dump_two_level_mapping( "nameprep_char_type", @flags_table ); + dump_two_level_mapping( "nameprep_char_type", 0, @flags_table ); ######### mapping table # first determine all the 16-char subsets that contain something @@ -2006,7 +2010,7 @@ sub DUMP_CTYPE_TABLES($) $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i]; } - dump_simple_mapping( "wine_wctype_table", @category_table ); + dump_simple_mapping( "wine_wctype_table", 0, @category_table ); close OUTPUT; save_file($filename);