Path: blob/main/Tools/scripts/indent_make_if.pl
16461 views
#!/usr/bin/env perl1# perltidy -bext=/ -i=8 -et=8 -l=132 -pt=2 -ce -cti=123use strict;4use utf8;5use warnings;67my $extension = '.orig';8my $oldargv = q{};9my $spaces = 2;10my $indent;11my $argvout;1213sub dotindent {14my $amount = shift;15return '.' . (' ' x ($spaces * $amount));16}1718LINE: while (<>) {1920# For each file, save a .orig backup.21if ($ARGV ne $oldargv) {22my $backup;23if ($extension !~ /[*]/) {24$backup = $ARGV . $extension;25} else {26($backup = $extension) =~ s/[*]/$ARGV/g;27}28rename $ARGV, $backup;29open $argvout, '>', $ARGV or die "Error for $ARGV: $!";30$oldargv = $ARGV;31$indent = 0;32}3334if (/^[.]\s*(?:if|for)/o) { # if/for -> indent and increase indent35s/^[.]\s*/dotindent($indent)/oe;36$indent++;37} elsif (/^[.]\s*end(?:if|for)/o) { # endif/endfor -> decrease indent and indent38$indent--;39s/^[.]\s*/dotindent($indent)/oe;40} elsif (/^[.]\s*(?:else|elif)/o) { # else/elif -> indent one level down41s/^[.]\s*/dotindent($indent-1)/oe;42}43} continue {4445# Print the line.46print {$argvout} $_;47}484950