#
#################################################################################
use Data::Dumper;
+use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END);
use File::Find;
if (!@ARGV and !-t STDIN) {
die "$NAME: option require file/path as arguments!\n" if $Opt{find};
for $file (@ARGV) {
if ($file eq "-") {
- $hfile = <>;
- $hfile = \*ARGV;
+ #$hfile = \*ARGV;
+ $hfile = \*STDIN;
} else {
next if myself($file);
open($hfile,"<",$file);
}
+ my @original = <$hfile>;
+ seek($hfile,0,SEEK_SET);
- verbose(1,">Processing: $file\n");
+ verbose(1,"Processing: $file\n");
my @lines = &shell_replace($hfile);
print map { $_ } @lines;
+
close $hfile;
+ verbose(1,"Changed: $file\n") if join('',@original) ne join('',@lines);
}
#################################################################################
#################################################################################
sub verbose {
my $level = shift @_;
- return 0 if $VERBOSE <= $level;
+ return 0 if $VERBOSE < $level;
print STDERR join(" ",@_)."\n";
+ return 1;
}
+
sub myself {
my $file = shift @_;
if ($file eq $0 or $file =~ /(^|\/)$NAME$/) {
next unless /^.{1,3}<SHELL_REPLACE/;
- verbose(1,">Found: $file\n");
+ verbose(1,"Found: $file\n");
push @WANTED_FILES, $file;
last;
}
}
sub shell_replace {
+# Search tags and execute command, return new lines
my $ident;
my $i;
my $change;