3 # This script goes through a source directory rewriting the top bits of
4 # source files to match a template (inline, below). For files with no
5 # top comment, it adds a fresh one.
7 # usage: contrib/update-copyright.pl [dirs...]
8 # if dirs... are unspecified, the script scans its own parent directory's
9 # "src" directory. Since it lives in contrib/ in the CVC4 source tree,
10 # that means src/ in the CVC4 source tree.
12 # It ignores any file/directory not starting with [a-zA-Z]
13 # (so, this includes . and .., vi swaps, .svn meta-info,
16 # It ignores any file not ending with one of:
17 # .c .cc .cpp .C .h .hh .hpp .H .y .yy .ypp .Y .l .ll .lpp .L
18 # (so, this includes emacs ~-backups, CVS detritus, etc.)
20 # It ignores any directory matching $excluded_directories
21 # (so, you should add here any sources imported but not covered under
24 my $excluded_directories = '^(minisat|CVS)$';
26 # Years of copyright for the template. E.g., the string
27 # "1985, 1987, 1992, 1997, 2008" or "2006-2009" or whatever.
30 my $standard_template = <<EOF;
31 ** This file is part of the CVC4 prototype.
32 ** Copyright (c) $years The Analysis of Computer Systems Group (ACSys)
33 ** Courant Institute of Mathematical Sciences
34 ** New York University
35 ** See the file COPYING in the top-level source directory for licensing
39 my $public_template = <<EOF;
40 ** This file is part of the CVC4 prototype.
41 ** Copyright (c) $years The Analysis of Computer Systems Group (ACSys)
42 ** Courant Institute of Mathematical Sciences
43 ** New York University
44 ** See the file COPYING in the top-level source directory for licensing
56 $dir =~ s
,/[^/]+/*$,,;
58 (chdir($dir."/..") && -f
"src/include/cvc4_expr.h") || die "can't find top-level source directory for CVC4";
59 my $pwd = `pwd`; chomp $pwd;
62 Warning: this script is dangerous. It will overwrite the header comments in your
63 source files to match the template in the script, attempting to retain file-specific
64 comments, but this isn't guaranteed. You should run this in an svn working directory
65 and run "svn diff" after to ensure everything was correctly rewritten.
67 The directories in which to search for and change sources is:
75 die 'aborting operation' if !( $_ eq 'y' || $_ eq 'yes' || $_ eq 'Y' || $_ eq 'YES' );
77 $searchdirs[0] = 'src';
78 $searchdirs[1] = 'test';
83 print "Updating sources...\n";
85 recurse
(shift @searchdirs) while $#searchdirs >= 0;
89 print "in dir $srcdir\n";
90 opendir(my $DIR, $srcdir);
91 while(my $file = readdir $DIR) {
92 next if !($file =~ /^[a-zA-Z]/);
94 my $mode = (stat($srcdir.'/'.$file))[2];
95 my $is_directory = S_ISDIR
($mode);
97 next if $file =~ /$excluded_directories/;
98 recurse
($srcdir.'/'.$file);
100 next if !($file =~ /\.(c|cc|cpp|C|h|hh|hpp|H|y|yy|ypp|Y|l|ll|lpp|L)$/);
101 print "$srcdir/$file...";
102 my $infile = $srcdir.'/'.$file;
103 my $outfile = $srcdir.'/#'.$file.'.tmp';
104 open(my $IN, $infile) || die "error opening $infile for reading";
105 open(my $OUT, '>', $outfile) || die "error opening $outfile for writing";
107 if(m
,^(%{)?
/\
*\
*\
*\
*\
*,) {
109 if($file =~ /\.(y|yy|ypp|Y)$/) {
110 print $OUT "%{/******************* -*- C++ -*- */\n";
112 print $OUT "/********************* -*- C++ -*- */\n";
114 print $OUT "/** $file\n";
115 print $OUT $standard_template;
117 while(my $line = <$IN>) {
118 last if $line =~ /^ \*\*\s*$/;
123 if($file =~ /\.(y|yy|ypp|Y)$/) {
124 print $OUT "%{/******************* -*- C++ -*- */\n";
126 print $OUT "/********************* -*- C++ -*- */\n";
128 print $OUT "/** $file\n";
129 print $OUT $standard_template;
131 print $OUT " ** [[ Add file-specific comments here ]]\n";
132 print $OUT " **/\n\n";
134 if($file =~ /\.(y|yy|ypp|Y)$/) {
135 while(my $line = <$IN>) {
137 if($line =~ '\s*%{(.*)') {
141 # just in case something's weird with the file ?
142 if(!($line =~ '\s*')) {
143 print $OUT "$line\n";
149 while(my $line = <$IN>) {
154 rename($outfile, $infile) || die "can't rename working file \`$outfile' to \`$infile'";
161 ### perl-indent-level: 2