OSDN Git Service

update data to 2021-04-30
[canna-yubin/canna-yubin.git] / yu2.PL
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use utf8;
6 use Getopt::Long;
7
8 use constant {
9     CANNA => 'canna',
10     WNN => 'wnn',
11 };
12
13 sub usage()
14 {
15     print STDERR "usage: yu2.PL [--yubin=KEN_ALL.CSV] [--jigyosho=JIGYOSYO.CSV] [--ime={canna|wnn}]
16
17 If you want see more detail, type 'pod2text yu2.PL'.
18 ";
19     exit(2);
20 }
21
22 sub printCANNAyubin($$)
23 {
24     my ($seven, $jusho) = @_;
25     print "${seven} \#CN ${jusho}\n";
26 }
27
28 sub printCANNAjigyosho($$$)
29 {
30     my ($seven, $jigyosho, $jusho) = @_;
31     print "${seven} \#CN ${jigyosho} ${jusho}\n";
32 }
33
34 sub printWNNyubin($$)
35 {
36     my ($seven, $jusho) = @_;
37     $seven =~ tr/0123456789/0123456789/;
38     print "${seven} ${jusho} 地名 0\n";
39 }
40
41 sub printWNNjigyosho($$$)
42 {
43     my ($seven, $jigyosho, $jusho) = @_;
44     $seven =~ tr/0123456789/0123456789/;
45     print "${seven} ${jigyosho} 地名 0\n";
46     print "${seven} ${jusho} 地名 0\n";
47 }
48
49
50 my ($yubin, $jigyosho, $ime) = ('./KEN_ALL.CSV', './JIGYOSYO.CSV', CANNA);
51 GetOptions(
52     "yubin=s" => \$yubin,
53     "jigyosho=s" => \$jigyosho,
54     "ime=s" => \$ime,
55     ) or usage();
56
57 my ($printlineYubin, $printlineJigyosho)
58     = (\&printCANNAyubin, \&printCANNAjigyosho);
59 if ("$ime" eq WNN) {
60     $printlineYubin = \&printWNNyubin;
61     $printlineJigyosho = \&printWNNjigyosho
62 } elsif ("$ime" eq CANNA) {
63 } else { usage(); };
64
65
66 binmode STDOUT, ':encoding(EUC-JP)';
67
68 open(CSV, $yubin);
69 binmode CSV, ':encoding(Shift_JIS)';
70 while (<CSV>) {
71     $_ =~ tr/\"//d;
72     my @tmp = split (/\,/, $_);
73     &$printlineYubin($tmp[2], "$tmp[6]$tmp[7]$tmp[8]");
74 }
75 close (CSV);
76
77 open(CSV, $jigyosho);
78 binmode CSV, ':encoding(Shift_JIS)';
79 while (<CSV>) {
80     $_ =~ tr/\"//d;
81     my @tmp = split (/\,/, $_);
82     &$printlineJigyosho("$tmp[7]", "$tmp[2]", "$tmp[3]$tmp[4]$tmp[5]$tmp[6]");
83
84 }
85 close (CSV);
86
87 =pod
88
89 =head1 NAME
90
91 yu2.PL - convert Japanese ZIP codes CSV files to Canna|(Free)Wnn's dictionary
92
93 =head1 SYNOPSIS
94
95 yu2.PL [--yubin=KEN_ALL.CSV] [--jigyosho=JIGYOSYO.CSV] [--ime={canna|wnn}]
96
97 =head1 DESCRIPTION
98
99 The yu2.PL is a program for converting from Japanese ZIP codes CSV files
100 to Canna|(Free)Wnn readable CSV files.
101
102 Japanese ZIP codes CSV files can get from JAPAN POST Co., Ltd.'s Web pages.
103
104 =head2 See
105
106 L<http://www.post.japanpost.jp/zipcode/dl/kogaki-zip.html>
107 L<http://www.post.japanpost.jp/zipcode/dl/jigyosyo/index-zip.html>
108
109 =head1 OPTIONS
110
111 =head2 --yubin=F<KEN_ALL.CSV>
112
113 Specify ZIP codes file.
114
115 =head2 --jigyosho=F<JIGYOSYO.CSV>
116
117 Specify office ZIP codes file.
118
119 =head2 --ime={canna|wnn}
120
121 Specify IME type.
122
123 =head3 Default
124
125 canna
126
127 =head1 FILES
128
129 =head2 F<KEN_ALL.CSV>
130
131 You can get from
132 L<http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip>.
133
134 =head2 F<JIGYOSYO.CSV>
135
136 You can get from
137 L<http://www.post.japanpost.jp/zipcode/dl/jigyosyo/zip/jigyosyo.zip>.
138
139 =head1 SEE ALSO
140
141 mkbindic(1), atod(1), L<http://www.post.japanpost.jp/zipcode/dl/readme.html>,
142 L<http://www.post.japanpost.jp/zipcode/dl/jigyosyo/readme.html>
143
144 =head1 Copyright(C)
145
146 2001 Yoshito Komatsu <ykomatsu@akaumigame.org>
147
148 2014, 2015 Mitsutoshi NAKANO <bkbin005@rinku.zaq.ne.jp>
149
150 =head1 License
151
152 This program is free software; you can redistribute it and/or modify it under
153 the terms of the GNU General Public License as published
154 by the Free Software Foundation; either version 2 of the License,
155 or (at your option) any later version.
156
157 This program is distributed in the hope that it will be useful,
158 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
159 or FITNESS FOR A PARTICULAR PURPOSE.
160 See the GNU General Public License for more details.
161
162 You should have received a copy of the GNU General Public License along
163 with this program; if not, write to
164 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
165 MA 02110-1301, USA.
166
167 =cut