| 1 | |||||||||||||||
| 2 | package Cz::Cstocs::Getopt; | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use Cz::Cstocs; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 3 | ▶ | use Getopt::Long; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 0 | ▶ | sub usage { | ||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 9 | 0 | print_version(); | |||||||||||||
| 10 | 0 | print STDERR <<EOF; | |||||||||||||
| 11 | Usage: cstocs [options] inputencoding outputencoding [ files ... ] | ||||||||||||||
| 12 | where options can be | ||||||||||||||
| 13 | -i[.ext] In-place substitution; must be the first parameter. | ||||||||||||||
| 14 | --dir=string Alternate directory with encoding and accent files. | ||||||||||||||
| 15 | --fillstring=str String that will replace unconvertable characters, | ||||||||||||||
| 16 | the default is one space. | ||||||||||||||
| 17 | --null Equivalent to --fillstring="" | ||||||||||||||
| 18 | --nofillstring Keep unconvertable unconverted. | ||||||||||||||
| 19 | --onebymore Use all entries from the accent file (the default). | ||||||||||||||
| 20 | --onebyone Use only one-by-one character rules from accent file. | ||||||||||||||
| 21 | --nochange, --noaccent Do not use accent file at all. | ||||||||||||||
| 22 | --version Print out the version information. | ||||||||||||||
| 23 | --debug Print out debugging info while processing. | ||||||||||||||
| 24 | Input and output encodings can also be specified using --inputencoding | ||||||||||||||
| 25 | and --outputencoding options. See man page for detailed description. | ||||||||||||||
| 26 | Available encodings are: | ||||||||||||||
| 27 | 0 | @{[ &Cz::Cstocs::available_enc() ]} | |||||||||||||
| 28 | EOF | ||||||||||||||
| 29 | 0 | exit; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | ▶ | sub print_version { | ||||||||||||
|
Subroutine
print_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 33 | 0 | print STDERR "This is cstocs version $Cz::Cstocs::VERSION.\n"; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 3 | ▶ | sub process_argv { | ||||||||||||
|
Subroutine
process_argv: called CC=12 SCAR=33.7
Pod
undocumented
| |||||||||||||||
| 37 | 3 | my $getopt_config_hashref = shift; | |||||||||||||
| 38 | 3 | my %options; | |||||||||||||
| 39 | 3 | my $options = \%options; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 3 | ▶ | $getopt_config_hashref = {} unless defined $getopt_config_hashref; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 3 | for my $key (keys %$getopt_config_hashref) { | |||||||||||||
| 43 | 0 | my $value = $getopt_config_hashref->{$key}; | |||||||||||||
| 44 | ### print "Key $key -> $value\n"; | ||||||||||||||
| 45 | 0 | ▶ | $getopt_config_hashref->{$key} = \$options{$value} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | unless ref $value; | ||||||||||||||
| 47 | } | ||||||||||||||
| 48 | my %getopt_config = ( | ||||||||||||||
| 49 | 0 | ▶ | 'null' => sub { $options{'fillstring'} = ''; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 50 | 'fillstring=s' => \$options{'fillstring'}, | ||||||||||||||
| 51 | 0 | ▶ | 'nofillstring' => sub { $options{'nofillstring'} = 1 }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 52 | 0 | ▶ | 'usefillstring' => sub { $options{'nofillstring'} = 0 }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | 'onebyone' => sub { $options{'one_by_one'} = 1; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 55 | 0 | ▶ | 'onebymore' => sub { $options{'one_by_one'} = 0; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | 'noaccent', sub { $options{'use_accent'} = 0; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 58 | 0 | ▶ | 'nochange', sub { $options{'use_accent'} = 0; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 'dir=s' => \$options{'cstocsdir'}, | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 'inputencoding=s' => \$options{'inputenc'}, | ||||||||||||||
| 63 | 'outputencoding=s' => \$options{'outputenc'}, | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 'help' => \&usage, | ||||||||||||||
| 66 | 0 | ▶ | 'version' => sub { print_version(); exit 0; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 67 | 0 | ▶ | 'debug' => sub { $Cz::Cstocs::DEBUG = 1; }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 68 | 3 | %$getopt_config_hashref | |||||||||||||
| 69 | ); | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 3 | ▶ | if (grep { /--/ } @ARGV) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 72 | 0 | Getopt::Long::GetOptions(%getopt_config); | |||||||||||||
| 73 | } elsif (@ARGV < 2) { | ||||||||||||||
| 74 | 0 | usage(); | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 3 | my ($inputenc, $outputenc); | |||||||||||||
| 78 | 3 | ▶ | if (defined $options{'inputenc'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | 0 | $inputenc = $options{'inputenc'}; | |||||||||||||
| 80 | 0 | delete $options{'inputenc'}; | |||||||||||||
| 81 | } else { | ||||||||||||||
| 82 | 3 | $inputenc = shift @ARGV; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 3 | ▶ | if (defined $options{'outputenc'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | 0 | $outputenc = $options{'outputenc'}; | |||||||||||||
| 87 | 0 | delete $options{'outputenc'}; | |||||||||||||
| 88 | } else { | ||||||||||||||
| 89 | 3 | $outputenc = shift @ARGV; | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | |||||||||||||||
| 92 | 3 | my $tag; | |||||||||||||
| 93 | 3 | for $tag (keys %options) { | |||||||||||||
| 94 | 12 | ▶ | delete $options{$tag} unless defined $options{$tag}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 95 | } | ||||||||||||||
| 96 | 3 | ▶ | print STDERR "Calling new Cz::Cstocs $inputenc, $outputenc\n" if Cz::Cstocs::DEBUG; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | 3 | my $convert = new Cz::Cstocs $inputenc, $outputenc, %options; | |||||||||||||
| 98 | |||||||||||||||
| 99 | 3 | $options{'inputenc'} = $inputenc; | |||||||||||||
| 100 | 3 | $options{'outputenc'} = $outputenc; | |||||||||||||
| 101 | 3 | ▶ | if (wantarray) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | 0 | return ($convert, $options); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | 3 | return $convert; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 3 | 1; | |||||||||||||
| 108 | |||||||||||||||