1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#!/usr/bin/perl
#
# 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.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
if (scalar(@ARGV) != 1) {
print "Usage:
fix_headers.pl <header_file_list>\n";
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");
|