cgal/Maintenance/public_release/make_public_header

234 lines
6.2 KiB
Plaintext
Executable File

#!/sw/bin/perl5 -w
#----------------------------------------------------------------#
# This script updates a file with a valid internal header to
# a file with a public header.
# It does the following things:
# it adds a release number and date
# it removes email addresses from authors
# it adds the public license
#----------------------------------------------------------------#
use strict;
#use Cwd;
use File::Copy;
#use File::Basename;
#use File::Find;
use Getopt::Std;
sub usage()
{
print STDERR<<"EOF";
usage:
$0 -h
show this message and quit
$0 -v version [-d date] file1 ...
$0 -v version [-d date] -f filenames_file
-v version of the release (compulsory)
-d date of the release (default: today)
The filenames may either be given on the command line
or may be listed in a file, one name per line.
EOF
}
sub gjmove($$)
{
return 1 if rename($_[0], $_[1] );
return (system('mv', "$_[0]", "$_[1]") == 0);
}
#----------------------------------------------------------------#
# initialization #
#----------------------------------------------------------------#
my $TEMPFILE;
sub print_license()
{
print TEMPFILE <<'END_OF_LICENSE';
// This software and related documentation is part of the Computational
// Geometry Algorithms Library (CGAL).
// This software and documentation is provided "as-is" and without warranty
// of any kind. In no event shall the CGAL Consortium be liable for any
// damage of any kind.
//
// Every use of CGAL requires a license.
//
// Academic research and teaching license
// - For academic research and teaching purposes, permission to use and copy
// the software and its documentation is hereby granted free of charge,
// provided that it is not a component of a commercial product, and this
// notice appears in all copies of the software and related documentation.
//
// Commercial licenses
// - A commercial license is available through Algorithmic Solutions, who also
// markets LEDA (http://www.algorithmic-solutions.de).
// - Commercial users may apply for an evaluation license by writing to
// Algorithmic Solutions (contact@algorithmic-solutions.com).
//
// The CGAL Consortium consists of Utrecht University (The Netherlands),
// ETH Zurich (Switzerland), Free University of Berlin (Germany),
// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
// and Tel-Aviv University (Israel).
//
END_OF_LICENSE
}
#----------------------------------------------------------------#
# check_and_update_2 #
#----------------------------------------------------------------#
sub check_and_update_2($$$)
{
my ($version, $date, $filename) = @_;
my $warnings = 0;
my $header_position = 1;
# 1:before header; 2: in first part; 3: in second part 4: after header.
while ( <SOURCE_FILE> ) {
print TEMPFILE $_;
if ( m|^\s*//\s*={10,}\s*$| ) {
$header_position = 2;
last;
}
}
if ($header_position != 2) {
print FILE_CHECKS "$filename has no header.\n";
return 0;
}
print TEMPFILE "//\n";
$_ = <SOURCE_FILE>;
$_ = <SOURCE_FILE> while (m|^\s*//\s*$|);
if ($_ !~ m<^\s*//\s*Copyright\s*\(c\)\s*\d{4}(,\s?\d{4})*\s+(t|T)he CGAL Consortium\s*$> ) {
print FILE_CHECKS "$filename has no valid copyright notice.\n";
return 0;
}
print TEMPFILE $_;
print_license;
while ( <SOURCE_FILE> ) {
if (m|^\s*//\s*-{10,}\s*$|) {
$header_position = 3;
last;
}
}
if ($header_position != 3) {
print FILE_CHECKS "$filename has an incorrect header.\n";
print FILE_CHECKS "The line with dashes (----) is missing.\n";
return 0;
}
print TEMPFILE "// ", '-' x 70,"\n";
while ( <SOURCE_FILE> ) {
if ( m|^\s*//\s*={10,}\s*$| ) {
$header_position = 4;
last;
}
if ( m<^\s*//\s*maintainer\s*:> ) {
next;
}
if ( m<^\s*//\s*email\s*:> ) {
next;
}
next if ($_ !~ m|^\s*//| );
if ( m<^\s*//\s*release\s*:> ) {
print TEMPFILE "// release : $version\n";
next;
}
if ( m<^\s*//\s*release_date\s*:> ) {
print TEMPFILE "// release_date : $date\n";
next;
}
s/([\w]+)\s*<[-\w\.\s]+\@{1,2}[-\w\.\s]+>/$1/g;
s/([\w]+)\s*\([-\w\.\s]+\@{1,2}[-\w\.\s]+\)/$1/g;
s/([\w]+)\@{1,2}[-\w\.]+/$1/g;
if ( m/\@/) {
print FILE_CHECKS "In $filename remains a @ sign.\n ";
print FILE_CHECKS $_;
}
print TEMPFILE $_;
}
if ($header_position != 4) {
print FILE_CHECKS "Header of $filename does not end.\n";
return 0;
}
print TEMPFILE '// email : contact@cgal.org',"\n";
print TEMPFILE '// www : http://www.cgal.org',"\n//\n";
print TEMPFILE "// ", '=' x 70,"\n";
my ($lines_exceeding_length, $has_line_directives) = (0, 0);
while ( <SOURCE_FILE> ) {
print TEMPFILE $_;
}
return 2;
}
sub check_and_update_file($$$)
{
my ($filename, $version, $date) = @_;
my $check_status;
if (! -r $filename) {
print FILE_CHECKS "$filename is not a readable file.\n";
return;
}
open SOURCE_FILE, "<$filename" || die "Error opening $filename: $!\n";
open TEMPFILE, ">$TEMPFILE" || die;
$check_status =check_and_update_2($version, $date, $filename);
close SOURCE_FILE || die "Error closing $filename: $!";
close TEMPFILE || die "Error closing temporary file: $!\n";
if ($check_status == 0) {
print FILE_CHECKS "Header check failed for $filename.\n";
} else {
gjmove($TEMPFILE, $filename )
|| warn "Could not update file $filename\n";
}
}
sub main()
{
umask(002);
getopts('hv:d:f:');
if ($::opt_h ) {
usage;
return;
}
$::opt_h = 0;
if (!$::opt_v) {
usage;
die "Error: no -v option present.\n";
}
$TEMPFILE="tmp.$$";
if ( ! $::opt_d ) {
$::opt_d = `date '+%Y, %B %d'`;
chomp $::opt_d;
}
open FILE_CHECKS, ">-";
my $filename;
if ( $::opt_f ) {
open FILENAMES, "$::opt_f";
while (defined($filename=<FILENAMES>)) {
chomp $filename;
check_and_update_file($filename, $::opt_v, $::opt_d);
}
close FILENAMES;
} else {
foreach $filename (@ARGV) {
check_and_update_file($filename, $::opt_v, $::opt_d);
}
}
close FILE_CHECKS;
}
main;