Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / bin / piconv
CommitLineData
86530b38
AT
1#!/import/bw/tools/local/perl-5.8.0/bin/perl
2 eval 'exec /import/bw/tools/local/perl-5.8.0/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4#!./perl
5# $Id: piconv,v 1.25 2002/06/01 18:07:49 dankogai Exp dankogai $
6#
7use 5.8.0;
8use strict;
9use Encode ;
10use Encode::Alias;
11my %Scheme = map {$_ => 1} qw(from_to decode_encode perlio);
12
13use Getopt::Std;
14
15my %Opt; getopts("pcC:hDS:lf:t:s:", \%Opt);
16$Opt{h} and help();
17$Opt{l} and list_encodings();
18my $locale = $ENV{LC_CTYPE} || $ENV{LC_ALL} || $ENV{LANG};
19$Opt{f} || $Opt{t} || help();
20my $from = $Opt{f} || $locale or help("from_encoding unspecified");
21my $to = $Opt{t} || $locale or help("to_encoding unspecified");
22$Opt{s} and Encode::from_to($Opt{s}, $from, $to) and print $Opt{s} and exit;
23my $scheme = exists $Scheme{$Opt{S}} ? $Opt{S} : 'from_to';
24$Opt{C} ||= $Opt{c};
25$Opt{p} and $Opt{C} = Encode::FB_PERLQQ;
26
27if ($Opt{D}){
28 my $cfrom = Encode->getEncoding($from)->name;
29 my $cto = Encode->getEncoding($to)->name;
30 print <<"EOT";
31Scheme: $scheme
32From: $from => $cfrom
33To: $to => $cto
34EOT
35}
36
37# default
38if ($scheme eq 'from_to'){
39 while(<>){
40 Encode::from_to($_, $from, $to, $Opt{C}); print;
41 };
42# step-by-step
43}elsif ($scheme eq 'decode_encode'){
44 while(<>){
45 my $decoded = decode($from, $_, $Opt{C});
46 my $encoded = encode($to, $decoded);
47 print $encoded;
48 };
49# NI-S favorite
50}elsif ($scheme eq 'perlio'){
51 binmode(STDIN, ":encoding($from)");
52 binmode(STDOUT, ":encoding($to)");
53 while(<>){ print; }
54}else{ # won't reach
55 die "unknown scheme: $scheme";
56}
57
58sub list_encodings{
59 print join("\n", Encode->encodings(":all")), "\n";
60 exit;
61}
62
63sub help{
64 my $message = shift;
65 use File::Basename;
66 my $name = basename($0);
67 $message and print STDERR "$name error: $message\n";
68 print STDERR <<"EOT";
69$name [-f from_encoding] [-t to_encoding] [-s string] [files...]
70$name -l
71 -l lists all available encodings (the canonical names, many aliases exist)
72 -f from_encoding When omitted, the current locale will be used.
73 -t to_encoding When omitted, the current locale will be used.
74 -s string "string" will be converted instead of STDIN.
75EOT
76 exit;
77}
78
79__END__
80
81=head1 NAME
82
83piconv -- iconv(1), reinvented in perl
84
85=head1 SYNOPSIS
86
87 piconv [-f from_encoding] [-t to_encoding] [-s string] [files...]
88 piconv -l
89
90=head1 DESCRIPTION
91
92B<piconv> is perl version of B<iconv>, a character encoding converter
93widely available for various Unixen today. This script was primarily
94a technology demonstrator for Perl 5.8.0, but you can use piconv in the
95place of iconv for virtually any case.
96
97piconv converts the character encoding of either STDIN or files
98specified in the argument and prints out to STDOUT.
99
100Here is the list of options.
101
102=over 4
103
104=item -f from_encoding
105
106Specifies the encoding you are converting from. Unlike B<iconv>,
107this option can be omitted. In such cases, the current locale is used.
108
109=item -t to_encoding
110
111Specifies the encoding you are converting to. Unlike B<iconv>,
112this option can be omitted. In such cases, the current locale is used.
113
114Therefore, when both -f and -t are omitted, B<piconv> just acts
115like B<cat>.
116
117=item -s I<string>
118
119uses I<string> instead of file for the source of text. Same as B<iconv>.
120
121=item -l
122
123Lists all available encodings, one per line, in case-insensitive
124order. Note that only the canonical names are listed; many aliases
125exist. For example, the names are case-insensitive, and many standard
126and common aliases work, such as "latin1" for "ISO-8859-1", or "ibm850"
127instead of "cp850", or "winlatin1" for "cp1252". See L<Encode::Supported>
128for a full discussion.
129
130=item -C I<N>
131
132Check the validity of the stream if I<N> = 1. When I<N> = -1, something
133interesting happens when it encounters an invalid character.
134
135=item -c
136
137Same as C<-C 1>.
138
139=item -p
140
141Same as C<-C -1>.
142
143=item -h
144
145Show usage.
146
147=item -D
148
149Invokes debugging mode. Primarily for Encode hackers.
150
151=item -S scheme
152
153Selects which scheme is to be used for conversion. Available schemes
154are as follows:
155
156=over 4
157
158=item from_to
159
160Uses Encode::from_to for conversion. This is the default.
161
162=item decode_encode
163
164Input strings are decode()d then encode()d. A straight two-step
165implementation.
166
167=item perlio
168
169The new perlIO layer is used. NI-S' favorite.
170
171=back
172
173Like the I<-D> option, this is also for Encode hackers.
174
175=back
176
177=head1 SEE ALSO
178
179L<iconv(1)>
180L<locale(3)>
181L<Encode>
182L<Encode::Supported>
183L<Encode::Alias>
184L<PerlIO>
185
186=cut