| 1 | #!perl | ||||||||||
| 2 | # | ||||||||||
| 3 | # inicat - cat .ini files to standard output | ||||||||||
| 4 | # | ||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Getopt::Std; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use IO::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use App::IniDiff::IniFile; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | my $prog = $0; | |||||||||
| 13 | 3 | $prog =~ s:.*\/::; | |||||||||
| 14 | |||||||||||
| 15 | 3 | my $Usage = "Usage: $prog [-V] [-o outfile] [file ...] | |||||||||
| 16 | -V Print version number and exit. | ||||||||||
| 17 | -o outfile - print output to outfile | ||||||||||
| 18 | file Read from file (defaults to stdin) | ||||||||||
| 19 | Reads the contents of the specified .ini files (or standard input | ||||||||||
| 20 | if no files are given), and writes them to standard output. | ||||||||||
| 21 | "; | ||||||||||
| 22 | |||||||||||
| 23 | # add support for --help and --version | ||||||||||
| 24 | 3 | $Getopt::Std::STANDARD_HELP_VERSION = "true"; | |||||||||
| 25 | 3 | my $VERSION = '0.19'; | |||||||||
| 26 | 0 | ▶ | sub VERSION_MESSAGE { | ||||||||
|
Subroutine
VERSION_MESSAGE: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 0 | print "$prog: version $VERSION\n"; | |||||||||
| 28 | } | ||||||||||
| 29 | 0 | ▶ | sub HELP_MESSAGE { | ||||||||
|
Subroutine
HELP_MESSAGE: not called CC=1 SCAR=6.9
| |||||||||||
| 30 | 0 | print STDERR $Usage; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 3 | my %opt; | |||||||||
| 34 | 3 | ▶ | if (!&getopts('o:V', \%opt)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | print STDERR $Usage; | |||||||||
| 36 | 0 | exit 1; | |||||||||
| 37 | } | ||||||||||
| 38 | 3 | ▶ | my $outFile = defined $opt{'o'} ? $opt{'o'} : '-'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 3 | ▶ | if (defined $opt{'V'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | print "$prog: version $VERSION\n"; | |||||||||
| 41 | 0 | exit 0; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 3 | ▶ | if (@ARGV == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | print STDERR "$prog: no files to cat\n"; | |||||||||
| 46 | 0 | die $Usage; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 3 | my $out; | |||||||||
| 50 | 3 | ▶ | if ($outFile eq '-') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 1 | $out = new IO::Handle; | |||||||||
| 52 | 1 | ▶ | if (!$out->fdopen("STDOUT", "w")) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | die "$prog: can't fdopen STDOUT - $!\n"; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | else { | ||||||||||
| 57 | 2 | $out = new IO::File $outFile, 'w'; | |||||||||
| 58 | 2 | ▶ | if (!defined $out) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | die "$prog: couldn't open $outFile for writing - $!\n"; | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 3 | my $ok = 1; | |||||||||
| 64 | 3 | my $file; | |||||||||
| 65 | 3 | foreach $file (@ARGV) { | |||||||||
| 66 | 3 | my $in = new IO::File $file, "r"; | |||||||||
| 67 | 3 | ▶ | if (!defined $in) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | print STDERR "$prog: can't open $file - $!\n"; | |||||||||
| 69 | 0 | $ok = 0; | |||||||||
| 70 | 0 | next; | |||||||||
| 71 | } | ||||||||||
| 72 | 3 | my $ini = new App::IniDiff::IniFile($in); | |||||||||
| 73 | 3 | $in->close; | |||||||||
| 74 | 3 | ▶ | if (!defined $ini) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 1 | print STDERR "$prog: $file:${App::IniDiff::IniFile::errorString}\n"; | |||||||||
| 76 | 1 | $ok = 0; | |||||||||
| 77 | 1 | next; | |||||||||
| 78 | } | ||||||||||
| 79 | 2 | $ini->write($out); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 3 | exit $ok ? 0 : 1; | |||||||||
| 83 | |||||||||||
| 84 | __END__ | ||||||||||