Skip to content

Instantly share code, notes, and snippets.

@p
Created April 15, 2010 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p/366837 to your computer and use it in GitHub Desktop.
Save p/366837 to your computer and use it in GitHub Desktop.
Reformat phpbb files to phpbb coding standards
#!/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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment