aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/whitespace.pl
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-25 12:28:00 -0700
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-07-26 16:32:51 +0300
commit68b5fe9ccbbc7255a00d657cf29e6dc2515b8c3c (patch)
tree56e87f2c865bee8696c8a9e2cec9bed6f969c0ea /scripts/whitespace.pl
parent19871a6ab2c7a3022e0f7981154d4d6cd59715a9 (diff)
downloadsubsurface-68b5fe9ccbbc7255a00d657cf29e6dc2515b8c3c.tar.gz
Small edit of whitespace script
This makes sure we don't end up indenting macro invocations. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'scripts/whitespace.pl')
-rwxr-xr-xscripts/whitespace.pl8
1 files changed, 8 insertions, 0 deletions
diff --git a/scripts/whitespace.pl b/scripts/whitespace.pl
index 9ed9bf431..2cb01b5bc 100755
--- a/scripts/whitespace.pl
+++ b/scripts/whitespace.pl
@@ -2,6 +2,7 @@
my $input = $ARGV[0];
my $source = `clang-format $input`;
+
# for_each_dive (...) and Q_FOREACH and friends...
$source =~ s/(?:\G|^)(.*each.*\(.*) \* (\S.*\))$/$1 *$2/img; # if a variable is declared in the argument, '*' is an indicator for a pointer, not arithmatic
$source =~ s/(?:\G|^)(.*each.*\(.*) \& (\S.*\))$/$1 &$2/img; # if a variable is declared in the argument, '&' is an indicator for a reference, not bit logic
@@ -15,14 +16,18 @@ $source =~ s/^(\s*static\s+struct[^()\n]*)\n\s*{\s*$/$1 {/img;
$source =~ s/^(\s*union[^()\n]*)\n\s*{\s*$/$1 {/img;
$source =~ s/^(\s*static\s+union[^()\n]*)\n\s*{\s*$/$1 {/img;
$source =~ s/^(\s*class.*)\n\s*{\s*$/$1 {/img;
+
# a namespace shouldn't look like a function
$source =~ s/(?:\G|^)(namespace.*)\n\{/$1 {/img;
+
# colon goes at the end of a line
$source =~ s/^(\S*::\S*.*)\n\s*: /$1 : /img;
+
# odd indentations from clang-format:
# six spaces or four spaces after tabs (for continuation strings)
$source =~ s/(?:\G|^)[ ]{6}/\t/mg;
$source =~ s/(?:\G|^)(\t*)[ ]{4}"/$1\t"/mg;
+
# the next ones are rather awkward
# they capture multi line #define and #if definded statements
# that clang-format messes up (where does that 4 space indentation come
@@ -36,12 +41,14 @@ $source =~ s/^(#(?:if |)define.*)((?:\\\n.*){2})\n +([^*].*)$/$1$2\n\t$3/mg;
$source =~ s/^(#(?:if |)define.*)((?:\\\n.*){3})\n +([^*].*)$/$1$2\n\t$3/mg;
$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) = @_;
+ # all caps/_ with just an argument list is a macro invocation and shouldn't be moved
my @not_ctor_words = qw(
\bdo\b
\belse\b
@@ -52,6 +59,7 @@ sub indent_ctor_init_lists {
\bwhile\b
\btr\b
\bconnect\b
+ ^[A-Z_]+\(.*\)$
);
my $regexStr = "(" . join("|", @not_ctor_words) . ")";