4 # Morgan Deters <mdeters@cs.nyu.edu> for CVC4
5 # Copyright (c) 2009-2012 The CVC4 Project
7 # usage: update-copyright [-m] [files/directories...]
8 # update-copyright [-h | --help]
10 # This script goes through a source directory rewriting the top bits of
11 # source files to match a template (inline, below). For files with no
12 # top comment, it adds a fresh one.
14 # if no files/directories are unspecified, the script scans its own
15 # parent directory's "src" directory. Since it lives in contrib/ in
16 # the CVC4 source tree, that means src/ in the CVC4 source tree.
18 # If -m is specified as the first argument, all files and directories
19 # are scanned, but only ones modifed in the current working directory
20 # are modified (i.e., those that have status M in "svn status").
22 # It ignores any file/directory not starting with [a-zA-Z]
23 # (so, this includes . and .., vi swaps, .svn meta-info,
26 # It ignores any file not ending with one of:
27 # .c .cc .cpp .C .h .hh .hpp .H .y .yy .ypp .Y .l .ll .lpp .L .g
28 # (so, this includes emacs ~-backups, CVS detritus, etc.)
30 # It ignores any directory matching $excluded_directories
31 # (so, you should add here any sources imported but not covered under
35 my $excluded_directories = '^(minisat|CVS|generated)$';
36 my $excluded_paths = '^(src/parser/antlr_input_imports.cpp|src/bindings/compat/.*)$';
38 # Years of copyright for the template. E.g., the string
39 # "1985, 1987, 1992, 1997, 2008" or "2006-2009" or whatever.
40 my $years = '2009-2012';
42 my $standard_template = <<EOF;
43 ** This file is part of the CVC4 prototype.
44 ** Copyright (c) $years The Analysis of Computer Systems Group (ACSys)
45 ** Courant Institute of Mathematical Sciences
46 ** New York University
47 ** See the file COPYING in the top-level source directory for licensing
48 ** information.\\endverbatim
51 my $public_template = <<EOF;
52 ** This file is part of the CVC4 prototype.
53 ** Copyright (c) $years The Analysis of Computer Systems Group (ACSys)
54 ** Courant Institute of Mathematical Sciences
55 ** New York University
56 ** See the file COPYING in the top-level source directory for licensing
57 ** information.\\endverbatim
66 $dir =~ s
,/[^/]+/*$,,;
68 if($#ARGV >= 0 && $ARGV[0] eq '-h' || $ARGV[0] eq '--help') {
69 open(my $SELF, $0) || die "error opening $0 for reading";
78 # whether we ONLY process files with svn status "M"
81 if($#ARGV >= 0 && $ARGV[0] eq '-m') {
88 (chdir($dir."/..") && -f
"src/include/cvc4_public.h") || die "can't find top-level source directory for CVC4";
89 my $pwd = `pwd`; chomp $pwd;
92 Warning: this script is dangerous. It will overwrite the header comments in your
93 source files to match the template in the script, attempting to retain file-specific
94 comments, but this isn't guaranteed. You should run this in an svn working directory
95 and run "svn diff" after to ensure everything was correctly rewritten.
97 The directories in which to search for and change sources is:
105 die 'aborting operation' if !( $_ eq 'y' || $_ eq 'yes' || $_ eq 'Y' || $_ eq 'YES' );
107 $searchdirs[0] = 'src';
108 $searchdirs[1] = 'test';
113 print "Updating sources...\n";
115 while($#searchdirs >= 0) {
116 my $dir = shift @searchdirs;
117 my $mode = (stat($dir))[2] || warn "file or directory \`$dir' does not exist!";
118 my $is_directory = S_ISDIR
($mode);
122 if($dir =~ m
,^(.*)\
/([^/]*)$,) {
123 my($dir, $file) = ($1, $2);
127 handleFile
($dir, $file);
129 handleFile
(".", $dir);
135 my ($srcdir, $file) = @_;
136 return if !($file =~ /\.(c|cc|cpp|C|h|hh|hpp|H|y|yy|ypp|Y|l|ll|lpp|L|g|java)$/);
137 return if ($srcdir.'/'.$file) =~ /$excluded_paths/;
138 return if $modonly &&`svn status "$srcdir/$file" 2>/dev/null` !~ /^M
/;
139 print "$srcdir/$file...";
140 my $infile = $srcdir.'/'.$file;
141 my $outfile = $srcdir.'/#'.$file.'.tmp';
142 open(my $IN, $infile) || die "error opening $infile for reading";
143 open(my $OUT, '>', $outfile) || die "error opening $outfile for writing";
144 open(my $AUTHOR, "$dir/get-authors " . $infile . '|');
145 my $author = <$AUTHOR>; chomp $author;
146 my $major_contributors = <$AUTHOR>; chomp $major_contributors;
147 my $minor_contributors = <$AUTHOR>; chomp $minor_contributors;
150 if(m
,^(%{)?
/\
*(\
*| )\
*\
*\
*,) {
152 if($file =~ /\.(y|yy|ypp|Y)$/) {
153 print $OUT "%{/******************* */\n";
154 print $OUT "/** $file\n";
155 } elsif($file =~ /\.g$/) {
156 # avoid javadoc-style comment here; antlr complains
157 print $OUT "/* ******************* */\n";
158 print $OUT "/*! \\file $file\n";
160 print $OUT "/********************* */\n";
161 print $OUT "/*! \\file $file\n";
163 print $OUT " ** \\verbatim\n";
164 print $OUT " ** Original author: $author\n";
165 print $OUT " ** Major contributors: $major_contributors\n";
166 print $OUT " ** Minor contributors (to current version): $minor_contributors\n";
167 print $OUT $standard_template;
169 while(my $line = <$IN>) {
170 last if $line =~ /^ \*\*\s*$/;
171 if($line =~ /\*\//) {
172 print $OUT " ** [[ Add lengthier description here ]]\n";
173 print $OUT " ** \\todo document this file\n";
181 if($file =~ /\.(y|yy|ypp|Y)$/) {
182 print $OUT "%{/******************* */\n";
183 print $OUT "/*! \\file $file\n";
184 } elsif($file =~ /\.g$/) {
185 # avoid javadoc-style comment here; antlr complains
186 print $OUT "/* ******************* */\n";
187 print $OUT "/*! \\file $file\n";
189 print $OUT "/********************* */\n";
190 print $OUT "/*! \\file $file\n";
192 print $OUT " ** \\verbatim\n";
193 print $OUT " ** Original author: $author\n";
194 print $OUT " ** Major contributors: $major_contributors\n";
195 print $OUT " ** Minor contributors (to current version): $minor_contributors\n";
196 print $OUT $standard_template;
198 print $OUT " ** \\brief [[ Add one-line brief description here ]]\n";
200 print $OUT " ** [[ Add lengthier description here ]]\n";
201 print $OUT " ** \\todo document this file\n";
202 print $OUT " **/\n\n";
204 if($file =~ /\.(y|yy|ypp|Y)$/) {
205 while(my $line = <$IN>) {
207 if($line =~ '\s*%{(.*)') {
211 # just in case something's weird with the file ?
212 if(!($line =~ '\s*')) {
213 print $OUT "$line\n";
219 while(my $line = <$IN>) {
224 rename($outfile, $infile) || die "can't rename working file \`$outfile' to \`$infile'";
229 print "in dir $srcdir\n";
230 opendir(my $DIR, $srcdir);
231 while(my $file = readdir $DIR) {
232 next if !($file =~ /^[a-zA-Z]/);
234 my $mode = (stat($srcdir.'/'.$file))[2];
235 my $is_directory = S_ISDIR
($mode);
237 next if $file =~ /$excluded_directories/;
238 recurse
($srcdir.'/'.$file);
240 handleFile
($srcdir, $file);
247 ### perl-indent-level: 2