2004-10-06 03:52:35 +04:00
|
|
|
#!/usr/bin/perl
|
2004-11-22 03:37:56 +03:00
|
|
|
#
|
2004-11-22 04:38:40 +03:00
|
|
|
# Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
# All rights reserved.
|
|
|
|
# Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
# 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.
|
2004-11-22 04:38:40 +03:00
|
|
|
# $COPYRIGHT$
|
|
|
|
#
|
|
|
|
# Additional copyrights may follow
|
|
|
|
#
|
2004-11-22 03:37:56 +03:00
|
|
|
# $HEADER$
|
|
|
|
#
|
2004-10-06 03:52:35 +04:00
|
|
|
|
|
|
|
if (scalar(@ARGV) != 1) {
|
|
|
|
print "Usage:
|
2004-10-06 03:55:57 +04:00
|
|
|
fix_headers.pl <header_file_list>\n";
|
2004-10-06 03:52:35 +04:00
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
$header_file = @ARGV[0];
|
|
|
|
$temp_file = "/tmp/temp.c";
|
|
|
|
|
|
|
|
open(HEADERS, "$header_file") || print "Could not open $header_file\n";
|
|
|
|
open(MOD_FILES, "> modified_files.txt") || print "Could not open modified.txt\n";
|
|
|
|
|
|
|
|
while (<HEADERS>) {
|
|
|
|
|
|
|
|
#open all the c files
|
|
|
|
#check if this header is present
|
|
|
|
#if it is present, then substitute it with the protection
|
|
|
|
|
|
|
|
|
|
|
|
$header_string = $_;
|
|
|
|
chomp($header_string);
|
|
|
|
$protection = $_;
|
|
|
|
$protection =~ s/\./_/;
|
|
|
|
$protection =~ s/\//_/;
|
|
|
|
$protection =~ s/#include//;
|
|
|
|
$protection =~ tr/a-z/A-z/;
|
|
|
|
$protection =~ s/\s<//;
|
|
|
|
$protection =~ s/>//;
|
|
|
|
$protection = "HAVE_" . $protection;
|
|
|
|
|
|
|
|
print $protection;
|
|
|
|
|
|
|
|
$string_to_replace = "#ifdef $protection$_#endif\n";
|
|
|
|
|
|
|
|
print $string_to_replace;
|
|
|
|
|
|
|
|
open(C_FILES, "find . -name *.c |") || print "find failed\n";
|
|
|
|
while (<C_FILES>) {
|
|
|
|
$c_file = $_;
|
|
|
|
if (not /mca/) {
|
|
|
|
open(C_FILE, "$c_file") || print "Open failed on $c_file\n";
|
|
|
|
chomp($protection);
|
|
|
|
|
|
|
|
#ensure that this protection has not been already put in place
|
|
|
|
$protected = 0;
|
|
|
|
$written_to_file = 0;
|
|
|
|
|
|
|
|
while (<C_FILE>) {
|
|
|
|
if (/$protection/) {
|
|
|
|
$protected = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (C_FILE);
|
|
|
|
if ($protected == 0) {
|
|
|
|
#this file is not yet protected
|
|
|
|
open(C_FILE, "$c_file") || print "Open failed on $c_file\n";
|
|
|
|
open(TEMP, "> $temp_file") || print "Open failed on temp.c \n";
|
|
|
|
|
|
|
|
while (<C_FILE>) {
|
|
|
|
if (/$header_string/) {
|
|
|
|
print TEMP $string_to_replace;
|
|
|
|
print "Replacing defintion ---- $c_file";
|
|
|
|
if ($written_to_file == 0) {
|
|
|
|
print MOD_FILES $c_file;
|
|
|
|
$written_to_file = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print TEMP $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (TEMP_C);
|
|
|
|
system("cp $temp_file $c_file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (C_FILES);
|
|
|
|
|
|
|
|
#Now to do the same for header files
|
|
|
|
open(H_FILES, "find . -name *.h |") || print "find failed\n";
|
|
|
|
while (<H_FILES>) {
|
|
|
|
|
|
|
|
$h_file = $_;
|
|
|
|
if (not /mca/) {
|
|
|
|
open(H_FILE, "$h_file") || print "Open failed on $h_file\n";
|
|
|
|
chomp($protection);
|
|
|
|
|
|
|
|
#ensure that this protection has not been already put in place
|
|
|
|
$protected = 0;
|
|
|
|
$written_to_file = 0;
|
|
|
|
|
|
|
|
while (<H_FILE>) {
|
|
|
|
if (/$protection/) {
|
|
|
|
$protected = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (H_FILE);
|
|
|
|
if ($protected == 0) {
|
|
|
|
#this file is not yet protected
|
|
|
|
open(H_FILE, "$h_file") || print "Open failed on $h_file\n";
|
|
|
|
open(TEMP, "> $temp_file") || print "Open failed on temp.c \n";
|
|
|
|
|
|
|
|
while (<H_FILE>) {
|
|
|
|
if (/$header_string/) {
|
|
|
|
print TEMP $string_to_replace;
|
|
|
|
print "Replacing defintion ---- $h_file";
|
|
|
|
if ($written_to_file == 0) {
|
|
|
|
print MOD_FILES $h_file;
|
|
|
|
$written_to_file = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print TEMP $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (TEMP_C);
|
|
|
|
system("cp $temp_file $h_file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (H_FILES);
|
|
|
|
}
|
|
|
|
close(HEADERS);
|
|
|
|
close(MOD_FILES);
|
|
|
|
system("rm -f $temp_file");
|