#!/usr/bin/perl -w -W use Cwd; use strict; my $TMPDIR; my $version = ""; my $final_version; my $original_arguments=join(" ", @ARGV); sub usage { print STDERR "$0: usage\n"; print STDERR "$0 [-v version] result1.tar[.gz] ...\n"; print STDERR "$0: you called it with the arguments:\n"; print STDERR "$0 $original_arguments\n"; } sub make_tempdir() { my $dirno = 1; $TMPDIR = "TMP$dirno"; while ( -f $TMPDIR or -d $TMPDIR ) { ++$dirno; $TMPDIR = "TMP$dirno"; } mkdir($TMPDIR,0770) or die "Cannot create temporary directory $TMPDIR\n"; } sub reformat_results($) { $_ = shift; s/\.tar//; my $platform = $_; # system("dos2unix ${platform}.txt ${platform}.txt"); open (PLATFORM_RESULTS,"<${platform}.txt") or return; while (/^\s*$/) { $_= ; } open (PLATFORM_INFO,">${platform}.info") or return; open (PLATFORM_NEW_RESULTS,">${platform}.new_results") or return; my ($CGAL_VERSION,$LEDA_VERSION,$TESTER,$TESTER_NAME,$TESTER_ADDRESS,$GMP,$GMPXX,$CORE,$QT) = ("-","-","-","-","-","-","-","-","-"); while (! /^------/) { if (/^CGAL_VERSION\s+([\w\.-]+)/) { $CGAL_VERSION = $1; } if (/^LEDA\s+version\s+([\w\.-]+)/) { $LEDA_VERSION = $1; } if (/^TESTER\s+([\w\.-]+)/) { $TESTER = $1; } if (/^TESTER_NAME\s+(.*)$/) { $TESTER_NAME = $1; } if (/^TESTER_ADDRESS\s+(.*)$/) { $TESTER_ADDRESS = $1; } if (/GMP_SUPPORT\s*=\s*\'_GMP\'/) { $GMP="+"; } if (/GMPXX_SUPPORT\s*=\s*\'_GMPXX\'/) { $GMPXX="+"; } if (/CORE_SUPPORT\s*=\s*\'_CORE\'/) { $CORE="+"; } if (/QT_SUPPORT\s*=\s*\'_QT\'/) { $QT="+"; } if (/LEDA_SUPPORT\s*=\s*\'_LEDA\'/ && $LEDA_VERSION eq "-") { $LEDA_VERSION="+"; } $_= ; } while () { print PLATFORM_NEW_RESULTS $_; } rename("${platform}.new_results","${platform}.txt") or die "cannot rename!"; print PLATFORM_INFO <<"EOF"; $CGAL_VERSION $TESTER $TESTER_NAME $TESTER_ADDRESS $LEDA_VERSION $GMP $GMPXX $CORE $QT EOF close(PLATFORM_INFO); close(PLATFORM_RESULTS); close(PLATFORM_NEW_RESULTS); $final_version="CGAL-$CGAL_VERSION"; if ($version && $version ne "CGAL-$CGAL_VERSION" && ($version !~ /^CGAL-${CGAL_VERSION}-I-[\d]+$/)) { die "Wrong version in $platform: $CGAL_VERSION instead of $version.\n"; } } sub one_archive($) { my $archive = shift; if (! -f $archive) { print STDERR "$archive is not a valid filename\n"; return 0; } if ( $archive =~ m/\.gz$/ ) { system("gunzip", "$archive") == 0 or return 0; $archive =~ s/\.gz$//; } if ( $archive =~ m/.*\.tgz$/ ) { system("gunzip", "$archive") == 0 or return 0; $archive =~ s/\.tgz$/.tar/; } if ( $archive !~ /\.tar$/) { print STDERR "$0: $archive not a tar file\n"; return 0; } make_tempdir(); rename("$archive","$TMPDIR/$archive") or die "cannot rename"; chdir("$TMPDIR") or die "cannot chdir"; system("gtar", "xf", "$archive") == 0 or die "cannot gtar"; unlink($archive); reformat_results($archive); system('gzip',glob("*/*")) == 0 or die "cannot gzip"; system('chmod','-R','a+r,og+w','.') == 0 or die "cannot chmod"; system('tar', 'cf', "../$archive", glob("*")) == 0 or die; chdir('..') or die; system('rm', '-rf', "$TMPDIR")== 0 or die; return 1; } sub all_archives() { my $archive; foreach $archive (@ARGV) { if (one_archive($archive)) { open (TESTRESULTSLOG, ">>../test_results.log") or die "Could not open test_results.log\n"; my $date=`date`; chop $date; print TESTRESULTSLOG "$final_version : $archive succesfully reformatted. [ $date ]\n"; close (TESTRESULTSLOG); } else { print STDERR "$final_version : Could not reformat $archive\n"; } } } if ($#ARGV < 0) { usage; exit 1; } if ($ARGV[0] eq "-v") { shift; $version = shift; } if ($#ARGV < 0) { usage; exit 1; } all_archives(); exit 0;