370d542002-01-07Peter Bortas #!/usr/bin/env pike
95d0821999-03-19David Hedbor import Stdio;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
936d2b1996-03-02Fredrik Hübinette (Hubbe) int main(int argc, string *argv)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
cb22561995-10-11Fredrik Hübinette (Hubbe)  int i;
5267b71995-08-09Fredrik Hübinette (Hubbe)  string file;
95d0821999-03-19David Hedbor  if(argc < 4)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
95d0821999-03-19David Hedbor  werror("Usage: rsif <from> <to> <files>\n");
936d2b1996-03-02Fredrik Hübinette (Hubbe)  return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
95d0821999-03-19David Hedbor  for(i = 3; i < argc; i++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
06983f1996-09-22Fredrik Hübinette (Hubbe)  string file_contents;
95d0821999-03-19David Hedbor  if(file_contents = read_bytes(argv[i]))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
95d0821999-03-19David Hedbor  if(-1 != search(file_contents,argv[1]))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
95d0821999-03-19David Hedbor  write("Processing %s.\n", argv[i]); file_contents = replace(file_contents,argv[1],argv[2]);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
95d0821999-03-19David Hedbor  if( mv(argv[i], argv[i]+"~") )
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
95d0821999-03-19David Hedbor  write_file(argv[i], file_contents); } else {
5267b71995-08-09Fredrik Hübinette (Hubbe)  write("Failed to create backup file.\n"); } } } }
95d0821999-03-19David Hedbor 
936d2b1996-03-02Fredrik Hübinette (Hubbe)  return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe) }>