public
Last active

Reformat phpbb files to phpbb coding standards

  • Download Gist
phpbb-reformat.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/env perl
 
die "Usage: reformat-phpbb file ..." unless @ARGV;
 
if ($ARGV[0] == '-8') {
$indent = 8;
shift @ARGV;
} elsif ($ARGV[0] == '-2') {
$indent = 2;
shift @ARGV;
} else {
$indent = undef;
}
 
undef $/;
for $file (@ARGV) {
open FH, $file or die "Can't open file for reading: $file";
$_ = <FH>;
close FH;
if ($indent) {
$rep = $indent;
} else {
if (/^ {1,3}\S/m) {
$rep = 2;
} else {
$rep = 8;
}
}
s|^(( {$rep})+)|"\t" x (length($1) / $rep)|gem;
s|^(\t*)(.*) \{$|$1$2\n${1}{|gm;
s/^(\t*)} else/\1}\n\1else/gm;
s/^(\t*)$//gm;
open FH, ">$file" or die "Can't open file for writing: $file";
print FH $_;
print $rep;
close FH;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.