From 1f11c3d2a885a918002d0f2a89b7f442c3183487 Mon Sep 17 00:00:00 2001 From: lxoliva Date: Fri, 22 Jan 2010 09:09:42 +0000 Subject: [PATCH] Avoid skipping blobs that precede blobs in the same line (awk and python). git-svn-id: http://www.fsfla.org/svn/fsfla/software/linux-libre/scripts@5871 559672b5-ba27-0410-b829-e8f1faed8b1b --- deblob-check-awk | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/deblob-check-awk b/deblob-check-awk index 74b3fee31643..75002ecf534b 100755 --- a/deblob-check-awk +++ b/deblob-check-awk @@ -3283,7 +3283,9 @@ s,^\\(.*\\)\$,blob = r'(?P\\1)',;\ if no_falsepos or falsepos is None: falsepos = r'(?!)' -rx = '^%s|[^\n]*%s' % (falsepos, blob) +# Use non-greedy operator to skip partial line before blob, to avoid +# skipping blobs when more than one appears in the same line. +rx = '^%s|[^\n]*?%s' % (falsepos, blob) if with_context: rx += '|^' + cblob @@ -3521,7 +3523,7 @@ BEGIN { pp = p = pend = 1; if (verbose > 1) print "searching starting at", substr (s, p, 10) while (match (substr (s, p), - /(^|[\n])($falsepos)|(^|[\n])($cblob)|[^\n]*($blob)/)) { + /(^|[\n])($falsepos)|(^|[\n])($cblob)|$blob/)) { blobs = falses = 0; firstmatchstart = RSTART + p - 1; if (substr (s, firstmatchstart, 1) == "\n") @@ -3550,10 +3552,6 @@ BEGIN { continue; } else { if (verbose) print "match is a blob"; - # Match again, to skip the leading non-blob characters. - match (substr (s, matchstart), /$blob/); - matchstart = RSTART + matchstart - 1; - matchlen = RLENGTH; blob_p = 1; blobs++; } @@ -3565,14 +3563,23 @@ BEGIN { p = matchstart + length (replacement); } else p = matchstart + matchlen; + i = index (substr (s, p), "\n"); + if (!i) + i = length (s) + p--; if (!match (substr (s, p), - /^($falsepos)|^($cblob)|[^\n]*($blob)/) \\ - || (RSTART != 1 && p + RSTART >= pend)) + /[\n]($falsepos)|[\n]($cblob)|$blob/) \\ + || (RSTART > i && p + RSTART >= pend)) break; } if (print_nomatch) printf "%s", substr (s, pp, firstmatchstart - pp); + else if (print_blob || print_falsepos) { + lastline = substr (s, pp, firstmatchstart - pp); + sub (/.*[\n]/, "", lastline); + firstmatchstart -= length (lastline); + } pp = firstmatchstart; if (p < pend) -- 2.31.1