get-authors: Exclude common source code patterns. (#2900)
[cvc5.git] / contrib / update-copyright.pl
index 7ad839b1d27a9107f990d8d35b6ced786ffd7eca..3412905af99c785e93cf3dc7d606361318b2d8a0 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/perl -w
 #
 # update-copyright.pl
-# Morgan Deters <mdeters@cs.nyu.edu> for CVC4
-# Copyright (c) 2009, 2010, 2011  The CVC4 Project
+# Copyright (c) 2009-2018  The CVC4 Project
 #
 # usage: update-copyright [-m] [files/directories...]
 #        update-copyright [-h | --help]
 # the CVC4 source tree, that means src/ in the CVC4 source tree.
 #
 # If -m is specified as the first argument, all files and directories
-# are scanned, but only ones modifed in the current working directory
-# are modified (i.e., those that have status M in "svn status").
+# are scanned, but only ones modified in the index or working tree
+# are modified (i.e., those that have at least one status M in
+# "git status -s").
 #
 # It ignores any file/directory not starting with [a-zA-Z]
-# (so, this includes . and .., vi swaps, .svn meta-info,
+# (so, this includes . and .., vi swaps, .git meta-info,
 # .deps, etc.)
 #
 # It ignores any file not ending with one of:
 #   .c .cc .cpp .C .h .hh .hpp .H .y .yy .ypp .Y .l .ll .lpp .L .g
+#   [ or those with ".in" also suffixed, e.g., .cpp.in ]
 # (so, this includes emacs ~-backups, CVS detritus, etc.)
 #
 # It ignores any directory matching $excluded_directories
 # the license.)
 #
 
-my $excluded_directories = '^(minisat|CVS|generated)$';
-my $excluded_paths = '^(src/parser/antlr_input_imports.cpp|src/bindings/compat/.*)$';
+my $excluded_directories = '^(CVS|generated)$';
+my $excluded_paths = '^(';
+# note: first excluded path regexp must not start with a '|'
+# different license
+$excluded_paths .= 'src/util/channel.h';
+# minisat license
+$excluded_paths .= '|src/prop/(bv)?minisat/core/.*';
+$excluded_paths .= '|src/prop/(bv)?minisat/mtl/.*';
+$excluded_paths .= '|src/prop/(bv)?minisat/simp/.*';
+$excluded_paths .= '|src/prop/(bv)?minisat/utils/.*';
+$excluded_paths .= ')$';
 
 # Years of copyright for the template.  E.g., the string
 # "1985, 1987, 1992, 1997, 2008" or "2006-2009" or whatever.
-my $years = '2009, 2010, 2011';
+my $years = '2009-2018';
 
 my $standard_template = <<EOF;
- ** This file is part of the CVC4 prototype.
- ** Copyright (c) $years  The Analysis of Computer Systems Group (ACSys)
- ** Courant Institute of Mathematical Sciences
- ** New York University
- ** See the file COPYING in the top-level source directory for licensing
- ** information.\\endverbatim
-EOF
-
-my $public_template = <<EOF;
- ** This file is part of the CVC4 prototype.
- ** Copyright (c) $years  The Analysis of Computer Systems Group (ACSys)
- ** Courant Institute of Mathematical Sciences
- ** New York University
- ** See the file COPYING in the top-level source directory for licensing
- ** information.\\endverbatim
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) $years by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\\endverbatim
 EOF
 
 ## end config ##
