| 1 | #!/usr/local/bin/perl -w | ||||||||||
| 2 | 3 | eval 'exec perl -S $0 "$@"' | |||||||||
| 3 | if 0; | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use vars qw( $running_under_some_shell ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | cstocs -- charset encoding convertor for the Czech and Slovak languages. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 FORMAT | ||||||||||
| 13 | |||||||||||
| 14 | cstocs [options] src_encoding dst_encoding [files ...] | ||||||||||
| 15 | |||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||
| 17 | |||||||||||
| 18 | cstocs il2 ascii < file | less | ||||||||||
| 19 | cstocs -i utf8 il2 file1 file2 file3 | ||||||||||
| 20 | cstocs --help | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | Cstocs is a simple conversion utility to change charset encoding of | ||||||||||
| 25 | a text. It reads either specified files or (if none specified) the | ||||||||||
| 26 | standard input, assumes that the input is encoded in C<src_encoding> | ||||||||||
| 27 | and ties to reencode it into C<dst_encoding>. The result is written to | ||||||||||
| 28 | the standard output. | ||||||||||
| 29 | |||||||||||
| 30 | Run C<cstocs> without parameters to get short help and list of | ||||||||||
| 31 | available encodings. | ||||||||||
| 32 | |||||||||||
| 33 | Characters that are not defined in C<src_encoding> are passed to the | ||||||||||
| 34 | output unchanged. | ||||||||||
| 35 | |||||||||||
| 36 | If source text contains character, that is defined in C<src_encoding> | ||||||||||
| 37 | but not in C<dst_encoding>, it can be handled several ways. For | ||||||||||
| 38 | example, character "e with caron" (symbol ecaron), and "d with caron" | ||||||||||
| 39 | (symbol dcaron) are included in the iso-8859-2 encoding, but not in | ||||||||||
| 40 | the iso-8859-1. If you will do reencoding of 8859-2 text to 8859-1, | ||||||||||
| 41 | you may want to do one of the following actions: | ||||||||||
| 42 | |||||||||||
| 43 | =over 3 | ||||||||||
| 44 | |||||||||||
| 45 | =item 1. | ||||||||||
| 46 | |||||||||||
| 47 | Keep it the same, option C<--nofillstring>. | ||||||||||
| 48 | |||||||||||
| 49 | =item 2. | ||||||||||
| 50 | |||||||||||
| 51 | Do not produce any output instead of "ecaron" symbol, option C<--null>. | ||||||||||
| 52 | |||||||||||
| 53 | =item 3. | ||||||||||
| 54 | |||||||||||
| 55 | Substitute some string (possibly a space) instead of both ecaron and | ||||||||||
| 56 | dcaron, options C<--fillstring>. | ||||||||||
| 57 | |||||||||||
| 58 | =item 4. | ||||||||||
| 59 | |||||||||||
| 60 | Substitute a letter "d" instead of dcaron, and "e" instead of ecaron. | ||||||||||
| 61 | It is even possible to substitute string instead of symbol, so you can | ||||||||||
| 62 | replace the "AE" Latin character with string "AE" (letter "A", and | ||||||||||
| 63 | letter "E"). Or you can replace a "plusminus sign" with a string | ||||||||||
| 64 | "+/-". These substitutions are described in the F<accent> file. | ||||||||||
| 65 | |||||||||||
| 66 | =back | ||||||||||
| 67 | |||||||||||
| 68 | =head1 OPTIONS | ||||||||||
| 69 | |||||||||||
| 70 | =over 4 | ||||||||||
| 71 | |||||||||||
| 72 | =item -i, -i.ext, --inplace.ext | ||||||||||
| 73 | |||||||||||
| 74 | Files specified will be converted in-place, using Perl C<-i> facility. | ||||||||||
| 75 | Optionaly, an extension for backup copies may be specified after dot. | ||||||||||
| 76 | This parameter B<has> to be the first one, if specified. | ||||||||||
| 77 | |||||||||||
| 78 | =item --dir directory | ||||||||||
| 79 | |||||||||||
| 80 | Encoding files are taken from F<directory> instead of the default, | ||||||||||
| 81 | which is F<Cz/Cstocs/enc> in the Perl lib tree. The location of encoding | ||||||||||
| 82 | files can also be changed using the I<CSTOCSDIR> environment variable, | ||||||||||
| 83 | but the --dir option has the highest priority. | ||||||||||
| 84 | |||||||||||
| 85 | =item --fillstring string | ||||||||||
| 86 | |||||||||||
| 87 | If source text contains character, that is defined in the | ||||||||||
| 88 | C<src_encoding> but not in the C<dst_encoding> nor in the F<accent> | ||||||||||
| 89 | file (or F<accent> file is not used), it is replaced by C<string>. | ||||||||||
| 90 | The default is single space. | ||||||||||
| 91 | |||||||||||
| 92 | =item --nofillstring | ||||||||||
| 93 | |||||||||||
| 94 | Disable changes of characters that would otherwise have fillstring | ||||||||||
| 95 | applied. This is different from C<--null> because that cancels that | ||||||||||
| 96 | character out. | ||||||||||
| 97 | |||||||||||
| 98 | =item --null | ||||||||||
| 99 | |||||||||||
| 100 | Completely equivalent to --fillstring "". | ||||||||||
| 101 | |||||||||||
| 102 | =item --nochange or --noaccent | ||||||||||
| 103 | |||||||||||
| 104 | Do not use the F<accent> file at all. | ||||||||||
| 105 | |||||||||||
| 106 | =item --onebyone | ||||||||||
| 107 | |||||||||||
| 108 | Use only those rules from the F<accent> file, which rewrite one | ||||||||||
| 109 | character to one character. If this option is specified, character | ||||||||||
| 110 | "ecaron" will be rewritten to "e", but "AE" character will not be | ||||||||||
| 111 | rewritten to "AE" string. | ||||||||||
| 112 | |||||||||||
| 113 | =item --onebymore | ||||||||||
| 114 | |||||||||||
| 115 | Use all rules from accent file. This is the default option. | ||||||||||
| 116 | |||||||||||
| 117 | =back | ||||||||||
| 118 | |||||||||||
| 119 | =head1 SEE ALSO | ||||||||||
| 120 | |||||||||||
| 121 | Cz::Cstocs(3). | ||||||||||
| 122 | |||||||||||
| 123 | =head1 AUTHOR | ||||||||||
| 124 | |||||||||||
| 125 | Jan "Yenya" Kasprzak has done the original Un*x implementation. | ||||||||||
| 126 | |||||||||||
| 127 | Jan Pazdziora created the Perl module version. | ||||||||||
| 128 | |||||||||||
| 129 | =cut | ||||||||||
| 130 | |||||||||||
| 131 | 4 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.2
| |||||||||||
| 132 | 4 | ▶ | if ($ARGV[0] =~ /^--?i(npl)?.*?(\..+?$)?$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | 1 | my $ext = ''; | |||||||||
| 134 | 1 | ▶ | $ext = $2 if defined $2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | 1 | shift @ARGV; | |||||||||
| 136 | ### print STDERR "Running: $^X -i$ext -- $0 @ARGV\n"; | ||||||||||
| 137 | 1 | exec $^X, "-i$ext", '--', $0, @ARGV; | |||||||||
| 138 | 0 | die "Exec of perl $^X for inplace substitution failed.\n"; | |||||||||
| 139 | } | ||||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 3 | ▶ | use Cz::Cstocs; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 143 | 3 | ▶ | use Cz::Cstocs::Getopt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 144 | |||||||||||
| 145 | 3 | my $convert = Cz::Cstocs::Getopt::process_argv; | |||||||||
| 146 | |||||||||||
| 147 | 3 | ▶ | if (not defined $convert) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 0 | print STDERR $@; | |||||||||
| 149 | 0 | exit(1); | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 3 | ▶ | while (<>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 153 | 3 | print &$convert($_); | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||