2005-07-03 17:31:45 +04:00
|
|
|
#!/usr/bin/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.
|
2005-07-03 17:31:45 +04:00
|
|
|
# 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$
|
|
|
|
#
|
|
|
|
|
|
|
|
use File::Find;
|
|
|
|
|
|
|
|
if (scalar(@ARGV) != 2) {
|
|
|
|
print "Usage: search_replace.pl search_string replace_string\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$search_string = @ARGV[0];
|
|
|
|
$replace_string = @ARGV[1];
|
|
|
|
|
|
|
|
print "search: $search_string\n";
|
|
|
|
print "replace: $replace_string\n";
|
|
|
|
|
|
|
|
sub replace {
|
2005-07-03 19:21:49 +04:00
|
|
|
# don't process directories or links, and dont' recurse down
|
2005-07-03 17:31:45 +04:00
|
|
|
# "special" directories
|
2005-07-03 19:21:49 +04:00
|
|
|
if ( -l $_ ) { return; }
|
2005-07-03 17:31:45 +04:00
|
|
|
if ( -d $_ ) {
|
2014-05-06 22:01:51 +04:00
|
|
|
if ((/\.svn/) || (/\.deps/) || (/\.libs/) || (/\.hg/) || (/\.git/) || (/autom4te\.cache/)) {
|
2005-07-03 17:31:45 +04:00
|
|
|
$File::Find::prune = true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# $File::Find::name is the path relative to the starting point.
|
|
|
|
# $_ contains the file's basename. The code automatically changes
|
|
|
|
# to the processed directory, so we want to open / close $_.
|
|
|
|
$process_file = $_;
|
|
|
|
print "--> $File::Find::name\n";
|
2005-07-03 18:29:16 +04:00
|
|
|
my $replace = 0;
|
2005-07-03 17:31:45 +04:00
|
|
|
|
|
|
|
open(INFILE, $process_file) ||
|
|
|
|
die "Could not open " . $File::Find::name . ": $!\n";
|
|
|
|
open(OUTFILE, "> " . $process_file . ".tmp") ||
|
|
|
|
die "Could not open " . $File::Find::name . ".tmp: $!\n";
|
|
|
|
|
|
|
|
while (<INFILE>) {
|
2005-07-03 18:29:16 +04:00
|
|
|
$replace += s/$search_string/$replace_string/g;
|
2005-07-03 17:31:45 +04:00
|
|
|
print OUTFILE $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(OUTFILE);
|
|
|
|
close(INFILE);
|
|
|
|
|
2005-07-03 18:29:16 +04:00
|
|
|
if ($replace) {
|
|
|
|
rename($process_file . ".tmp", $process_file);
|
|
|
|
} else {
|
|
|
|
unlink($process_file . ".tmp");
|
|
|
|
}
|
2005-07-03 17:31:45 +04:00
|
|
|
}
|
|
|
|
find(\&replace, ".");
|