aboutsummaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorMathieu Arnold <mat@FreeBSD.org>2016-06-02 14:13:57 +0000
committerMathieu Arnold <mat@FreeBSD.org>2016-06-02 14:13:57 +0000
commit7fcd63424c929adc13c1bc2acccb6b471d4d7ca3 (patch)
treecaed2919baae4ffea0d8242bc6cb3ee22007f935 /Tools
parent55ba3c0da65c110675b15f51abf296e4c07cc289 (diff)
downloadports-7fcd63424c929adc13c1bc2acccb6b471d4d7ca3.tar.gz
ports-7fcd63424c929adc13c1bc2acccb6b471d4d7ca3.zip
Add a script to indent make(1)'s .if/.for blocks.
Sponsored by: Absolight
Notes
Notes: svn path=/head/; revision=416279
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/scripts/indent_make_if.pl42
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} $_;
+}