~ubuntu-branches/ubuntu/lucid/spamassassin/lucid-proposed

« back to all changes in this revision

Viewing changes to build/replace_license_blocks

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2006-12-06 15:25:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061206152533-0lq5d0c8f7le7ugq
Tags: 3.1.7-1ubuntu1
* Merge from Debian unstable. The remaining Ubuntu changes are:
  - debian/control:
    + libmail-spf-query-perl from Recommends to Depends for spamassassin 
      binary (Ubuntu: #28486)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -i.bak
2
 
#
3
 
# build/replace_license_blocks file ...
4
 
#
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.
9
 
#
10
 
#     * <@LICENSE>
11
 
#
12
 
# will result in all lines of the license text being prefixed with "    * ".
13
 
 
14
 
# read the new license text; die if not available
15
 
open (IN, "<newlicense") or die "cannot read 'newlicense'";
16
 
my $license = join ('', <IN>);
17
 
close IN;
18
 
 
19
 
# remove final comment if present
20
 
$license =~ s/\n \*\/$//gs;
21
 
# remove C comment start-of-line markers
22
 
$license =~ s/^(?:\/\* | \* | \*\/| \*)//gm;
23
 
 
24
 
# and fixup in-place
25
 
$in_license_block = 0;
26
 
 
27
 
while (<>) {
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;
32
 
    }
33
 
  } else {
34
 
    if (s{^(.+)<\@LICENSE>\s*$}{ license_with_prefix($1); }eg) {
35
 
      $in_license_block = 1;
36
 
    } else {
37
 
      # a non-block form -- will be replaced with a block
38
 
      s{^(.+)\@LICENSE\s*$}{ license_with_prefix($1); }eg;
39
 
    }
40
 
    print;
41
 
  }
42
 
}
43
 
 
44
 
sub license_with_prefix {
45
 
  my $prefix = shift;
46
 
  my $text = $license; $text =~ s/^/$prefix/gm;
47
 
 
48
 
  return $prefix."<\@LICENSE>\n".
49
 
    $text.
50
 
    $prefix."</\@LICENSE>\n";
51
 
}