1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

logparse.pl: more sensible option-parsing.

Switched to Getopt::Long in place of the previous ad-hockery, which
will make it easier to add more (and more complicated) options.
This commit is contained in:
Simon Tatham 2018-04-05 18:19:08 +01:00
parent 510187a733
commit 204780080d

View File

@ -1,22 +1,25 @@
#!/usr/bin/perl
use Getopt::Long;
use strict;
use warnings;
use FileHandle;
my $dumpchannels = 0;
my $dumpdata = 0;
while ($ARGV[0] =~ /^-/) {
my $opt = shift @ARGV;
if ($opt eq "--") {
last; # stop processing options
} elsif ($opt eq "-c") {
$dumpchannels = 1;
} elsif ($opt eq "-d") {
$dumpdata = 1;
} else {
die "unrecognised option '$opt'\n";
}
GetOptions("dump-channels|c" => \$dumpchannels,
"dump-data|d" => \$dumpdata,
"help" => sub { &usage(\*STDOUT, 0); })
or &usage(\*STDERR, 1);
sub usage {
my ($fh, $exitstatus) = @_;
print $fh <<'EOF';
usage: logparse.pl [ options ] [ input-log-file ]
options: --dump-channels, -c dump the final state of every channel
--dump-data, -d save data of every channel to ch0.i, ch0.o, ...
EOF
exit $exitstatus;
}
my @channels = (); # ultimate channel ids are indices in this array