diff options
Diffstat (limited to 'ext/Encode/bin/piconv')
-rw-r--r-- | ext/Encode/bin/piconv | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/ext/Encode/bin/piconv b/ext/Encode/bin/piconv index fd546f0428..cb0c236698 100644 --- a/ext/Encode/bin/piconv +++ b/ext/Encode/bin/piconv @@ -1,5 +1,5 @@ #!./perl -# $Id: piconv,v 2.0 2004/05/16 20:55:16 dankogai Exp $ +# $Id: piconv,v 2.1 2004/10/06 05:07:20 dankogai Exp $ # use 5.8.0; use strict; @@ -52,25 +52,39 @@ To: $to => $cto EOT } -# default -if ($scheme eq 'from_to'){ - while(<>){ - Encode::from_to($_, $from, $to, $Opt{check}); print; - }; -# step-by-step -}elsif ($scheme eq 'decode_encode'){ - while(<>){ - my $decoded = decode($from, $_, $Opt{check}); - my $encoded = encode($to, $decoded); - print $encoded; - }; -# NI-S favorite -}elsif ($scheme eq 'perlio'){ - binmode(STDIN, ":encoding($from)"); - binmode(STDOUT, ":encoding($to)"); - while(<>){ print; } -} else { # won't reach - die "$name: unknown scheme: $scheme"; +# we do not use <> (or ARGV) for the sake of binmode() +@ARGV or push @ARGV, \*STDIN; + +unless ($scheme eq 'perlio'){ + binmode STDOUT; + for my $argv (@ARGV){ + my $ifh = ref $argv ? $argv : undef; + $ifh or open $ifh, "<", $argv or next; + binmode $ifh; + if ($scheme eq 'from_to'){ # default + while(<$ifh>){ + Encode::from_to($_, $from, $to, $Opt{check}); + print; + } + }elsif ($scheme eq 'decode_encode'){ # step-by-step + while(<$ifh>){ + my $decoded = decode($from, $_, $Opt{check}); + my $encoded = encode($to, $decoded); + print $encoded; + } + } else { # won't reach + die "$name: unknown scheme: $scheme"; + } + } +}else{ + # NI-S favorite + binmode STDOUT => "raw:encoding($to)"; + for my $argv (@ARGV){ + my $ifh = ref $argv ? $argv : undef; + $ifh or open $ifh, "<", $argv or next; + binmode $ifh => "raw:encoding($from)"; + print while(<$ifh>); + } } sub list_encodings{ |