Skip to content

Commit f4840fd

Browse files
committed
Meta/indent-cpp-directive: C preprocessor directive indentation rules
1 parent e8bdc59 commit f4840fd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

indent-cpp-directive.perl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
6+
my $indent_level = -1;
7+
8+
sub emit {
9+
my $indent = $indent_level <= 0 ? "" : " " x $indent_level;
10+
printf "#%s%s", $indent, $_;
11+
}
12+
13+
while (<>) {
14+
unless (s/^\s*#\s*//) {
15+
print;
16+
next;
17+
}
18+
19+
if (/^if/) {
20+
emit($_);
21+
$indent_level++;
22+
} elsif (/^el/) {
23+
$indent_level--;
24+
emit($_);
25+
$indent_level++;
26+
} elsif (/^endif/) {
27+
$indent_level--;
28+
emit($_);
29+
} else {
30+
emit($_);
31+
}
32+
}

0 commit comments

Comments
 (0)