Date: Thu, 2 Jun 2016 14:13:58 +0000 (UTC) From: Mathieu Arnold <mat@FreeBSD.org> To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r416279 - head/Tools/scripts Message-ID: <201606021413.u52EDwuw012359@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mat Date: Thu Jun 2 14:13:57 2016 New Revision: 416279 URL: https://svnweb.freebsd.org/changeset/ports/416279 Log: Add a script to indent make(1)'s .if/.for blocks. Sponsored by: Absolight Added: head/Tools/scripts/indent_make_if.pl (contents, props changed) Added: head/Tools/scripts/indent_make_if.pl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/Tools/scripts/indent_make_if.pl Thu Jun 2 14:13:57 2016 (r416279) @@ -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} $_; +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606021413.u52EDwuw012359>