In needing a tool to convert files between utf8 and ascii with above-ascii code points escaped \xXX or \uXXXX, I just ended up refactoring rsif a bit. We now have a shiny process_files.pike in Tools.Standalone which you can inherit, providing a process callback of your own. This is what rsif looks like now:
#! /usr/bin/env pike
inherit Tools.Standalone.process_files; string version = ("$Revision: 1.5 $"/" ")[1]; string description = "Replaces strings in files."; string usage = #"[options] <from> <to> <files>
rsif ("replace string in file") replaces all occurrences of the string <from> with the string <to> in listed files. The name of the files that were changed are written to stdout. Directories may be given instead of files, in which case all the files in that directory will be processed. Available options: " + default_flag_docs;
int want_args = 2;
string process( string input, string from, string to ) { if( has_value( input, from ) ) return replace( input, from, to ); }
Complete documentation is available in refdoc comments in the file;
http://pike.ida.liu.se/development/cvs/view.xml?module=Pike&file=7.6/lib...
As this makes writing rsif style hacks a mere pike expression or two, a logical next step would be some lazy person bringing this power kit right up to the pike command line, for instant ad-hoc directory tree processing goodness à la pike -e 'something'.
That could make rsif the equivalent of "pike -p2 'replace(arg1,arg2)'" or similar. My own side dish hack quota just ran out for the day, but feel very free to pick up the ball! (Checked in to Pike 7.6 and 7.7.)
Probably not in its current shape (throwing an exception about process not being overridden by the inheritor). Suggestions for a better place to put it? A filter in the master implementing -x is of course another possibility.
I felt it was better left for discussion than rushing into heaps of additional design decisions at five am.
Not a bad idea; I'll get to it tomorrow unless somebody does today.
Consensus on reverting the change from 7.6, by the way? The bugfix to rsif could fairly eaily be worked into the old looks of the code too, if so preferred.
Fair enough, but try to avoid refactoring 150 lines for small bugs in 7.6 unless it can't be solved some other way. Refactoring goes in 7.7.
pike-devel@lists.lysator.liu.se