diff options
Diffstat (limited to 'tools/compress-table.pl')
-rwxr-xr-x | tools/compress-table.pl | 91 |
1 files changed, 78 insertions, 13 deletions
diff --git a/tools/compress-table.pl b/tools/compress-table.pl index 83b268cb..a11f3d8a 100755 --- a/tools/compress-table.pl +++ b/tools/compress-table.pl @@ -7,6 +7,37 @@ sub convert { return $s; } +$combo_index = 1; + +sub add { + my $combo = shift; + if (!exists($combos{$combo})) { + $combos{$combo} = $combo_index++; + printf " $combo,\n", $combos{$combo}; + } +} + +my $col = 0; + +sub output { + my ($start,$u,$index) = @_; + + for (my $i = $start; $i < $u; $i++) { + print " 0,"; + $col = ($col + 1) % 16; + if ($col == 0) { + print "\n"; + } + } + printf " %2d,", $index; + $col = ($col + 1) % 16; + if ($col == 0) { + print "\n"; + } +} + +print "const guint32 char_mask_map[] = {\n 0,\n"; + open TABLE, "table"; $encodings = ""; @@ -16,28 +47,62 @@ while (<TABLE>) { ($u, $e) = ($1, $2); $u = oct($u); - - if (!defined $start) { - $start = $u; + + if (!defined $old_u) { $old_u = $u; $encodings = convert($e); - $end = $u; } elsif ($old_u ne $u) { - if (!defined $old_encodings) { - $old_encodings = $encodings; - } elsif ($old_encodings ne $encodings || $old_u != $end + 1) { - - printf "{ %#x, %#x, $old_encodings },\n", $start, $end; - $start = $old_u; - $old_encodings = $encodings; - } - $end = $old_u; + add($encodings); + $old_u = $u; + $encodings = convert($e); + } else { + $encodings .= "|".convert($e); + } + } +} + +if (defined $old_u) { + add($encodings); +} + +close TABLE; + +print <<EOF; +}; + +const guchar char_masks[] = { +EOF + +open TABLE, "table"; + +$encodings = ""; + +undef $old_u; +$start = 0; +while (<TABLE>) { + if (/^(0x[0-9a-fA-F]+)\s+([^:]*):(0x[0-9a-fA-F]+)/) { + ($u, $e) = ($1, $2); + + $u = oct($u); + + if (!defined $old_u) { + $old_u = $u; $encodings = convert($e); + } elsif ($old_u ne $u) { + output($start, $old_u, $combos{$encodings}); + $start = $old_u + 1; $old_u = $u; + $encodings = convert($e); } else { $encodings .= "|".convert($e); } } } +if (defined $old_u) { + output($start, $old_u, $combos{$encodings}); +} + close TABLE; + +print "\n};\n"; |