X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=carnet-tools-cn.git;a=blobdiff_plain;f=cp-update;h=2207c407d1b8a7eab26066fd5dfe1fe65671b5e9;hp=6491c7837f4e0f2c566d11c9ba53fe40f204af8e;hb=dbb7399cf634ebc433853bf4870789e424debf98;hpb=06bf55ad6430db2ba3fd0f4155b5cb36fbfff646 diff --git a/cp-update b/cp-update index 6491c78..2207c40 100755 --- a/cp-update +++ b/cp-update @@ -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 }