4 # Morgan Deters <mdeters@cs.nyu.edu> for CVC4
5 # Copyright (c) 2009, 2010 The CVC4 Project
7 # usage: update-copyright [ files/directories... ]
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.
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.
18 # It ignores any file/directory not starting with [a-zA-Z]
19 # (so, this includes . and .., vi swaps, .svn meta-info,
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.)
26 # It ignores any directory matching $excluded_directories
27 # (so, you should add here any sources imported but not covered under
30 my $excluded_directories = '^(minisat|CVS|generated)$';
31 my $excluded_paths = '^(src/parser/bounded_token_buffer\.(h|cpp))$';
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';
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
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
61 $dir =~ s
,/[^/]+/*$,,;
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;
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.
74 The directories in which to search for and change sources is:
82 die 'aborting operation' if !( $_ eq 'y' || $_ eq 'yes' || $_ eq 'Y' || $_ eq 'YES' );
84 $searchdirs[0] = 'src';
85 $searchdirs[1] = 'test';
90 print "Updating sources...\n";
92 recurse
(shift @searchdirs) while $#searchdirs >= 0;
96 print "in dir $srcdir\n";
97 opendir(my $DIR, $srcdir);
98 while(my $file = readdir $DIR) {
99 next if !($file =~ /^[a-zA-Z]/);
101 my $mode = (stat($srcdir.'/'.$file))[2];
102 my $is_directory = S_ISDIR
($mode);
104 next if $file =~ /$excluded_directories/;
105 recurse
($srcdir.'/'.$file);
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;
120 if(m
,^(%{)?
/\
*(\
*| )\
*\
*\
*,) {
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";
130 print $OUT "/********************* */\n";
131 print $OUT "/** $file\n";
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;
138 while(my $line = <$IN>) {
139 last if $line =~ /^ \*\*\s*$/;
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";
152 print $OUT "/********************* */\n";
153 print $OUT "/** $file\n";
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;
160 print $OUT " ** [[ Add file-specific comments here ]]\n";
161 print $OUT " **/\n\n";
163 if($file =~ /\.(y|yy|ypp|Y)$/) {
164 while(my $line = <$IN>) {
166 if($line =~ '\s*%{(.*)') {
170 # just in case something's weird with the file ?
171 if(!($line =~ '\s*')) {
172 print $OUT "$line\n";
178 while(my $line = <$IN>) {
183 rename($outfile, $infile) || die "can't rename working file \`$outfile' to \`$infile'";
190 ### perl-indent-level: 2