File: //usr/local/bin/vendor_perl/b2g.pl
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
$VERSION = '0.14';
=head1 NAME
b2g.pl - Traditional to Simplified Chinese converter
=head1 SYNOPSIS
B<b2g.pl> [ B<-p> ] [ B<-u> ] [ I<inputfile> ...] > I<outputfile>
=head1 USAGE
% b2g.pl -p < big5.txt > gbk.txt
% b2g.pl -pu < trad.txt > simp.txt
=head1 DESCRIPTION
The B<b2g.pl> utility reads files sequentially, converts them from
Traditional to Simplified Chinese, then writes them to the standard
output. The I<inputfile> arguments are processed in command-line order.
If I<inputfile> is a single dash (C<->) or absent, this program reads
from the standard input.
The C<-p> switch enables rudimentary phrase-oriented substition via a
small built-in lexicon.
The C<-u> switch specifies that both the input and output streams should
be UTF-8 encoded. If not specified, the input stream is assumed to be
in Big5, and the output will be encoded in GBK.
=head1 CAVEATS
In pure-perl implementations (pre-5.8 perl or without a C compiler),
C<-p> and C<-u> cannot be used together.
=cut
use strict;
use warnings;
use Getopt::Std;
sub MAP ();
my %opts;
BEGIN {
getopts('hup', \%opts);
if ($opts{h}) { system("perldoc", $0); exit }
$SIG{__WARN__} = sub {};
}
use constant UTF8 => $opts{u};
use constant DICT => ($opts{p} and (!UTF8 or $] >= 5.008));
use Encode::HanConvert;
my $KEYS = join('|', map quotemeta, sort { length($b) <=> length($a) } keys %{+MAP}) if DICT;
my $MAP = +MAP if DICT;
if (@ARGV) {
for (@ARGV) {
unless(open F, $_) {
warn "Can't open $_: $!";
next;
}
convert(\*F);
close F;
}
} else {
convert(\*STDIN);
}
sub convert {
my ($fh) = @_;
if ($] >= 5.008) {
if (UTF8) {
binmode($fh, ':encoding(trad-simp)'); binmode(STDOUT, ':utf8')
} else {
binmode($fh, ':encoding(big5-simp)'); binmode(STDOUT, ':encoding(gbk)')
}
}
while (<$fh>) {
unless ($] >= 5.008) {
if (UTF8) { Encode::HanConvert::trad_to_simp($_) }
else { Encode::HanConvert::big5_to_gb($_) }
}
if (DICT) { s/($KEYS)/$MAP->{$1}/g }
print;
}
}
use constant MAP => DICT && {
map { UTF8 ? Encode::decode(gbk => $_) : $_ } (
'��̫' => '��̫',
'��̫�·' => '��̫���',
'�žų˷���' => '�žű�',
'�жϵ�' => '�ϵ�',
'����' => '�ӿ�',
'Ԫ��' => '��',
'���°�' => '���İ�',
'��ȿ���' => '�������',
'���' => '���',
'̫����' => '����Ա',
'̫����' => '������з�',
'̫����' => '����ɻ�',
'̫�մ�' => '����ɴ�',
'������' => '�����Ƿ�',
'�������' => '���ڲ�',
'֧Ԯ' => '֧��',
'�ļ���' => '��ҳ��',
'�ն������' => '�ն������',
'���б�' => '����',
'��ƴ' => '��',
'Ƭ��' => '����',
'���ܱ�' => '�˵�',
'����' => '����',
'ʷ���' => '˹���',
'��̫��' => '���ռ�',
'��ϣ' => '��ʲ',
'ƽ���ҵ' => '���в��',
'ƽ�в�' => '���ж˿�',
'ƽ����' => '������',
'����' => '��',
'ĸ��' => 'Ԫ��',
'���' => '���',
'��ʿ��' => '��˹��',
'�ٽ�' => '�н�',
'����' => '���',
'ȫ��' => 'ȫ��',
'����' => '����',
'����' => '��',
'��ӡ' => '��ӡ',
'ӡ��' => '��ӡ��',
'�����' => '�������',
'���' => '����',
'��Ȧ' => 'ѭ��',
'��Ӧ' => '��Ӧ',
'������' => '�������',
'�ִ�' => '�ַ���',
'����' => 'ǰ',
'�浵' => '����',
'���' => '���',
'�����' => '�տ�',
'���' => '����',
'�������' => '��������',
'�Ԫ' => '��Ԫ',
'λַ' => '��ַ',
'���' => '���',
'��֤' => '��֤',
'�ŷ��' => '�����',
'�ҵϵͳ' => '���ϵͳ',
'�����' => '�����',
'�ͽ�����' => '�ͼ�����',
'��ʱ' => 'ʵʱ',
'�����' => '������',
'����' => '����',
'������ȥ' => '������ȥ',
'����' => '����',
'�궼��˹' => '�鶼��˹',
'��в�' => '���ж˿�',
'ɳ����' => 'ɫ����',
'ɳ�ڵذ�����' => 'ɳ�ذ�����',
'��' => '����',
'���' => '�����',
'��д' => 'д����',
'������' => '������',
'���' => '���',
'��' => '��',
'����' => '�����',
'�ܱ�' => '��Χ',
'�����' => '������',
'ע��' => '��ע',
'ע��' => '�ע',
'��' => '����',
'֪ʶ����' => '֪ʶ����',
'�ʯ' => '��ʯ',
'���Ƭ' => '��оƬ',
'��羧��' => '�辧���',
'�հ�' => '�ո�',
'��' => '��',
'����' => '�ž�',
'��ķ˹׳' => '��ķ˹���',
'��˹ƥ��' => '��˾ƥ��',
'�Ϲ�' => '����',
'ָ��' => 'ָ��',
'����' => '����',
'ӳ��' => 'ӳ��',
'���' => '����',
'����' => '����',
'Ү����' => 'ʥ����',
'������' => '�������',
'��ʱ�' => '��ʱ�',
'�Ƴ̳�' => '���',
'����' => '�����',
'��˹��' => '��˹��',
'�ز�' => '�ط�',
'ʳ��' => '�;�',
'���' => '��ù',
'����' => '����',
'����' => '��¥',
'��װ����' => '����',
'���' => '���',
'�����' => '������',
'��ˮӡ' => 'ˮӡ',
'������' => '�ڳ���',
'������' => '������',
'����' => '�ؼ�',
'�����' => '����',
'��̫����' => '��������',
'���C' => '����',
'������' => '�ڴ�',
'��O��' => '�����',
'���' => '���',
'����' => '����',
'����ʽ' => '�ӳ���',
'�����' => '��չ�',
'������' => '������',
'Ψ��' => 'ֻ��',
'�ѵ�' => '��ջ',
'ר��' => '��Ŀ',
'��ʽ' => '����',
'���˵Ҹ�' => '����ҿ�',
'�ݾ�' => '��ݷ�ʽ',
'ɨ���' => 'ɨ����',
'��' => '����',
'������' => '����',
'���϶���' => '���ɶ���',
'�Ͽ��' => '�ϼ��',
'���' => '���',
'��Ƭ' => '����',
'ͨѶ¼' => 'ͨѶ��',
'ͨ��' => '�ŵ�',
'����' => '����',
'��ʳ' => '���',
'����' => '����',
'�����' => '�����',
'������' => '���ι�',
'������' => '������',
'��Բ���' => '��Բ���',
'��Ƭ' => 'оƬ',
'�ǻ�' => '����',
'�α�' => '���',
'����' => '����',
'�dz�' => 'ע�',
'Ӳ��' => 'Ӳ��',
'��ʽ' => '����',
'�������' => '���̿���',
'��¼��' => '¼��',
'��' => '��',
'���' => '���',
'�ζ�' => '�̶�',
'�Ӵ�' => '����',
'����' => '����',
'������' => '��������',
'�ʵ����' => '�������',
'������' => '�ڳ���',
'���' => '���',
'����' => '����',
'�ܽ�' => '���',
'�¿��������' => '����������',
'�»�' => '��ί��',
'���' => '�������',
'�º�����' => '�º���ʲ��',
'������' => '������',
'����' => '���',
'���' => '���',
'ʥ�����' => 'ʥ���Ǹ�',
'�����' => '�ֱ���',
'����' => '����',
'�����' => '���ӱ��',
'��Ѷ' => '��Ϣ',
'����' => '����',
'����Ԫ' => '����',
'����ʽ' => '���ʽ',
'�Ҹ�' => '��',
'բ��' => '���',
'����ӡ��' => '�����ӡ��',
'��' => '��',
'�羧��' => '�����',
'�紫��Ѷ' => 'ͼ�ĵ���',
'����' => '����',
'���Գ�ʽ' => '��������',
'��' => '�緹��',
'ͼʾ' => 'ͼ��',
'���' => '�ҵ�',
'ߡ��' => '�ۺ�',
'���㷨' => '�㷨',
'��Ƭ' => '����',
'�Ź�' => '�ŵ�',
'���' => '���',
'�ŵ�' => '����',
'�ŵ���' => '��������',
'�ŵ���' => '�����ļ�',
'̼��ϻ' => 'ī�ۺ�',
'�����' => '�������',
'����' => '��Կ',
'�·' => '���',
'�L��' => '�ѹ�',
'��ʿ' => '����',
'��³ѩ��' => '��³���',
'Զ��' => 'Զ��',
'���' => '����',
'����' => '���',
'��ݻ�' => '���ƽ��',
'�ݴ��' => '�����',
'��ǩ' => '���',
'�' => '�',
'�' => '����',
'����' => '��������',
'��ʯ' => '��ʯ',
'����' => '�',
'����Ϳ' => '����Ϳ',
'��Ϳ' => '��Ϳ',
'�����ҵ' => '�������',
'��՞' => '����',
'����' => '���',
'��' => '��ѬѬ',
'���' => '���',
'�ڱ�' => 'ǽ��',
'����' => '����',
'�����·' => '���ɵ�·',
'өĻ' => '�Ļ',
'��ѯ' => '��ѯ',
'ŵ���' => 'ŵ���',
'ŵ���' => 'ŵ���',
'¼Ӱ' => '¼��',
'�����' => '������',
'倸�' => '����',
'����' => '����',
'˪��' => '����',
'����' => '����',
'��' => '��ʾ�ĸ�',
'��' => '��',
'��' => 'Ѭ��',
'ת���' => 'ת�۵�',
'��Ѷ' => '���',
'����' => '����',
'���ֿ�' => '������',
'�µ�' => '�õ�',
'ʶ����' => '��ʶ��',
'�ο�' => '�ӿ�',
'�ǻ�' => '�ʻ�',
'�ؼ���' => '�ؼ���',
'���' => '�',
'��' => '���',
'Я����' => '��Яʽ',
'��λ' => '�ֶ�',
'����' => '����',
'Ȩ��' => '����',
'������' => '��Ƭ�Ķ���',
'��̫��' => '�̫��',
'��ţ' => '��ţ',
'�kͬ' => '��ͬ',
'�F��' => '����',
'�ظ�' => '�ظ�',
'λԪ��' => '�ֽ�',
'����' => '����',
'����' => '���',
'��' => '��',
'��' => '��',
'��' => '��',
'��' => '��',
'ד�' => 'ٝ�',
'ד�' => 'ٝ�',
'ד�~' => 'ٝ�~',
'��ǰ' => '̨ǰ',
'����' => '̨��',
'����' => '̨��',
'�_��' => '̨��',
'�_��' => '̨��',
'�_��' => '̨��',
'�_�|' => '̨�|',
'�U�L' => '̨�L',
'�I��' => '���',
'�I��' => '��',
'�I�l' => '��l',
'���I' => '����',
'��I' => '����',
'���' => '���',
'ĸ��' => 'ĸ��',
) };
__END__
=head1 SEE ALSO
L<g2b.pl>, L<Encode::HanConvert>
=head1 AUTHORS
Currently maintained by Kuang-che Wu E<lt>kcwu@csie.orgE<gt>. Orignal author:
Audrey Tang E<lt>cpan@audreyt.orgE<gt>
=head1 COPYRIGHT
Copyright 2002, 2003, 2004 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>.
Copyright 2006 by Kuang-che Wu E<lt>kcwu@csie.orgE<gt>.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
See L<http://www.perl.com/perl/misc/Artistic.html>
=cut