mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
test-wrap-argv: split out rewrap_line
Shorten the rewrap subroutine by splitting out the code dealing with a single line. Also remove $file from the warning.
This commit is contained in:
parent
8ebf780e08
commit
a615a2fa58
@ -59,70 +59,76 @@ sub rewrap {
|
|||||||
# Now each @lines represents a single command, we
|
# Now each @lines represents a single command, we
|
||||||
# can process them
|
# can process them
|
||||||
foreach my $line (@lines) {
|
foreach my $line (@lines) {
|
||||||
my @bits = split / /, join('', $line);
|
&rewrap_line ($line);
|
||||||
|
}
|
||||||
|
|
||||||
# @bits contains env vars, then the command line
|
}
|
||||||
# and then the arguments
|
|
||||||
my @env;
|
|
||||||
my $cmd;
|
|
||||||
my @args;
|
|
||||||
|
|
||||||
if ($bits[0] !~ /=/) {
|
sub rewrap_line {
|
||||||
$cmd = shift @bits;
|
my $line = shift;
|
||||||
}
|
my @bits = split / /, join('', $line);
|
||||||
|
|
||||||
foreach my $bit (@bits) {
|
# @bits contains env vars, then the command line
|
||||||
# If no command is defined yet, we must still
|
# and then the arguments
|
||||||
# have env vars
|
my @env;
|
||||||
if (!defined $cmd) {
|
my $cmd;
|
||||||
# Look for leading / to indicate command name
|
my @args;
|
||||||
if ($bit =~ m,^/,) {
|
|
||||||
$cmd = $bit;
|
if ($bits[0] !~ /=/) {
|
||||||
} else {
|
$cmd = shift @bits;
|
||||||
push @env, $bit;
|
}
|
||||||
}
|
|
||||||
|
foreach my $bit (@bits) {
|
||||||
|
# If no command is defined yet, we must still
|
||||||
|
# have env vars
|
||||||
|
if (!defined $cmd) {
|
||||||
|
# Look for leading / to indicate command name
|
||||||
|
if ($bit =~ m,^/,) {
|
||||||
|
$cmd = $bit;
|
||||||
} else {
|
} else {
|
||||||
# If there's a leading '-' then this is a new
|
push @env, $bit;
|
||||||
# parameter, otherwise its a value for the prev
|
|
||||||
# parameter.
|
|
||||||
if ($bit =~ m,^-,) {
|
|
||||||
push @args, $bit;
|
|
||||||
} else {
|
|
||||||
$args[$#args] .= " " . $bit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
# If there's a leading '-' then this is a new
|
||||||
# Print env + command first
|
# parameter, otherwise its a value for the prev
|
||||||
print join(" \\\n", @env, $cmd), " \\\n";
|
# parameter.
|
||||||
# We might have to split line argument values...
|
if ($bit =~ m,^-,) {
|
||||||
for (my $i = 0; $i <= $#args; $i++) {
|
push @args, $bit;
|
||||||
my $arg = $args[$i];
|
|
||||||
while (length($arg) > 80) {
|
|
||||||
my $split = rindex $arg, ",", 80;
|
|
||||||
if ($split == -1) {
|
|
||||||
$split = rindex $arg, ":", 80;
|
|
||||||
}
|
|
||||||
if ($split == -1) {
|
|
||||||
$split = rindex $arg, " ", 80;
|
|
||||||
}
|
|
||||||
if ($split == -1) {
|
|
||||||
warn "$file: cannot find nice place to split '$arg' below 80 chars\n";
|
|
||||||
$split = 79;
|
|
||||||
}
|
|
||||||
$split++;
|
|
||||||
|
|
||||||
my $head = substr $arg, 0, $split;
|
|
||||||
$arg = substr $arg, $split;
|
|
||||||
|
|
||||||
print $head, "\\\n";
|
|
||||||
}
|
|
||||||
print $arg;
|
|
||||||
if ($i != $#args) {
|
|
||||||
print " \\\n";
|
|
||||||
} else {
|
} else {
|
||||||
print "\n";
|
$args[$#args] .= " " . $bit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print env + command first
|
||||||
|
print join(" \\\n", @env, $cmd), " \\\n";
|
||||||
|
# We might have to split line argument values...
|
||||||
|
for (my $i = 0; $i <= $#args; $i++) {
|
||||||
|
my $arg = $args[$i];
|
||||||
|
while (length($arg) > 80) {
|
||||||
|
my $split = rindex $arg, ",", 80;
|
||||||
|
if ($split == -1) {
|
||||||
|
$split = rindex $arg, ":", 80;
|
||||||
|
}
|
||||||
|
if ($split == -1) {
|
||||||
|
$split = rindex $arg, " ", 80;
|
||||||
|
}
|
||||||
|
if ($split == -1) {
|
||||||
|
warn "cannot find nice place to split '$arg' below 80 chars\n";
|
||||||
|
$split = 79;
|
||||||
|
}
|
||||||
|
$split++;
|
||||||
|
|
||||||
|
my $head = substr $arg, 0, $split;
|
||||||
|
$arg = substr $arg, $split;
|
||||||
|
|
||||||
|
print $head, "\\\n";
|
||||||
|
}
|
||||||
|
print $arg;
|
||||||
|
if ($i != $#args) {
|
||||||
|
print " \\\n";
|
||||||
|
} else {
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user