Improve argument parsing

This commit is contained in:
Aaro Altonen 2020-05-01 19:51:05 +03:00
parent 0e1804d8ee
commit 81d7f23942
1 changed files with 22 additions and 35 deletions

View File

@ -251,47 +251,34 @@ sub print_help {
} }
GetOptions( GetOptions(
"lib=s" => \(my $lib = ""), "lib|l=s" => \(my $lib = ""),
"role=s" => \(my $role = ""), "role|r=s" => \(my $role = ""),
"path=s" => \(my $path = ""), "path|p=s" => \(my $path = ""),
"threads=i" => \(my $threads = 0), "threadst|=i" => \(my $threads = 0),
"iter=i" => \(my $iter = 0), "iter|i=i" => \(my $iter = 0),
"best" => \(my $best = 0), "parse|s=s" => \(my $parse = ""),
"packet-loss=f" => \(my $pkt_loss = 100.0), "packet-loss|p=f" => \(my $pkt_loss = 100.0),
"frame-loss=f" => \(my $frame_loss = 100.0), "frame-loss|f=f" => \(my $frame_loss = 100.0),
"help" => \(my $help = 0) "help" => \(my $help = 0)
) or die "failed to parse command line!\n"; ) or die "failed to parse command line!\n";
if (!$lib and $path =~ m/.*(uvgrtp|ffmpeg|gstreamer).*/i) { $lib = $1 if (!$lib and $path =~ m/.*(uvgrtp|ffmpeg|gstreamer).*/i);
$lib = $1; $role = $1 if (!$role and $path =~ m/.*(recv|send).*/i);
} $threads = $1 if (!$threads and $path =~ m/.*_(\d+)threads.*/i);
$iter = $1 if (!$iter and $path =~ m/.*_(\d+)iter.*/i);
if (!$role and $path =~ m/.*(recv|send).*/i) {
$role = $1;
}
if (!$threads and $path =~ m/.*_(\d+)threads.*/i) {
$threads = $1;
}
if (!$iter and $path =~ m/.*_(\d+)iter.*/i) {
$iter = $1;
}
print_help() if $help or !$lib; print_help() if $help or !$lib;
print_help() if !$iter and !$best and !$csv; print_help() if !$iter and !$parse;
print_help() if (!$best and !$csv and (!$role or !$threads)); print_help() if (!$parse and (!$role or !$threads));
my @libs = ("uvgrtp", "ffmpeg"); my @libs = ("uvgrtp", "ffmpeg");
if (grep (/$lib/, @libs)) { die "not implemented\n" if !grep (/$lib/, @libs);
if ($best) {
parse_all($lib, $iter, $path, $pkt_loss, $frame_loss); if ($parse eq "best") {
} elsif ($role eq "send") { parse_all($lib, $iter, $path, $pkt_loss, $frame_loss);
print_send($lib, $iter, $threads, $path); } elsif ($role eq "send") {
} else { print_send($lib, $iter, $threads, $path);
print_recv($lib, $iter, $threads, $path);
}
} else { } else {
die "not implemented\n"; print_recv($lib, $iter, $threads, $path);
} }