06983f1996-09-22Fredrik Hübinette (Hubbe) #!/usr/local/bin/pike
5267b71995-08-09Fredrik Hübinette (Hubbe) 
06983f1996-09-22Fredrik Hübinette (Hubbe) #include <simulate.h>
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;
cb22561995-10-11Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(argc<4) {
936d2b1996-03-02Fredrik Hübinette (Hubbe)  perror("Usage: rsif <from> <to> <files>\n"); return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
936d2b1996-03-02Fredrik Hübinette (Hubbe)  for(i=3; i<argc; i++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
06983f1996-09-22Fredrik Hübinette (Hubbe)  string file_contents;
9d66451996-03-31Fredrik Hübinette (Hubbe)  if(file_contents=read_bytes(argv[i]))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
06983f1996-09-22Fredrik Hübinette (Hubbe)  if(-1!=strstr(file_contents,argv[1]))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
cb22561995-10-11Fredrik Hübinette (Hubbe)  write("Processing "+argv[i]+".\n");
9d66451996-03-31Fredrik Hübinette (Hubbe)  file_contents=replace(file_contents,argv[1],argv[2]);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
cb22561995-10-11Fredrik Hübinette (Hubbe)  if( mv(argv[i],argv[i]+"~") )
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
9d66451996-03-31Fredrik Hübinette (Hubbe)  write_file(argv[i],file_contents);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{ write("Failed to create backup file.\n"); } } } }
936d2b1996-03-02Fredrik Hübinette (Hubbe)  return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe) }>