summaryrefslogtreecommitdiff
path: root/tools/compress-table.pl
blob: a11f3d8a038cd2a44873a154161a2a6ef3764337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl -w

sub convert {
    $s = shift;
    $s = "ENC_".uc($s);
    $s =~ s/-/_/g;
    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 = "";

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) {
	    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";