Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 49 lines (28 sloc) 1.25 KB
#!/usr/bin/perl
# Usage: tools/patchLicense LICENSE.txt $( find . -name "*.[chm]" | grep -v filestoavoid )
use strict;
use warnings;
my $licenseFile = shift @ARGV;
my @files = @ARGV;
die "Usage: $0 licensefile-containing-marker files...\n" unless $licenseFile and @files;
my @license = map { s/\s*$//; $_ } qx{ sed '1,/^LICENSE TERMS/d' $licenseFile };
for my $file ( @files ) {
warn "# working on $file\n";
open(FILE, "<", "$file") or die "$0: can't open '$file' for reading ($!)\n";
my @lines = <FILE>;
close(FILE);
shift @lines while($lines[0] =~ /^\s*$/ ); # skip whitespace
shift @lines while $lines[0] =~ m!^\s*//!; # skip // lines
shift @lines while($lines[0] =~ /^\s*$/ ); # skip whitespace
if( $lines[0] =~ m!^\s*/\*! ) {
shift @lines while( $lines[0] !~ m!\*/! ); # skip /* ... */
shift @lines if $lines[0] =~ m!\*/\s*$!;
}
shift @lines while($lines[0] =~ /^\s*$/ ); # skip whitespace
unshift @lines, "/*\n", ( map { length($_) ? " " . "$_\n" : "$_\n" } @license ) , "*/\n", "\n"; # add license
push @lines, "\n" unless $lines[-1] =~ /\n/; # end trailing newline
open(FILE, ">", $file) or die "$0: can't open '$file' for writing ($!)\n";
print FILE @lines;
close(FILE);
}
exit 0;