pike.git / bin / rsif

version» Context lines:

pike.git/bin/rsif:1:   #! /usr/local/bin/pike - // -*- pike -*- $Id: rsif,v 1.4 2002/04/06 21:45:46 jhs Exp $ + // -*- pike -*- $Id: rsif,v 1.5 2002/04/06 21:54:42 jhs Exp $    - string version = ("$Revision: 1.4 $"/" ")[1]; + string version = ("$Revision: 1.5 $"/" ")[1];   int verbosity = 1; // interactive   int overwrite = 1; // no backups      void usage(function|void output_fun)   {    if(!output_fun)    output_fun = write;    output_fun(#"rsif [options] <from> <to> <files>      rsif (\"replace string in file\") replaces all occurrences of the string
pike.git/bin/rsif:52:    {    if(verbosity > 1)    werror("Processing stdin.\n");    write(replace(file, argv[1], argv[2]));    } else    write(file);    }    return 0;    }    -  int failures = 0; +  int failures, mode;    if(verbosity > 1)    werror("Replaced strings in these files:\n");    foreach(argv[3..], string filename)    {    if(file = Stdio.read_file(filename))    {    if(has_value(file, argv[1]))    {    if(verbosity > 0)    write("%s\n", filename);    file = replace(file, argv[1], argv[2]); -  +  mode = file_stat(filename)->mode;    if(overwrite || mv(filename, filename + "~")) -  failures += !Stdio.write_file(filename, file); +  failures += !Stdio.write_file(filename, file, mode);    else    {    werror("Failed to create backup file.\n");    failures++;    }    }    }    }    return failures;   }