Created
April 15, 2010 08:27
-
-
Save p/366837 to your computer and use it in GitHub Desktop.
Reformat phpbb files to phpbb coding standards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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