@@ -65,7 +65,7 @@ use Fcntl ':mode';
 my $dir = $0;
 $dir =~ s,/[^/]+/*$,,;
 
-if($#ARGV >= 0 && $ARGV[0] eq '-h' || $ARGV[0] eq '--help') {
+if($#ARGV >= 0 && ($ARGV[0] eq '-h' || $ARGV[0] eq '--help')) {
   open(my $SELF, $0) || die "error opening $0 for reading";
   while($_ = <$SELF>) {
     last if !/^#/;
@@ -75,7 +75,7 @@ if($#ARGV >= 0 && $ARGV[0] eq '-h' || $ARGV[0] eq '--help') {
   exit;
 }
 
-# whether we ONLY process files with svn status "M"
+# whether we ONLY process files with git status "M"
 my $modonly = 0;
 
 if($#ARGV >= 0 && $ARGV[0] eq '-m') {
@@ -91,11 +91,12 @@ if($#ARGV == -1) {
   print <<EOF;
 Warning: this script is dangerous.  It will overwrite the header comments in your
 source files to match the template in the script, attempting to retain file-specific
-comments, but this isn't guaranteed.  You should run this in an svn working directory
-and run "svn diff" after to ensure everything was correctly rewritten.
+comments, but this isn't guaranteed.  You should run this in a git working tree
+and run "git diff" after to ensure everything was correctly rewritten.
 
 The directories in which to search for and change sources is:
   $pwd/src
+  $pwd/examples
   $pwd/test
 
 Continue? y or n:
@@ -105,7 +106,8 @@ EOF
   die 'aborting operation' if !( $_ eq 'y' || $_ eq 'yes' || $_ eq 'Y' || $_ eq 'YES' );
 
   $searchdirs[0] = 'src';
-  $searchdirs[1] = 'test';
+  $searchdirs[1] = 'examples';
+  $searchdirs[2] = 'test';
 } else {
   @searchdirs = @ARGV;
 }
@@ -114,6 +116,7 @@ print "Updating sources...\n";
 
 while($#searchdirs >= 0) {
   my $dir = shift @searchdirs;
+  $dir =~ s,\/$,,;              # remove trailing slash from directory
   my $mode = (stat($dir))[2] || warn "file or directory \`$dir' does not exist!";
   my $is_directory = S_ISDIR($mode);
   if($is_directory) {
@@ -133,21 +136,19 @@ while($#searchdirs >= 0) {
 
 sub handleFile {
   my ($srcdir, $file) = @_;
-  return if !($file =~ /\.(c|cc|cpp|C|h|hh|hpp|H|y|yy|ypp|Y|l|ll|lpp|L|g|java)$/);
+  return if !($file =~ /\.(c|cc|cpp|C|h|hh|hpp|H|y|yy|ypp|Y|l|ll|lpp|L|g|java)(\.in)?$/);
   return if ($srcdir.'/'.$file) =~ /$excluded_paths/;
-  return if $modonly  &&`svn status "$srcdir/$file" 2>/dev/null` !~ /^M/;
+  return if $modonly && `git status -s "$srcdir/$file" 2>/dev/null` !~ /^(M|.M)/;
   print "$srcdir/$file...";
   my $infile = $srcdir.'/'.$file;
   my $outfile = $srcdir.'/#'.$file.'.tmp';
   open(my $IN, $infile) || die "error opening $infile for reading";
   open(my $OUT, '>', $outfile) || die "error opening $outfile for writing";
   open(my $AUTHOR, "$dir/get-authors " . $infile . '|');
-  my $author = <$AUTHOR>; chomp $author;
-  my $major_contributors = <$AUTHOR>; chomp $major_contributors;
-  my $minor_contributors = <$AUTHOR>; chomp $minor_contributors;
+  my $authors = <$AUTHOR>; chomp $authors;
   close $AUTHOR;
   $_ = <$IN>;
-  if(m,^(%{)?/\*(\*| )\*\*\*,) {
+  if(m,^(%\{)?/\*(\*| )\*\*\*,) {
     print "updating\n";
     if($file =~ /\.(y|yy|ypp|Y)$/) {
       print $OUT "%{/*******************                                                        */\n";
@@ -161,20 +162,27 @@ sub handleFile {
       print $OUT "/*! \\file $file\n";
     }
     print $OUT " ** \\verbatim\n";
-    print $OUT " ** Original author: $author\n";
-    print $OUT " ** Major contributors: $major_contributors\n";
-    print $OUT " ** Minor contributors (to current version): $minor_contributors\n";
-    print $OUT $standard_template;
-    print $OUT " **\n";
+    print $OUT " ** Top contributors (to current version):\n";
+    print $OUT " **   $authors\n";
+    my $comment_stub = "";
     while(my $line = <$IN>) {
+      if($line =~ /\b[Cc]opyright\b/ && $line !~ /\bby the authors listed in the file AUTHORS\b/) {
+        # someone else holds this copyright
+        print $OUT $line;
+      }
       last if $line =~ /^ \*\*\s*$/;
       if($line =~ /\*\//) {
-        print $OUT " ** [[ Add lengthier description here ]]\n";
-        print $OUT " ** \\todo document this file\n";
-        print $OUT $line;
+        $comment_stub = " ** [[ Add lengthier description here ]]\n\
+ ** \\todo document this file\n\
+$line";
         last;
       }
     }
+    print $OUT $standard_template;
+    print $OUT " **\n";
+    if($comment_stub) {
+      print $OUT $comment_stub;
+    }
   } else {
     my $line = $_;
     print "adding\n";
@@ -190,9 +198,8 @@ sub handleFile {
       print $OUT "/*! \\file $file\n";
     }
     print $OUT " ** \\verbatim\n";
-    print $OUT " ** Original author: $author\n";
-    print $OUT " ** Major contributors: $major_contributors\n";
-    print $OUT " ** Minor contributors (to current version): $minor_contributors\n";
+    print $OUT " ** Top contributors (to current version):\n";
+    print $OUT " **   $authors\n";
     print $OUT $standard_template;
     print $OUT " **\n";
     print $OUT " ** \\brief [[ Add one-line brief description here ]]\n";
@@ -204,7 +211,7 @@ sub handleFile {
     if($file =~ /\.(y|yy|ypp|Y)$/) {
       while(my $line = <$IN>) {
         chomp $line;
-        if($line =~ '\s*%{(.*)') {
+        if($line =~ '\s*%\{(.*)') {
           print $OUT "$1\n";
           last;
         }