aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGravatar K. \"pestophagous\" Heller <pestophagous@gmail.com>2015-10-17 17:05:36 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-19 07:37:35 -0700
commit5902a1aace98783cd38abdc2c439c6c1042e80b7 (patch)
tree994f191338ca336a171df00f9f9a81a56441deba /scripts
parentefaf697e769bb6108798febd1b4a9db611b61374 (diff)
downloadsubsurface-5902a1aace98783cd38abdc2c439c6c1042e80b7.tar.gz
Add perl function indent_ctor_init_lists to whitespace.pl
whitespace.pl can now do a better job (although surely still not 100% perfect job) of formatting constructor member initialization lists according to the rules described in the current CodingStyle file. Signed-off-by: K. Heller <pestophagous@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/whitespace.pl38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/whitespace.pl b/scripts/whitespace.pl
index 6cd808123..9ed9bf431 100755
--- a/scripts/whitespace.pl
+++ b/scripts/whitespace.pl
@@ -38,6 +38,44 @@ $source =~ s/^(#(?:if |)define.*)((?:\\\n.*){4})\n +([^*].*)$/$1$2\n\t$3/mg;
$source =~ s/^(#(?:if |)define.*)((?:\\\n.*){5})\n +([^*].*)$/$1$2\n\t$3/mg;
# don't put line break before the last single term argument of a calculation
$source =~ s/(?:\G|^)(.*[+-])\n\s*(\S*\;)$/$1 $2/mg;
+
+sub indent_ctor_init_lists {
+ my($content) = @_;
+
+ my @not_ctor_words = qw(
+ \bdo\b
+ \belse\b
+ \bfor\b
+ \bif\b
+ \bsizeof\b
+ \bswitch\b
+ \bwhile\b
+ \btr\b
+ \bconnect\b
+ );
+
+ my $regexStr = "(" . join("|", @not_ctor_words) . ")";
+ my $not_ctor_regex = qr{$regexStr};
+
+ my $result = "";
+
+ for ( split(/\n/, $content) ) {
+
+ if ($_ =~ $not_ctor_regex) {
+ # probably not a ctor line. leave it be.
+ $result .= $_ . "\n";
+ }
+ else {
+ $_ =~ s/^\s*(\w*\(.*\),?)$/\t$1/mg;
+ $result .= $_ . "\n";
+ }
+ }
+
+ return $result;
+}
+
+$source = indent_ctor_init_lists($source);
+
$quotedinput = $input;
$quotedinput =~ s|/|\\/|g;
open (DIFF, "| diff -u $input - | sed -e 's/--- $quotedinput/--- $quotedinput.old/' | sed -e 's/+++ -/+++ $quotedinput/'");