mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Meta/indent-cpp-directive: C preprocessor directive indentation rules
This commit is contained in:
32
indent-cpp-directive.perl
Executable file
32
indent-cpp-directive.perl
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $indent_level = -1;
|
||||
|
||||
sub emit {
|
||||
my $indent = $indent_level <= 0 ? "" : " " x $indent_level;
|
||||
printf "#%s%s", $indent, $_;
|
||||
}
|
||||
|
||||
while (<>) {
|
||||
unless (s/^\s*#\s*//) {
|
||||
print;
|
||||
next;
|
||||
}
|
||||
|
||||
if (/^if/) {
|
||||
emit($_);
|
||||
$indent_level++;
|
||||
} elsif (/^el/) {
|
||||
$indent_level--;
|
||||
emit($_);
|
||||
$indent_level++;
|
||||
} elsif (/^endif/) {
|
||||
$indent_level--;
|
||||
emit($_);
|
||||
} else {
|
||||
emit($_);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user