3
# build/replace_license_blocks file ...
5
# Replace a <@LICENSE> ... </@LICENSE> delimited block of comment text inside
6
# an arbitrary number of files with the contents of the file named
7
# 'newlicense'. The comment character to use at start-of-line is read
8
# from the file being worked on, e.g.
12
# will result in all lines of the license text being prefixed with " * ".
14
# read the new license text; die if not available
15
open (IN, "<newlicense") or die "cannot read 'newlicense'";
16
my $license = join ('', <IN>);
19
# remove final comment if present
20
$license =~ s/\n \*\/$//gs;
21
# remove C comment start-of-line markers
22
$license =~ s/^(?:\/\* | \* | \*\/| \*)//gm;
25
$in_license_block = 0;
28
if ($in_license_block) {
29
# we're waiting until the end-of-license "closing tag"
30
if (s/^.+<\/\@LICENSE>//) {
31
$in_license_block = 0;
34
if (s{^(.+)<\@LICENSE>\s*$}{ license_with_prefix($1); }eg) {
35
$in_license_block = 1;
37
# a non-block form -- will be replaced with a block
38
s{^(.+)\@LICENSE\s*$}{ license_with_prefix($1); }eg;
44
sub license_with_prefix {
46
my $text = $license; $text =~ s/^/$prefix/gm;
48
return $prefix."<\@LICENSE>\n".
50
$prefix."</\@LICENSE>\n";