diff options
author | Mathieu Arnold <mat@FreeBSD.org> | 2016-06-17 14:58:36 +0000 |
---|---|---|
committer | Mathieu Arnold <mat@FreeBSD.org> | 2016-06-17 14:58:36 +0000 |
commit | 75a1df13c598e3030d81ee7f79defbe0eb9a550d (patch) | |
tree | 17449ec864fc4e31d6bf7c8fdb01cf8ca20c60b6 /Tools | |
parent | bf3282080ec46292f07db7727d0ea8d1866a249b (diff) | |
download | ports-75a1df13c598e3030d81ee7f79defbe0eb9a550d.tar.gz ports-75a1df13c598e3030d81ee7f79defbe0eb9a550d.zip |
Refactor a bit.
Sponsored by: Absolight
Notes
Notes:
svn path=/head/; revision=417014
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/indent_make_if.pl | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Tools/scripts/indent_make_if.pl b/Tools/scripts/indent_make_if.pl index 5c5e4466bd60..7e2758c0606a 100755 --- a/Tools/scripts/indent_make_if.pl +++ b/Tools/scripts/indent_make_if.pl @@ -8,8 +8,15 @@ use warnings; my $extension = '.orig'; my $oldargv = q{}; +my $spaces = 2; my $indent; my $argvout; + +sub dotindent { + my $amount = shift; + return '.' . (' ' x ($spaces * $amount)); +} + LINE: while (<>) { # For each file, save a .orig backup. @@ -21,19 +28,19 @@ LINE: while (<>) { ($backup = $extension) =~ s/[*]/$ARGV/g; } rename $ARGV, $backup; - open $argvout, '>', $ARGV; + open $argvout, '>', $ARGV or die "Error for $ARGV: $!"; $oldargv = $ARGV; $indent = 0; } if (/^[.]\s*(?:if|for)/o) { # if/for -> indent and increase indent - s/^[.]\s*/"." . " " x $indent/oe; + s/^[.]\s*/dotindent($indent)/oe; $indent++; } elsif (/^[.]\s*end(?:if|for)/o) { # endif/endfor -> decrease indent and indent $indent--; - s/^[.]\s*/"." . " " x $indent/oe; + s/^[.]\s*/dotindent($indent)/oe; } elsif (/^[.]\s*(?:else|elif)/o) { # else/elif -> indent one level down - s/^[.]\s*/"." . " " x ($indent - 1)/oe; + s/^[.]\s*/dotindent($indent-1)/oe; } } continue { |