From: NeilBrown Date: Wed, 2 Dec 2015 09:44:59 +0000 (+1100) Subject: Fix search bug: not finding longest match. X-Git-Tag: lca2016~128 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=e54091dc041a6918173af8daa1e54fcf78bb94e9;p=edlib.git Fix search bug: not finding longest match. We need to keep going while we have a partial match (len=-1) and record the last good match. Signed-off-by: NeilBrown --- diff --git a/lib-search.c b/lib-search.c index 26d3a287..64148a23 100644 --- a/lib-search.c +++ b/lib-search.c @@ -14,7 +14,7 @@ DEF_CMD(text_search) { - struct mark *m; + struct mark *m, *endmark = NULL;; struct doc *d; unsigned short *rxl; struct match_state *st; @@ -32,19 +32,24 @@ DEF_CMD(text_search) return -1; st = rxl_prepare(rxl); since_start = -1; - while (since_start < 0 || len > 0) { + while (since_start < 0 || len != -2) { wint_t wch = mark_next(d, m); if (wch == WEOF) break; - if (since_start >= 0) - since_start += 1; + len = rxl_advance(st, wch, 0, since_start < 0); if (len >= 0 && - (since_start < 0 || len > since_start)) + (since_start < 0 || len > since_start)) { since_start = len; + if (endmark) + mark_free(endmark); + endmark = mark_dup(m, 1); + } + } + if (since_start > 0 && endmark) { + mark_to_mark(m, endmark); + mark_free(endmark); } - if (since_start > 0) - mark_prev(d, m); ci->extra = since_start; rxl_free_state(st); free(rxl); diff --git a/rexel.c b/rexel.c index a1e7d471..36d53c2c 100644 --- a/rexel.c +++ b/rexel.c @@ -265,7 +265,6 @@ static int set_match(struct match_state *st, unsigned short addr, wchar_t ch) return 0; } - /* * Advance the match state to process 'ch' and/or flag. * flag indicates start/end of word/line, and whether to ignore ch.