2004-11-22 04:52:53 +03:00
#!/usr/bin/env perl
#
2005-11-05 22:57:48 +03:00
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
2004-11-28 23:09:25 +03:00
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
2005-03-24 15:43:37 +03:00
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
2004-11-22 04:52:53 +03:00
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Utility to stamp copyrights into files. This is only being checked
# into SVN because we have LANL and HLRS copyrights pending, and this
# script will be helpful in adding them to the tree (I'm sure the
# script will need to be modified, but it's got all the relevant
# File::Find code, etc.).
use strict ;
use File::Find ;
use Cwd ;
my $ verbose = 0 ;
my % files_found ;
my @ skip_dirs = ( "doxygen" , ".svn" , ".deps" , ".libs" , "libltdl" , "autom4te.cache" ) ;
2005-11-05 22:57:48 +03:00
my $ iu = " Copyright ( c ) 2004 - 2005 The Trustees of Indiana University and Indiana
University Research and Technology
Corporation . All rights reserved . " ;
my $ utk = " Copyright ( c ) 2004 - 2005 The University of Tennessee and The University
of Tennessee Research Foundation . All rights
reserved . " ;
2004-11-22 04:52:53 +03:00
my $ osu = " Copyright ( c ) 2004 The Ohio State University
All rights reserved . " ;
2004-11-28 23:09:25 +03:00
my $ hlrs = " Copyright ( c ) 2004 - 2005 High Performance Computing Center Stuttgart ,
University of Stuttgart . All rights reserved . " ;
2005-03-24 15:43:37 +03:00
my $ uc = " Copyright ( c ) 2004 - 2005 The Regents of the University of California .
All rights reserved . " ;
2004-11-28 23:09:25 +03:00
2005-03-24 15:43:37 +03:00
my $ copy = "$uc\n\$COPYRIGHT\$" ;
2004-11-22 04:52:53 +03:00
sub wanted {
# Setup
my $ file = $ _ ;
my @ dirnames = split ( '/' , $ File:: Find:: dir ) ;
my $ dir = $ dirnames [ $# dirnames ] ;
# Is the file a dir?
my $ is_dir = ( - d $ file ) ;
# Do we want this dir?
for ( my $ i = 0 ; $ i <= $# skip_dirs ; + + $ i ) {
if ( $ skip_dirs [ $ i ] eq $ dir ||
( $ is_dir && $ skip_dirs [ $ i ] eq $ file ) ) {
print ( "Skipping dir: $File::Find::dir / $file\n" )
if ( $ verbose ) ;
$ File:: Find:: prune = 1 ;
return 0 ;
}
}
# Do we want this file?
if ( $ is_dir ) {
print ( "Found dir: $File::Find::dir/$file\n" )
if ( $ verbose ) ;
} else {
$ files_found { $ File:: Find:: name } = 1 ;
print ( "Found file: $File::Find::name\n" )
if ( $ verbose ) ;
}
1 ;
}
2005-11-05 23:23:33 +03:00
find ( \ & wanted , "." ) ;
my $ counts ;
my $ max_count = - 1 ;
foreach my $ file ( sort keys % files_found ) {
open FILE , $ file ;
my @ found = grep ( /\$COPYRIGHT\$/ , <FILE> ) ;
close ( FILE ) ;
if ( $# found >= 0 ) {
print "Found file: $file\n" ;
# Added to fix IU/UTK copyrights, 5/Nov/2005
if ( 1 ) {
fix_iu_utk_copyright ( $ file ) ;
} else {
add_copyright ( $ file ) ;
}
}
}
2005-11-05 22:57:48 +03:00
2005-11-05 23:23:33 +03:00
#---------------------------------------------------------------------------
2005-11-05 22:57:48 +03:00
my $ new_iu1 = "Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana" ;
my $ new_iu2 = "University Research and Technology" ;
my $ new_iu3 = "Corporation. All rights reserved." ;
my $ new_utk1 = "Copyright (c) 2004-2005 The University of Tennessee and The University" ;
my $ new_utk2 = "of Tennessee Research Foundation. All rights" ;
my $ new_utk3 = "reserved." ;
2005-11-05 23:23:33 +03:00
sub fix_iu_utk_copyright {
my ( $ file ) = @ _ ;
2005-11-05 22:57:48 +03:00
2005-11-05 23:23:33 +03:00
open FILE , $ file ;
my @ lines = <FILE> ;
close FILE ;
2005-11-05 22:57:48 +03:00
2005-11-05 23:23:33 +03:00
my $ text = join ( '' , @ lines ) ;
$ text =~ s/([ \*\!\#\%\/dnl]*)Copyright \(c\) 2004-2005 The Trustees of Indiana University\.\n([ \*\!\#\%\/dnl]*)All rights reserved\.\n/$1$new_iu1\n$2$new_iu2\n$2$new_iu3\n/ ;
$ text =~ s/([ \*\!\#\%\/dnl]*)Copyright \(c\) 2004-2005 The Trustees of the University of Tennessee\.\n([ \*\!\#\%\/dnl]*)All rights reserved\.\n/$1$new_utk1\n$2$new_utk2\n$2$new_utk3\n/ ;
open FILENEW , ">$file.new" || die "could not open $file.new\n" ;
print FILENEW $ text ;
close FILENEW ;
2005-11-05 22:57:48 +03:00
2005-11-05 23:23:33 +03:00
system ( "cp $file.new $file" ) ;
unlink ( "$file.new" ) ;
}
#---------------------------------------------------------------------------
sub add_copyright {
my ( $ file ) = @ _ ;
open FILE , $ file ;
while ( <FILE> ) {
chomp ;
my $ line = $ _ ;
if ( $ line =~ /\$COPYRIGHT\$/ ) {
my $ prefix = $ line ;
$ prefix =~ s/(.+)\$COPYRIGHT\$.*$/\1/ ;
if ( $ prefix ne "\$COPYRIGHT\$" ) {
my $ c = $ prefix . $ copy ;
$ c =~ s/\n/\n$prefix/g ;
print FILENEW "$c\n" ;
2004-11-22 04:52:53 +03:00
} else {
2005-11-05 23:23:33 +03:00
print FILENEW "$copy\n" ;
2004-11-22 04:52:53 +03:00
}
2005-11-05 23:23:33 +03:00
} else {
print FILENEW "$line\n" ;
2004-11-22 04:52:53 +03:00
}
2005-11-05 22:57:48 +03:00
}
2005-11-05 23:23:33 +03:00
close ( FILENEW ) ;
close ( FILE ) ;
system ( "cp $file.new $file" ) ;
unlink ( "$file.new" ) ;
2004-11-22 04:52:53 +03:00
}