~ubuntu-branches/ubuntu/karmic/pango1.0/karmic-security

« back to all changes in this revision

Viewing changes to tools/gen-script-table.pl

Tags: upstream-1.15.4
ImportĀ upstreamĀ versionĀ 1.15.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w 
 
2
#
 
3
# Script to convert http://www.unicode.org/Public/UNIDATA/Scripts.txt
 
4
# into a machine-readable table.
 
5
#
 
6
######################################################################
 
7
 
 
8
if (@ARGV != 1) {
 
9
    die "Usage: gen-script-table.pl Scripts.txt > pango-script-table.h\n";
 
10
}
 
11
 
 
12
open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
 
13
 
 
14
my @ranges;
 
15
my $file;
 
16
my $easy_range;
 
17
my $i;
 
18
my $start;
 
19
my $end;
 
20
my $script;
 
21
 
 
22
 
 
23
while (<IN>) {
 
24
    if (/^\#\s+(Scripts-.*.txt)/) {
 
25
        $file = $1;
 
26
    }
 
27
    
 
28
    s/#.*//;
 
29
    next if /^\s*$/;
 
30
    if (!/^([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s*;\s*([A-Za-z_]+)\s*$/) {
 
31
        die "Cannot parse line: '$_'\n";
 
32
    }
 
33
 
 
34
    if (defined $2) {
 
35
        push @ranges, [ hex $1, hex $2, uc $3 ];
 
36
    } else {
 
37
        push @ranges, [ hex $1, hex $1, uc $3 ];
 
38
    }
 
39
}
 
40
 
 
41
@ranges = sort { $a->[0] <=> $b->[0] } @ranges;
 
42
$date = gmtime;
 
43
 
 
44
print <<"EOT";
 
45
/* pango-script-table.h: Generated by gen-script-table.pl
 
46
 *
 
47
 *  Date: $date
 
48
 *  Source: $file
 
49
 *
 
50
 * Do not edit.
 
51
 */
 
52
 
 
53
EOT
 
54
 
 
55
$easy_range = 0x2000;
 
56
 
 
57
print <<"EOT";
 
58
static const guchar pango_script_easy_table[$easy_range] = {
 
59
EOT
 
60
 
 
61
$i = 0;
 
62
$end = -1;
 
63
 
 
64
for (my $c = 0; $c < $easy_range; $c++) {
 
65
 
 
66
    if ($c % 3 == 0) {
 
67
      printf "\n ";
 
68
    }
 
69
 
 
70
    if ($c > $end) {
 
71
        $start = $ranges[$i]->[0];
 
72
        $end = $ranges[$i]->[1];
 
73
        $script = $ranges[$i]->[2];
 
74
        $i++;
 
75
    }
 
76
    
 
77
    if ($c < $start) {
 
78
        printf " PANGO_SCRIPT_UNKNOWN,";
 
79
    } else {
 
80
        printf " PANGO_SCRIPT_%s,", $script;
 
81
    }
 
82
}
 
83
 
 
84
if ($end >= $easy_range) {
 
85
    $i--;
 
86
    $ranges[$i]->[0] = $easy_range;
 
87
}
 
88
 
 
89
 
 
90
print <<"EOT";
 
91
 
 
92
};
 
93
 
 
94
static const struct {
 
95
    gunichar    start;
 
96
    guint16     chars;
 
97
    guint16     script;
 
98
} pango_script_table[] = { 
 
99
EOT
 
100
 
 
101
for (; $i <= $#ranges; $i++) {
 
102
    $start = $ranges[$i]->[0];
 
103
    $end = $ranges[$i]->[1];
 
104
    $script = $ranges[$i]->[2];
 
105
 
 
106
    while ($i <= $#ranges - 1 &&
 
107
           $ranges[$i + 1]->[0] == $end + 1 &&
 
108
           $ranges[$i + 1]->[2] eq $script) {
 
109
        $i++;
 
110
        $end = $ranges[$i]->[1];
 
111
    }
 
112
 
 
113
    printf " { %#06x, %5d, PANGO_SCRIPT_%s },\n", $start, $end - $start + 1, $script;
 
114
}
 
115
 
 
116
printf "};\n";
 
117