* script to do recursive search/replace in the source tree, without
screwing up SVN This commit was SVN r6318.
Этот коммит содержится в:
родитель
35c141aef6
Коммит
d1f8ac4ad5
62
contrib/search_replace.pl
Исполняемый файл
62
contrib/search_replace.pl
Исполняемый файл
@ -0,0 +1,62 @@
|
||||
#!/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, ".");
|
Загрузка…
x
Ссылка в новой задаче
Block a user