summaryrefslogtreecommitdiff
path: root/ext/Encode/ucm2table
blob: 85b2c2e692236fcdd8fe6e6eefa5948ce7ec8aae (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
#!/usr/bin/perl

use 5.006;
use strict;
use Getopt::Std;
my %Opt;
getopts("eu", \%Opt);
my @Chartab;

my $Hex = '[0-9A-Fa-f]';
while(<>){
	chomp;
	my ($uni, $enc, $fb, $comment) = 
	    /^<U($Hex+)>\s+(\S+)\s+\|(\d)\s+#\s+(.*)$/o or next;
	$comment =~ /<control>/io and next;
	$comment =~ /^DELETE/o and next;
	# print "$uni $enc $fb $comment\n";
	my @byte = ();
	my $ord = 0;
	while($enc =~ /\G\\x($Hex+)/iog){
	    my $byte = hex($1);
	    push @byte, $byte;
	    $ord <<= 8; $ord += $byte;
	};
	# print join('', @byte), " => $ord \n";
	if ($Opt{u}){
	    $Chartab[$ord] = pack("U", hex($uni));
	}else{
	    $Chartab[$ord] = pack("C*", @byte);
	}
}

for (my $x = 0x20; $x <= 0xffff; $ x+= 32) {
    my $line =  '';
    for my $i (0..31){
	my $char = $Chartab[$x+$i];
	$line .= !$char ? " " : 
	    ($x+$i < 0x7f ) ? " $char" : $char ;
    }
    $line =~ /^\s+$/o and next;
    printf "0x%04x: $line\n", $x;
}