OSDN Git Service

Support FreeWnn.
[canna-yubin/canna-yubin.git] / yu2.PL
1 #! /usr/bin/env perl
2 #
3 # Copyright (C) 2001 Yoshito Komatsu
4 #               2014 Mitsutoshi NAKANO <bkbin005@rinku.zaq.ne.jp>
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 2 of the License,
8 # or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.
13 # See the GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA 02110-1301, USA.
19 #
20 # yu2.PL - convert CSV file to Canna|Wnn dictionary
21
22 use strict;
23 use warnings;
24 use utf8;
25 use Getopt::Long;
26
27 use constant {
28     CANNA => 'canna',
29     WNN => 'wnn',
30 };
31
32 sub usage()
33 {
34     print STDERR "usage: yu2.PL [--yubin KEN_ALL.CSV] [--jigyosho JIGYOSYO.CSV] [--ime={canna|wnn}]";
35     exit(2);
36 }
37
38 sub printCANNAyubin($$)
39 {
40     my ($seven, $jusho) = @_;
41     print "${seven} \#CN ${jusho}\n";
42 }
43
44 sub printCANNAjigyosho($$$)
45 {
46     my ($seven, $jigyosho, $jusho) = @_;
47     print "${seven} \#CN ${jigyosho} ${jusho}\n";
48 }
49
50 sub printWNNyubin($$)
51 {
52     my ($seven, $jusho) = @_;
53     print "${seven} ${jusho} 地名 0\n";
54 }
55
56
57 sub printWNNjigyosho($$$)
58 {
59     my ($seven, $jigyosho, $jusho) = @_;
60     print "${seven} ${jigyosho} 地名 0\n";
61     print "${seven} ${jusho} 地名 0\n";
62 }
63
64
65
66 my ($yubin, $jigyosho, $ime) = ('./KEN_ALL.CSV', './JIGYOSYO.CSV', CANNA);
67 GetOptions(
68     "yubin=s" => \$yubin,
69     "jigyosho=s" => \$jigyosho,
70     "ime=s" => \$ime,
71     ) or usage();
72
73 my ($printlineYubin, $printlineJigyosho)
74     = (\&printCANNAyubin, \&printCANNAjigyosho);
75 if ("$ime" eq WNN) {
76     $printlineYubin = \&printWNNyubin;
77     $printlineJigyosho = \&printWNNjigyosho
78 } elsif ("$ime" eq CANNA) {
79 } else { usage(); };
80
81
82 binmode STDOUT, ':encoding(EUC-JP)';
83
84 open(CSV, $yubin);
85 binmode CSV, ':encoding(Shift_JIS)';
86 while (<CSV>) {
87     $_ =~ tr/\"//d;
88     my @tmp = split (/\,/, $_);
89     &$printlineYubin($tmp[2], "$tmp[6]$tmp[7]$tmp[8]");
90 }
91 close (CSV);
92
93 open(CSV, $jigyosho);
94 binmode CSV, ':encoding(Shift_JIS)';
95 while (<CSV>) {
96     $_ =~ tr/\"//d;
97     my @tmp = split (/\,/, $_);
98     &$printlineJigyosho("$tmp[7]", "$tmp[2]", "$tmp[3]$tmp[4]$tmp[5]$tmp[6]");
99
100 }
101 close (CSV);