reran update-copyright.pl to get new contributors and add new header comments to...
[cvc5.git] / contrib / update-copyright.pl
1 #!/usr/bin/perl -w
2 #
3 # update-copyright.pl
4 # Morgan Deters <mdeters@cs.nyu.edu> for CVC4
5 # Copyright (c) 2009, 2010 The CVC4 Project
6 #
7 # usage: update-copyright [ files/directories... ]
8 #
9 # This script goes through a source directory rewriting the top bits of
10 # source files to match a template (inline, below). For files with no
11 # top comment, it adds a fresh one.
12 #
13 # usage: contrib/update-copyright.pl [dirs...]
14 # if dirs... are unspecified, the script scans its own parent directory's
15 # "src" directory. Since it lives in contrib/ in the CVC4 source tree,
16 # that means src/ in the CVC4 source tree.
17 #
18 # It ignores any file/directory not starting with [a-zA-Z]
19 # (so, this includes . and .., vi swaps, .svn meta-info,
20 # .deps, etc.)
21 #
22 # It ignores any file not ending with one of:
23 # .c .cc .cpp .C .h .hh .hpp .H .y .yy .ypp .Y .l .ll .lpp .L .g
24 # (so, this includes emacs ~-backups, CVS detritus, etc.)
25 #
26 # It ignores any directory matching $excluded_directories
27 # (so, you should add here any sources imported but not covered under
28 # the license.)
29
30 my $excluded_directories = '^(minisat|CVS|generated)$';
31 my $excluded_paths = '^(src/parser/bounded_token_buffer\.(h|cpp))$';
32
33 # Years of copyright for the template. E.g., the string
34 # "1985, 1987, 1992, 1997, 2008" or "2006-2009" or whatever.
35 my $years = '2009, 2010';
36
37 my $standard_template = <<EOF;
38 ** This file is part of the CVC4 prototype.
39 ** Copyright (c) $years The Analysis of Computer Systems Group (ACSys)
40 ** Courant Institute of Mathematical Sciences
41 ** New York University
42 ** See the file COPYING in the top-level source directory for licensing
43 ** information.
44 EOF
45
46 my $public_template = <<EOF;
47 ** This file is part of the CVC4 prototype.
48 ** Copyright (c) $years The Analysis of Computer Systems Group (ACSys)
49 ** Courant Institute of Mathematical Sciences
50 ** New York University
51 ** See the file COPYING in the top-level source directory for licensing
52 ** information.
53 EOF
54
55 ## end config ##
56
57 use strict;
58 use Fcntl ':mode';
59
60 my $dir = $0;
61 $dir =~ s,/[^/]+/*$,,;
62
63 my @searchdirs = ();
64 if($#ARGV == -1) {
65 (chdir($dir."/..") && -f "src/include/cvc4_public.h") || die "can't find top-level source directory for CVC4";
66 my $pwd = `pwd`; chomp $pwd;
67
68 print <<EOF;
69 Warning: this script is dangerous. It will overwrite the header comments in your
70 source files to match the template in the script, attempting to retain file-specific
71 comments, but this isn't guaranteed. You should run this in an svn working directory
72 and run "svn diff" after to ensure everything was correctly rewritten.
73
74 The directories in which to search for and change sources is:
75 $pwd/src
76 $pwd/test
77
78 Continue? y or n:
79 EOF
80
81 $_ = <STDIN>; chomp;
82 die 'aborting operation' if !( $_ eq 'y' || $_ eq 'yes' || $_ eq 'Y' || $_ eq 'YES' );
83
84 $searchdirs[0] = 'src';
85 $searchdirs[1] = 'test';
86 } else {
87 @searchdirs = @ARGV;
88 }
89
90 print "Updating sources...\n";
91
92 recurse(shift @searchdirs) while $#searchdirs >= 0;
93
94 sub recurse {
95 my ($srcdir) = @_;
96 print "in dir $srcdir\n";
97 opendir(my $DIR, $srcdir);
98 while(my $file = readdir $DIR) {
99 next if !($file =~ /^[a-zA-Z]/);
100
101 my $mode = (stat($srcdir.'/'.$file))[2];
102 my $is_directory = S_ISDIR($mode);
103 if($is_directory) {
104 next if $file =~ /$excluded_directories/;
105 recurse($srcdir.'/'.$file);
106 } else {
107 next if !($file =~ /\.(c|cc|cpp|C|h|hh|hpp|H|y|yy|ypp|Y|l|ll|lpp|L|g)$/);
108 next if ($srcdir.'/'.$file) =~ /$excluded_paths/;
109 print "$srcdir/$file...";
110 my $infile = $srcdir.'/'.$file;
111 my $outfile = $srcdir.'/#'.$file.'.tmp';
112 open(my $IN, $infile) || die "error opening $infile for reading";
113 open(my $OUT, '>', $outfile) || die "error opening $outfile for writing";
114 open(my $AUTHOR, "$dir/get-authors " . $infile . '|');
115 my $author = <$AUTHOR>; chomp $author;
116 my $major_contributors = <$AUTHOR>; chomp $major_contributors;
117 my $minor_contributors = <$AUTHOR>; chomp $minor_contributors;
118 close $AUTHOR;
119 $_ = <$IN>;
120 if(m,^(%{)?/\*(\*| )\*\*\*,) {
121 print "updating\n";
122 if($file =~ /\.(y|yy|ypp|Y)$/) {
123 print $OUT "%{/******************* */\n";
124 print $OUT "/** $file\n";
125 } elsif($file =~ /\.g$/) {
126 # avoid javadoc-style comment here; antlr complains
127 print $OUT "/* ******************* */\n";
128 print $OUT "/* $file\n";
129 } else {
130 print $OUT "/********************* */\n";
131 print $OUT "/** $file\n";
132 }
133 print $OUT " ** Original author: $author\n";
134 print $OUT " ** Major contributors: $major_contributors\n";
135 print $OUT " ** Minor contributors (to current version): $minor_contributors\n";
136 print $OUT $standard_template;
137 print $OUT " **\n";
138 while(my $line = <$IN>) {
139 last if $line =~ /^ \*\*\s*$/;
140 }
141 } else {
142 my $line = $_;
143 print "adding\n";
144 if($file =~ /\.(y|yy|ypp|Y)$/) {
145 print $OUT "%{/******************* */\n";
146 print $OUT "/** $file\n";
147 } elsif($file =~ /\.g$/) {
148 # avoid javadoc-style comment here; antlr complains
149 print $OUT "/* ******************* */\n";
150 print $OUT "/* $file\n";
151 } else {
152 print $OUT "/********************* */\n";
153 print $OUT "/** $file\n";
154 }
155 print $OUT " ** Original author: $author\n";
156 print $OUT " ** Major contributors: $major_contributors\n";
157 print $OUT " ** Minor contributors (to current version): $minor_contributors\n";
158 print $OUT $standard_template;
159 print $OUT " **\n";
160 print $OUT " ** [[ Add file-specific comments here ]]\n";
161 print $OUT " **/\n\n";
162 print $OUT $line;
163 if($file =~ /\.(y|yy|ypp|Y)$/) {
164 while(my $line = <$IN>) {
165 chomp $line;
166 if($line =~ '\s*%{(.*)') {
167 print $OUT "$1\n";
168 last;
169 }
170 # just in case something's weird with the file ?
171 if(!($line =~ '\s*')) {
172 print $OUT "$line\n";
173 last;
174 }
175 }
176 }
177 }
178 while(my $line = <$IN>) {
179 print $OUT $line;
180 }
181 close $IN;
182 close $OUT;
183 rename($outfile, $infile) || die "can't rename working file \`$outfile' to \`$infile'";
184 }
185 }
186 closedir $DIR;
187 }
188
189 ### Local Variables:
190 ### perl-indent-level: 2
191 ### End: