2 # $Id: piconv,v 1.0 2002/03/28 23:26:28 dankogai Exp dankogai $
8 my %Scheme = map {$_ => 1} qw(from_to decode_encode perlio);
12 my %Opt; getopts("DS:lf:t:s:", \%Opt);
13 $Opt{l} and list_encodings();
14 my $locale = $ENV{LC_CTYPE} || $ENV{LC_ALL} || $ENV{LANG};
15 my $from = $Opt{f} || $locale or help("from_encoding unspecified");
16 my $to = $Opt{t} || $locale or help("to_encoding unspecified");
17 $Opt{s} and Encode::from_to($Opt{s}, $from, $to) and print $Opt{s} and exit;
18 my $scheme = exists $Scheme{$Opt{S}} ? $Opt{S} : 'from_to';
21 my $cfrom = Encode->getEncoding($from)->name;
22 my $cto = Encode->getEncoding($to)->name;
31 if ($scheme eq 'from_to'){
33 Encode::from_to($_, $from, $to); print;
36 }elsif ($scheme eq 'decode_encode'){
38 my $decoded = decode($from, $_);
39 my $encoded = encode($to, $decoded);
43 }elsif ($scheme eq 'perlio'){
44 binmode(STDIN, ":encoding($from)");
45 binmode(STDOUT, ":encoding($to)");
48 die "unknown scheme: $scheme";
52 print STDERR join("\n", Encode->encodings(":all")), "\n";
59 my $name = basename($0);
60 $message and print STDERR "$name error: $message\n";
62 $name [-f from_encoding] [-t to_encoding] [-s string] [files...]
64 -l lists all available encodings.
65 -f from_encoding When omitted, the current locale will be used.
66 -t to_encoding When omitted, the current locale will be used.
67 -s string "string" will be converted instead of STDIN.
76 piconv -- iconv(1), reinvented in perl
80 piconv [-f from_encoding] [-t to_encoding] [-s string] [files...]
85 B<piconv> is perl version of F<iconv>, a character encoding converter
86 widely availabe for various unixen today. This script was primarily
87 a technology demostrator for Perl 5.8.0, you can use piconv in the
88 place of iconv for virtually any cases.
90 piconv converts character encoding of either STDIN or files specified
91 in the argument and prints out to STDOUT.
93 Here are list of options.
97 =item -f from_encoding
99 Specifies the encoding you are converting from. Unlike F<iconv>,
100 this option can be ommited. In such cases the current locale is used.
104 Specifies the encoding you are converting to. Unlike F<iconv>,
105 this option can be ommited. In such cases the current locale is used.
107 Therefore when both -f and -t are omitted, F<piconv> just acts like F<cat>.
111 uses I<string> instead of file for the source of text. Same as F<iconv>.
115 Lists all available encodings to STDERR. This feature is missing from
120 Invokes debugging mode. primarily for Encode hackers.
124 Selects which scheme is to be used for conversion. Available schemes
131 Uses Encode::from_to for conversion. This is the default.
135 Input strings are decode()ed then encode()ed. A straight step-by-step
140 The new perlIO layer is used. NI-S favorite.
144 Like I<-D> option, this is also for Encode hackers.