root/lang/perl/Encode-JP-Mobile/trunk/tools/softbank-convert.pl @ 5328

Revision 5328, 1.6 kB (checked in by miyagawa, 7 years ago)

print compatible table

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2use strict;
3use warnings;
4use utf8;
5use Encode;
6use LWP::Simple;
7use YAML;
8
9my $text = decode("shift_jis", get("http://miyagawa.googlepages.com/convert.txt"));
10   $text =~ tr/\r//d;
11
12my $from_number = {};
13setup_table($from_number);
14
15my @table;
16my %conv;
17for (split /\n/, $text) {
18    next unless /^\d/;
19    chomp;
20
21    # 89468 = 8 95 68
22    # 169102 = 169 102
23    s/^(\d)(\d{2})(\d{2})$/$1 $2 $3/;
24    s/(\d{3})(\d{3})/$1 $2/;
25
26    # 拡02 => 拡2
27    s/拡0(\d)/拡$1/;
28
29    my %map;
30    @map{qw( softbank kddi docomo )} = split / (?:\- )?/, $_, 3;
31
32    for my $c ( qw( softbank kddi docomo )) {
33        warn "[$c] $_" unless defined $map{$c};
34        my $key = $c eq 'kddi' ? 'unicode_auto' : 'unicode';
35        if ($map{$c} =~ m!/!) {
36            my @code = split '/', $map{$c};
37            $map{$c} = join "", map $from_number->{$c}{$_}{$key}, @code;
38        } else {
39            my $info = $from_number->{$c}{$map{$c}};
40            if ($info) {
41                $map{$c} = $info->{$key};
42            } elsif ($map{$c} ne '〓' && $map{$c} !~ /^\[/) {
43                warn "$c: $map{$c}";
44            }
45        }
46    }
47
48    push @table, \%map;
49    $conv{$map{softbank}} = {
50        kddi => $map{kddi},
51        docomo => $map{docomo},
52    };
53}
54
55binmode STDOUT, ":utf8";
56#print Dump \@table;
57print Dump \%conv;
58
59sub setup_table {
60    my $from_number = shift;
61    for my $c ( qw( docomo kddi softbank ) ) {
62        my $dat = YAML::LoadFile("dat/$c-table.yaml");
63        for my $row (@$dat) {
64            $from_number->{$c}{ decode_utf8($row->{number}) } = $row;
65        }
66    }
67}
Note: See TracBrowser for help on using the browser.