4 # Morgan Deters <mdeters@cs.nyu.edu> for CVC4
5 # Copyright (c) 2009-2013 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 modified in the index or working tree
20 # are modified (i.e., those that have at least one status M in
23 # It ignores any file/directory not starting with [a-zA-Z]
24 # (so, this includes . and .., vi swaps, .git meta-info,
27 # It ignores any file not ending with one of:
28 # .c .cc .cpp .C .h .hh .hpp .H .y .yy .ypp .Y .l .ll .lpp .L .g
29 # [ or those with ".in" also suffixed, e.g., .cpp.in ]
30 # (so, this includes emacs ~-backups, CVS detritus, etc.)
32 # It ignores any directory matching $excluded_directories
33 # (so, you should add here any sources imported but not covered under
37 my $excluded_directories = '^(minisat|bvminisat|cryptominisat|CVS|generated)$';
38 my $excluded_paths = '^(src/parser/antlr_input_imports.cpp|src/bindings/compat/.*)$';
40 # Years of copyright for the template. E.g., the string
41 # "1985, 1987, 1992, 1997, 2008" or "2006-2009" or whatever.
42 my $years = '2009-2013';
44 my $standard_template = <<EOF;
45 ** This file is part of the CVC4 project.
46 ** Copyright (c) $years New York University and The University of Iowa
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 project.
53 ** Copyright (c) $years New York University and The University of Iowa
54 ** See the file COPYING in the top-level source directory for licensing
55 ** information.\\endverbatim
64 $dir =~ s
,/[^/]+/*$,,;
66 if($#ARGV >= 0 && $ARGV[0] eq '-h' || $ARGV[0] eq '--help') {
67 open(my $SELF, $0) || die "error opening $0 for reading";
76 # whether we ONLY process files with git status "M"
79 if($#ARGV >= 0 && $ARGV[0] eq '-m') {
86 (chdir($dir."/..") && -f
"src/include/cvc4_public.h") || die "can't find top-level source directory for CVC4";
87 my $pwd = `pwd`; chomp $pwd;
90 Warning: this script is dangerous. It will overwrite the header comments in your
91 source files to match the template in the script, attempting to retain file-specific
92 comments, but this isn't guaranteed. You should run this in a git working tree
93 and run "git diff" after to ensure everything was correctly rewritten.
95 The directories in which to search for and change sources is:
104 die 'aborting operation' if !( $_ eq 'y' || $_ eq 'yes' || $_ eq 'Y' || $_ eq 'YES' );
106 $searchdirs[0] = 'src';
107 $searchdirs[1] = 'examples';
108 $searchdirs[2] = '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)(\.in)?$/);
137 return if ($srcdir.'/'.$file) =~ /$excluded_paths/;
138 return if $modonly && `git status -s "$srcdir/$file" 2>/dev/null` !~ /^(M
|.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