d1f8ac4ad5
screwing up SVN This commit was SVN r6318.
63 строки
1.7 KiB
Perl
Исполняемый файл
63 строки
1.7 KiB
Perl
Исполняемый файл
#!/usr/bin/perl
|
|
#
|
|
# 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.
|
|
# 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 {
|
|
# don't process directories, and dont' recurse down
|
|
# "special" directories
|
|
if ( -d $_ ) {
|
|
if ((/\.svn/) || (/\.deps/) || (/\.libs/)) {
|
|
$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";
|
|
|
|
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>) {
|
|
s/$search_string/$replace_string/g;
|
|
print OUTFILE $_;
|
|
}
|
|
|
|
close(OUTFILE);
|
|
close(INFILE);
|
|
|
|
rename($process_file . ".tmp", $process_file);
|
|
}
|
|
find(\&replace, ".");
|