#!/import/archperf/ws/devtools/4/amd64/bin/perl
eval 'exec /import/archperf/ws/devtools/4/amd64/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
# $Id: piconv,v 2.1 2004/10/06 05:07:20 dankogai Exp $
my %Scheme = map {$_ => 1} qw(from_to decode_encode perlio);
use Getopt::Long qw(:config no_ignore_case);
$Opt{list} and list_encodings();
my $locale = $ENV{LC_CTYPE} || $ENV{LC_ALL} || $ENV{LANG};
defined $Opt{resolve} and resolve_encoding($Opt{resolve});
$Opt{from} || $Opt{to} || help();
my $from = $Opt{from} || $locale or help("from_encoding unspecified");
my $to = $Opt{to} || $locale or help("to_encoding unspecified");
$Opt{string} and Encode::from_to($Opt{string}, $from, $to) and print $Opt{string} and exit;
my $scheme = exists $Scheme{$Opt{Scheme}} ? $Opt{Scheme} : 'from_to';
$Opt{perlqq} and $Opt{check} = Encode::FB_PERLQQ;
my $cfrom = Encode->getEncoding($from)->name;
my $cto = Encode->getEncoding($to)->name;
# we do not use <> (or ARGV) for the sake of binmode()
@ARGV or push @ARGV, \*STDIN;
unless ($scheme eq 'perlio'){
my $ifh = ref $argv ? $argv : undef;
$ifh or open $ifh, "<", $argv or next;
if ($scheme eq 'from_to'){ # default
Encode::from_to($_, $from, $to, $Opt{check});
}elsif ($scheme eq 'decode_encode'){ # step-by-step
my $decoded = decode($from, $_, $Opt{check});
my $encoded = encode($to, $decoded);
die "$name: unknown scheme: $scheme";
binmode STDOUT => "raw:encoding($to)";
my $ifh = ref $argv ? $argv : undef;
$ifh or open $ifh, "<", $argv or next;
binmode $ifh => "raw:encoding($from)";
print join("\n", Encode->encodings(":all")), "\n";
if (my $alias = Encode::resolve_alias($_[0])) {
warn "$name: $_[0] is not known to Encode\n";
$message and print STDERR "$name error: $message\n";
$name [-f from_encoding] [-t to_encoding] [-s string] [files...]
lists all available encodings
-r,--resolve encoding_alias
resolve encoding to its (Encode) canonical name
when omitted, the current locale will be used
when omitted, the current locale will be used
"string" will be the input instead of STDIN or files
The following are mainly of interest to Encode hackers:
-D,--debug show debug information
-C N | -c | -p check the validity of the input
-S,--scheme scheme use the scheme for conversion
piconv -- iconv(1), reinvented in perl
piconv [-f from_encoding] [-t to_encoding] [-s string] [files...]
B<piconv> is perl version of B<iconv>, a character encoding converter
widely available for various Unixen today. This script was primarily
a technology demonstrator for Perl 5.8.0, but you can use piconv in the
place of iconv for virtually any case.
piconv converts the character encoding of either STDIN or files
specified in the argument and prints out to STDOUT.
Here is the list of options. Each option can be in short format (-f)
=item -f,--from from_encoding
Specifies the encoding you are converting from. Unlike B<iconv>,
this option can be omitted. In such cases, the current locale is used.
=item -t,--to to_encoding
Specifies the encoding you are converting to. Unlike B<iconv>,
this option can be omitted. In such cases, the current locale is used.
Therefore, when both -f and -t are omitted, B<piconv> just acts
=item -s,--string I<string>
uses I<string> instead of file for the source of text.
Lists all available encodings, one per line, in case-insensitive
order. Note that only the canonical names are listed; many aliases
exist. For example, the names are case-insensitive, and many standard
and common aliases work, such as "latin1" for "ISO-8859-1", or "ibm850"
instead of "cp850", or "winlatin1" for "cp1252". See L<Encode::Supported>
Check the validity of the stream if I<N> = 1. When I<N> = -1, something
interesting happens when it encounters an invalid character.
Invokes debugging mode. Primarily for Encode hackers.
Selects which scheme is to be used for conversion. Available schemes
Uses Encode::from_to for conversion. This is the default.
Input strings are decode()d then encode()d. A straight two-step
The new perlIO layer is used. NI-S' favorite.
Like the I<-D> option, this is also for Encode hackers.