Permalink
Browse files

* Fix a bug that b2g.pl and g2b.pl with -u flag won't set encoding co…

…rrect if

  providing file name in command line.
  • Loading branch information...
1 parent 26a2567 commit 2ce4999fed49674186099d69d12b4437966a3f14 @kcwu kcwu committed Dec 9, 2006
Showing with 49 additions and 16 deletions.
  1. +3 −0 Changes
  2. +23 −8 bin/b2g.pl
  3. +23 −8 bin/g2b.pl
View
3 Changes
@@ -2,6 +2,9 @@
* Fix map for U+FE35 in b2g_map.utf8.
+* Fix a bug that b2g.pl and g2b.pl with -u flag won't set encoding correct if
+ providing file name in command line.
+
____________________________________________________________________________
[ 10742] By: autrijus on 2004/06/04 07:15:15
Log: * This be 0.31.
View
31 bin/b2g.pl
@@ -2,7 +2,7 @@
# $File: //member/autrijus/Encode-HanConvert/bin/b2g.pl $ $Author: autrijus $
# $Revision: #14 $ $Change: 10740 $ $DateTime: 2004/06/03 22:02:31 $
-$VERSION = '0.11';
+$VERSION = '0.12';
=head1 NAME
@@ -56,16 +56,31 @@ BEGIN
use Encode::HanConvert;
-if (UTF8 and $] >= 5.008) { binmode(STDIN, ':utf8'); binmode(STDOUT, ':utf8') }
-
my $KEYS = join('|', map quotemeta, sort { length($b) <=> length($a) } keys %{+MAP}) if DICT;
my $MAP = +MAP if DICT;
-while (<>) {
- if (UTF8) { Encode::HanConvert::trad_to_simp($_) }
- else { Encode::HanConvert::big5_to_gb($_) }
- if (DICT) { s/($KEYS)/$MAP->{$1}/g }
- print;
+if (@ARGV) {
+ for (@ARGV) {
+ unless(open F, $_) {
+ warn "Can't open $_: $!";
+ next;
+ }
+ convert(\*F);
+ close F;
+ }
+} else {
+ convert(\*STDIN);
+}
+
+sub convert {
+ my ($fh) = @_;
+ if (UTF8 and $] >= 5.008) { binmode($fh, ':utf8'); binmode($fh, ':utf8') }
+ while (<$fh>) {
+ 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 && {
View
31 bin/g2b.pl
@@ -2,7 +2,7 @@
# $File: //member/autrijus/Encode-HanConvert/bin/g2b.pl $ $Author: autrijus $
# $Revision: #14 $ $Change: 10742 $ $DateTime: 2004/06/04 07:15:15 $
-$VERSION = '0.11';
+$VERSION = '0.12';
=head1 NAME
@@ -56,16 +56,31 @@ BEGIN
use Encode::HanConvert;
-if (UTF8 and $] >= 5.008) { binmode(STDIN, ':utf8'); binmode(STDOUT, ':utf8') }
-
my $KEYS = join('|', map quotemeta, sort { length($b) <=> length($a) } keys %{+MAP}) if DICT;
my $MAP = +MAP if DICT;
-while (<>) {
- if (UTF8) { Encode::HanConvert::simp_to_trad($_) }
- else { Encode::HanConvert::gb_to_big5($_) }
- if (DICT) { s/($KEYS)/$MAP->{$1}/g }
- print;
+if (@ARGV) {
+ for (@ARGV) {
+ unless(open F, $_) {
+ warn "Can't open $_: $!";
+ next;
+ }
+ convert(\*F);
+ close F;
+ }
+} else {
+ convert(\*STDIN);
+}
+
+sub convert {
+ my ($fh) = @_;
+ if (UTF8 and $] >= 5.008) { binmode($fh, ':utf8'); binmode($fh, ':utf8') }
+ while (<$fh>) {
+ if (UTF8) { Encode::HanConvert::simp_to_trad($_) }
+ else { Encode::HanConvert::gb_to_big5($_) }
+ if (DICT) { s/($KEYS)/$MAP->{$1}/g }
+ print;
+ }
}
use constant MAP => DICT && {

0 comments on commit 2ce4999

Please sign in to comment.