File: update_copyright.pl

package info (click to toggle)
xorp 1.8.5-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,560 kB
  • ctags: 54,995
  • sloc: cpp: 397,204; sh: 17,490; ansic: 17,029; python: 7,643; lex: 1,632; yacc: 1,474; awk: 956; makefile: 251; perl: 217; sed: 33
file content (65 lines) | stat: -rwxr-xr-x 1,622 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl

use strict;

if (@ARGV < 2) {
  print "Usage: update_copyright.pl <year> <file>\n";
  print "Example: update_copyright.pl 2011 foo.cc\n";
  exit(1);
}

my $year = $ARGV[0];
my $fname = $ARGV[1];
my $tmpfname = "/tmp/xorp_copyright_update.tmp";
my $found_one = 0;
my $next_xcr = 0;

# Skip some files we should never directly update.
if ($fname =~ /^docs\/wiki\//) {
  print "Skipping wiki file: $fname\n";
  exit(0);
}

open(FH, "<", $fname) or die "Can't open file: $fname  : $!";
open(OUTF, ">", "$tmpfname") or die "Can't open output file: $tmpfname  : $!";

while(<FH>) {
  my $ln = $_;
  if ($ln =~ /Copyright \(c\) (\d\d\d\d)-(\d\d\d\d) XORP, Inc and Others/) {
    if ($2 ne $year) {
      $found_one = 1;
    }
    $ln =~ s/Copyright \(c\) (\d\d\d\d)-(\d\d\d\d) XORP, Inc and Others/Copyright \(c\) $1-$year XORP, Inc and Others/g;
  }
  elsif ($ln =~ /Copyright \(c\) (\d\d\d\d)-(\d\d\d\d) Mass/) {
    $next_xcr = 1;
  }
  elsif ($ln =~ /Copyright \(c\) (\d\d\d\d)/) {
    if ($1 ne $year) {
      $found_one = 1;
    }
    $ln =~ s/Copyright \(c\) (\d\d\d\d)/Copyright \(c\) $1-$year XORP, Inc and Others/g;
  }
  else {
    if ($next_xcr == 1) {
      $found_one = 1;
      # Need to insert a copyright line for xorp
      if ($fname =~ /\.c$/) {
	print OUTF "/* Copyright (c) $year-$year XORP, Inc and Others */\n";
      }
      else {
	print OUTF "// Copyright (c) $year-$year XORP, Inc and Others\n";
      }
      $next_xcr = 0;
    }
  }
  print OUTF $ln;
}

if ($found_one) {
  print "Updated file: $fname\n";
  `mv $tmpfname $fname`;
}
else {
  print "No changes to file: $fname\n";
}