* view.c (get_line_at): Set prev properly for reverse search.

Don't remove final character in the last line without newline.
(search): During regexp search: handle properly '^'
in forward search and '$' in reverse search.
Based on the patch from Adam Byrtek <alpha@debian.org>.
This commit is contained in:
Andrew V. Samoilov 2003-03-24 18:52:02 +00:00
parent 8384e94b0b
commit 6851c22f74
2 changed files with 25 additions and 17 deletions

View File

@ -1,3 +1,11 @@
2003-03-24 Andrew V. Samoilov <sav@bcs.zp.ua>
* view.c (get_line_at): Set prev properly for reverse search.
Don't remove final character in the last line without newline.
(search): During regexp search: handle properly '^'
in forward search and '$' in reverse search.
Based on the patch from Adam Byrtek <alpha@debian.org>.
2003-03-22 Andrew V. Samoilov <sav@bcs.zp.ua> 2003-03-22 Andrew V. Samoilov <sav@bcs.zp.ua>
* cons.handler.c (set_attr) [__FreeBSD__]: Fix compilation. * cons.handler.c (set_attr) [__FreeBSD__]: Fix compilation.

View File

@ -1545,29 +1545,30 @@ get_line_at (WView *view, unsigned long *p, unsigned long *skipped)
} }
*skipped = i; *skipped = i;
if (pos) { if (!i && (pos || direction == -1)) {
prev = get_byte (view, pos - 1); prev = get_byte (view, pos - direction);
if ((prev == -1) || (prev == '\n')) if ((prev == -1) || (prev == '\n'))
prev = 0; prev = 0;
} }
for (i = 0; ch != -1; ch = get_byte (view, pos)) { for (i = 1; ch != -1; ch = get_byte (view, pos)) {
if (i == usable_size) { if (i >= usable_size) {
buffer = grow_string_buffer (buffer, &buffer_size); buffer = grow_string_buffer (buffer, &buffer_size);
usable_size = buffer_size - 2; usable_size = buffer_size - 2; /* prev & null terminator */
} }
i++; buffer[i++] = ch;
buffer[i] = ch;
if (!pos && direction == -1) if (!pos && direction == -1)
break; break;
pos += direction; pos += direction;
if (ch == '\n' || !ch) if (ch == '\n' || !ch) {
i--; /* Strip newline/zero */
break; break;
}
} }
if (buffer) { if (buffer) {
@ -1675,20 +1676,19 @@ search (WView *view, char *text,
/* We found the string */ /* We found the string */
if (*s && !view->search_start && (search == regexp_view_search) /* Handle ^ and $ when regexp search starts at the middle of the line */
&& (*text == '^')) { if (*s && !view->search_start && (search == regexp_view_search)) {
if ((*text == '^' && view->direction == 1)
/* We do not want to match a || (view->direction == -1 && text[strlen (text) - 1] == '$')
* ^ regexp when not at the real ) {
* beginning of some line continue;
*/ }
continue;
} }
/* Record the position used to continue the search */ /* Record the position used to continue the search */
if (view->direction == 1) if (view->direction == 1)
t += forward_line_start; t += forward_line_start;
else else
t = reverse_line_start ? reverse_line_start + 2 : 0; t = reverse_line_start ? reverse_line_start + 3 : 0;
view->search_start += t; view->search_start += t;
if (t != beginning) { if (t != beginning) {