summaryrefslogtreecommitdiffstats
path: root/src/gencompose
blob: 4b65c394ad180c0a7e0348ceb5f317aab42f96a6 (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
#!/usr/bin/perl

open UNIDATA, "<", "www.unicode.org/Public/UNIDATA/UnicodeData.txt"
   or die "www.unicode.org/Public/UNIDATA/UnicodeData.txt: $!";
#my %docom = qw(initial | medial | final | isolated | compat | none |); #+ arabic
my %docom = qw(compat | none |);

while (<UNIDATA>) {
   my ($code, undef, $category, undef, undef, $decompose, undef) = split /;/;

   push @cat_z, $code if $category =~ /^Z/;

   if ($decompose) {
      $type = $decompose =~ s/^<(.*)>\s*// ? $1 : "none";

      next unless $docom{$type};
      next unless $decompose =~ /^([0-9a-f]+) ([0-9a-f]+)$/i;
      my $pfx = sprintf "%08d %08d %08d", hex $1, hex $2, hex $code;
      push @compose, [$pfx, hex $1, hex $2, hex $code];
   }
}

open TABLE, ">", "table/compose.h"
   or die "table/compose.h: $!";

print TABLE <<EOF;
//
// AUTOMATICALLLY GENERATED by gencompose
//

struct rxvt_compose_entry {
   uint32_t c1, c2, r;
} rxvt_compose_table[] = {
#ifdef ENCODING_COMPOSE
EOF

for (sort { $a->[0] cmp $b->[0] } @compose) {
   next if $seen{$_->[1],$_->[2]}++;
   printf TABLE " { 0x%05x, 0x%05x, 0x%05x },\n", $_->[1], $_->[2], $_->[3];
}


print TABLE <<EOF;
#endif
};
EOF

open TABLE_Z, ">", "table/category.h";

print TABLE_Z <<EOF;
//
// AUTOMATICALLLY GENERATED by gencompose
//

#define IS_SPACE(c)	\\
EOF

for (@cat_z) {
   print TABLE_Z "	(c) == 0x$_ || \\\n";
}

print TABLE_Z "	0\n";