X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=cp-update;h=ecac2f7b2ca6e5286b2a0319086a0376b7c31fe7;hb=01968242e3b13b6f0d59e35e612a824780927ab0;hp=6491c7837f4e0f2c566d11c9ba53fe40f204af8e;hpb=b6374f775ed04f3c9767d19a364ad0994a94ac4f;p=carnet-tools-cn.git diff --git a/cp-update b/cp-update index 6491c78..ecac2f7 100755 --- a/cp-update +++ b/cp-update @@ -299,8 +299,8 @@ sub add() { } ++ $lineNo; } - if (! $added) { - warn "$ProgramName: Inserting lines at the end implicitly!\n"; + if ($MatchLine and ! $added) { + warn "$ProgramName: Inserting lines at the end implicitly! No '$MatchLine'\n"; push(@Lines, $StdinContent); } } @@ -311,6 +311,8 @@ sub del() { my ($mytrailer, $mybegin, $myend) = ($Trailer, $MarkBegin, $MarkEnd); + my ($bm_found, $em_found); # begin/end mark found indicator + # Make the strings regexp-friendly by quoting non-word chars. $mybegin =~ s/\W/\\$&/g; $myend =~ s/\W/\\$&/g; @@ -320,9 +322,19 @@ sub del() { foreach (@Lines) { push (@filtered, $_) unless (/^$mybegin(?:$mytrailer)?$/o .. /^$myend(?:$mytrailer)?$/o); + + # for safety check: + $bm_found = 1 if (/^$mybegin(?:$mytrailer)?$/o); + $em_found = 1 if (/^$myend(?:$mytrailer)?$/o); + } + if ($bm_found and $em_found) { + DEBUG and print STDERR "Deleted ". (@Lines - @filtered) ." out of ".scalar(@Lines)." lines\n"; + @Lines = @filtered; + } + elsif ($bm_found and ! $em_found) { + # safety exit + die "$ProgramName: no end-mark after begin-mark!\n"; } - DEBUG and print STDERR "Deleted ". (@Lines - @filtered) ." out of ".scalar(@Lines)." lines\n"; - @Lines = @filtered; return scalar(@Lines); # whatever }