Changeset 6a35938 for viewwin.c


Ignore:
Timestamp:
Sep 18, 2010, 5:07:40 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
38e2250
Parents:
fc5eef4
git-author:
David Benjamin <davidben@mit.edu> (08/15/10 15:56:44)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:40)
Message:
Add an unspeakably ugly version of reverse search

I think we really want the viewwin to have pre-split the output into
lines.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • viewwin.c

    r60c1386 r6a35938  
    224224}
    225225
     226/* This is a bit of a hack, because regexec doesn't have an 'n'
     227 * version. */
     228static int _re_memcompare(const owl_regex *re, const char *string, int start, int end)
     229{
     230  int ans;
     231  char *tmp = g_strndup(string + start, end - start);
     232  ans = owl_regex_compare(re, tmp, NULL, NULL);
     233  g_free(tmp);
     234  return !ans;
     235}
     236
    226237/* Scroll in 'direction' to the next line containing 're' in 'v',
    227238 * starting from the current line. Returns 0 if no occurrence is
     
    233244{
    234245  int start, end, offset;
     246  int lineend, linestart;
     247  const char *buf, *linestartp;
    235248  owl_fmtext_line_extents(&v->fmtext, v->topline, &start, &end);
    236249  if (direction == OWL_DIRECTION_DOWNWARDS) {
     
    242255    return 1;
    243256  } else {
    244     /* FIXME */
    245     owl_function_error("Upwards searching is not implemented in viewwin.");
    246     return 1;
     257    /* TODO: This is a hack. Really, we should have an owl_fmlines or
     258     * something containing an array of owl_fmtext split into
     259     * lines. Also, it cannot handle multi-line regex, if we ever care about
     260     * them. */
     261    buf = owl_fmtext_get_text(&v->fmtext);
     262    lineend = mode ? start : end;
     263    while (lineend > 0) {
     264      linestartp = memrchr(buf, '\n', lineend - 1);
     265      linestart = linestartp ? linestartp - buf + 1 : 0;
     266      if (_re_memcompare(re, buf, linestart, lineend)) {
     267        v->topline = owl_fmtext_line_number(&v->fmtext, linestart);
     268        owl_viewwin_dirty(v);
     269        return 1;
     270      }
     271      lineend = linestart;
     272    }
     273    return 0;
    247274  }
    248275}
Note: See TracChangeset for help on using the changeset viewer.