#!/usr/bin/env pike |
import Stdio; |
|
int main(int argc, string *argv) |
{ |
int i; |
string file; |
|
if(argc < 4) |
{ |
werror("Usage: rsif <from> <to> <files>\n"); |
return 1; |
} |
|
for(i = 3; i < argc; i++) |
{ |
string file_contents; |
if(file_contents = read_bytes(argv[i])) |
{ |
if(-1 != search(file_contents,argv[1])) |
{ |
write("Processing %s.\n", argv[i]); |
file_contents = replace(file_contents,argv[1],argv[2]); |
|
if( mv(argv[i], argv[i]+"~") ) |
{ |
write_file(argv[i], file_contents); |
} else { |
write("Failed to create backup file.\n"); |
} |
} |
} |
} |
|
return 0; |
}> |