Imported Upstream version 0.66.1
[hcoop/debian/courier-authlib.git] / libs / unicode / mkeastasianwidth.pl
1 #! /usr/bin/perl
2
3 # USAGE: perl mkeastasianwidth.pl > charwidth.c
4
5 use IO::File;
6
7 my $fh=new IO::File "<EastAsianWidth.txt";
8
9 my $pb=-1;
10 my $pe=-1;
11
12 print "static const unicode_char unicode_wcwidth_tab[][2]={\n";
13
14 sub full($$) {
15 my $b=hex(shift);
16 my $e=hex(shift);
17
18 if ($b == $pe+1)
19 {
20 $pe=$e;
21 return;
22 }
23
24 printf ("{0x%04x, 0x%04x},\n", $pb, $pe) unless $pb < 0;
25
26 $pb=$b;
27 $pe=$e;
28 }
29
30
31 while (defined($_=<$fh>))
32 {
33 chomp;
34 s/#.*//;
35
36 my @w=split(/;/);
37
38 grep {s/^\s*//; s/\s*$//; } @w;
39
40 next unless $w[1] eq "F" || $w[1] eq "W";
41
42 if ($w[0] =~ /(.*)\.\.(.*)/)
43 {
44 full($1, $2);
45 }
46 else
47 {
48 full($w[0], $w[0]);
49 }
50 }
51
52 printf ("{0x%04x, 0x%04x}\n};\n", $pb, $pe);