From 34916d10d815c8d07f5a57716ab24de61b26abf7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 10 Dec 2022 19:42:18 +0100 Subject: [PATCH] bin/shell-replace --- bin/shell-replace | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bin/shell-replace b/bin/shell-replace index c2a76a69..3c78cfb2 100755 --- a/bin/shell-replace +++ b/bin/shell-replace @@ -40,6 +40,7 @@ $main::_DATA_ = undef; # ################################################################################# 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}; @@ -72,18 +73,22 @@ my $file; 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); } ################################################################################# @@ -100,9 +105,11 @@ exit 0; ################################################################################# 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$/) { @@ -126,7 +133,7 @@ sub wanted { next unless /^.{1,3}Found: $file\n"); + verbose(1,"Found: $file\n"); push @WANTED_FILES, $file; last; } @@ -134,6 +141,7 @@ sub wanted { } sub shell_replace { +# Search tags and execute command, return new lines my $ident; my $i; my $change; -- 2.47.3