diff options
author | mat <mat@FreeBSD.org> | 2016-06-02 22:13:57 +0800 |
---|---|---|
committer | mat <mat@FreeBSD.org> | 2016-06-02 22:13:57 +0800 |
commit | e424314cb52493e50e5b2725bc450880b87ca612 (patch) | |
tree | caed2919baae4ffea0d8242bc6cb3ee22007f935 /Tools | |
parent | 4fb6a685cf91d98d62c09b561e349cae9e6793bf (diff) | |
download | freebsd-ports-gnome-e424314cb52493e50e5b2725bc450880b87ca612.tar.gz freebsd-ports-gnome-e424314cb52493e50e5b2725bc450880b87ca612.tar.zst freebsd-ports-gnome-e424314cb52493e50e5b2725bc450880b87ca612.zip |
Add a script to indent make(1)'s .if/.for blocks.
Sponsored by: Absolight
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/indent_make_if.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Tools/scripts/indent_make_if.pl b/Tools/scripts/indent_make_if.pl new file mode 100755 index 000000000000..5c5e4466bd60 --- /dev/null +++ b/Tools/scripts/indent_make_if.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +# $FreeBSD$ +# perltidy -bext=/ -i=8 -et=8 -l=132 -pt=2 -ce -cti=1 + +use strict; +use utf8; +use warnings; + +my $extension = '.orig'; +my $oldargv = q{}; +my $indent; +my $argvout; +LINE: while (<>) { + + # For each file, save a .orig backup. + if ($ARGV ne $oldargv) { + my $backup; + if ($extension !~ /[*]/) { + $backup = $ARGV . $extension; + } else { + ($backup = $extension) =~ s/[*]/$ARGV/g; + } + rename $ARGV, $backup; + open $argvout, '>', $ARGV; + $oldargv = $ARGV; + $indent = 0; + } + + if (/^[.]\s*(?:if|for)/o) { # if/for -> indent and increase indent + s/^[.]\s*/"." . " " x $indent/oe; + $indent++; + } elsif (/^[.]\s*end(?:if|for)/o) { # endif/endfor -> decrease indent and indent + $indent--; + s/^[.]\s*/"." . " " x $indent/oe; + } elsif (/^[.]\s*(?:else|elif)/o) { # else/elif -> indent one level down + s/^[.]\s*/"." . " " x ($indent - 1)/oe; + } +} continue { + + # Print the line. + print {$argvout} $_; +} |