svn commit: r417014 - head/Tools/scripts

Mathieu Arnold mat at FreeBSD.org
Fri Jun 17 14:58:37 UTC 2016


Author: mat
Date: Fri Jun 17 14:58:36 2016
New Revision: 417014
URL: https://svnweb.freebsd.org/changeset/ports/417014

Log:
  Refactor a bit.
  
  Sponsored by:	Absolight

Modified:
  head/Tools/scripts/indent_make_if.pl

Modified: head/Tools/scripts/indent_make_if.pl
==============================================================================
--- head/Tools/scripts/indent_make_if.pl	Fri Jun 17 13:44:39 2016	(r417013)
+++ head/Tools/scripts/indent_make_if.pl	Fri Jun 17 14:58:36 2016	(r417014)
@@ -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 {
 


More information about the svn-ports-head mailing list