3 # Script to convert http://www.unicode.org/Public/UNIDATA/Scripts.txt
4 # into a machine-readable table.
6 ######################################################################
9 die "Usage: gen-script-table.pl Scripts.txt > gscripttable.h\n";
12 open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
24 if (/^\#\s+(Scripts-.*.txt)/) {
30 if (!/^([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s*;\s*([A-Za-z_]+)\s*$/) {
31 die "Cannot parse line: '$_'\n";
35 push @ranges, [ hex $1, hex $2, uc $3 ];
37 push @ranges, [ hex $1, hex $1, uc $3 ];
41 @ranges = sort { $a->[0] <=> $b->[0] } @ranges;
45 /* gscripttable.h: Generated by gen-script-table.pl
58 #define G_EASY_SCRIPTS_RANGE $easy_range
60 static const guchar g_script_easy_table[$easy_range] = {
66 for (my $c = 0; $c < $easy_range; $c++) {
73 $start = $ranges[$i]->[0];
74 $end = $ranges[$i]->[1];
75 $script = $ranges[$i]->[2];
80 printf " G_UNICODE_SCRIPT_UNKNOWN,";
82 printf " G_UNICODE_SCRIPT_%s,", $script;
86 if ($end >= $easy_range) {
88 $ranges[$i]->[0] = $easy_range;
100 } g_script_table[] = {
103 for (; $i <= $#ranges; $i++) {
104 $start = $ranges[$i]->[0];
105 $end = $ranges[$i]->[1];
106 $script = $ranges[$i]->[2];
108 while ($i <= $#ranges - 1 &&
109 $ranges[$i + 1]->[0] == $end + 1 &&
110 $ranges[$i + 1]->[2] eq $script) {
112 $end = $ranges[$i]->[1];
115 printf " { %#06x, %5d, G_UNICODE_SCRIPT_%s },\n", $start, $end - $start + 1, $script;