mibew/src/messenger/tools/header_update.pl
Evgeny Gryaznov fe8af1fe34 update header script
git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@605 c66351dc-e62f-0410-b875-e3a5c0b9693f
2009-08-04 16:31:23 +00:00

64 lines
1.5 KiB
Perl
Executable File

#!/usr/bin/perl
$sourceFolder = "../webim";
sub file_content($) {
my $input = $_[0];
open( IN1, "< $input" ) or die "cannot find file $input";
$/ = EOI;
$content = <IN1>;
$content =~ s/\r//g;
close( IN1 );
return $content;
}
$php_header = file_content("header.txt");
$php_header =~ s/\s+$//;
@allfiles = ();
sub process_folder($) {
my($from) = @_;
opendir(DIR, $from) || die "can't opendir $from: $!";
my @content = readdir(DIR);
closedir DIR;
for(grep { -f "$from/$_" && ($_ !~ /^\./ || $_ eq ".htaccess") } @content) {
push @allfiles, "$from/$_";
}
for(grep { -d "$from/$_" && $_ !~ /^\./ } @content) {
process_folder("$from/$_");
}
}
process_folder($sourceFolder);
P: for $phpfile (grep { /\.php$/ } @allfiles) {
$content = file_content($phpfile);
$content =~ s/\s+$//g;
die "not a php: $phpfile" unless $content =~ /^<\?php\n(\/\*.*?\*\/)?/s;
die "no comment in $phpfile" unless defined($1);
$comment = $1;
if($comment =~ /\[external\]/) {
next P;
};
die "no contributors in $phpfile" unless $comment =~ /Contributors:/;
$newcomment = $comment;
$newcomment =~ s/\s\*\s//g;
$newcomment =~ s/^\/\*//;
$newcomment =~ s/\*\/$//;
$newcomment =~ s/.*(Contributors:)/$1/s;
$newcomment =~ s/^\s+//;
$newcomment =~ s/\s+$//;
$newcomment = "$php_header\n\n$newcomment";
$newcomment =~ s/^/ * /gm;
$newcomment = "/*\n$newcomment\n */";
$content =~ s/^(<\?php\n)\/\*.*?\*\//$1$newcomment/s;
open( OUT, "> $phpfile" ) or die "cannot write file: $phpfile\n";
print OUT $content;
close( OUT );
}