aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-08 16:44:32 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-08 16:44:32 +0000
commit5c1de367020ed4c05a094ffa3cd2781205db03c1 (patch)
treec61632268f1f11b3b7478a9d8d55f40ca293b29a /miscutils
parent8a91081d9d3bdef1d46a0629ac736b9051e32cf3 (diff)
downloadbusybox-5c1de367020ed4c05a094ffa3cd2781205db03c1.tar.gz
less: fix 'n'ext match: sometimes was going to 999999th line
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/less.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 3db7c9cdb..b0e2754f8 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -342,6 +342,23 @@ static void status_print(void)
print_hilite(p);
}
+static void cap_cur_fline(int nlines)
+{
+ int diff;
+ if (cur_fline < 0)
+ cur_fline = 0;
+ if (cur_fline + max_displayed_line > max_fline + TILDES) {
+ cur_fline -= nlines;
+ if (cur_fline < 0)
+ cur_fline = 0;
+ diff = max_fline - (cur_fline + max_displayed_line) + TILDES;
+ /* As the number of lines requested was too large, we just move
+ to the end of the file */
+ if (diff > 0)
+ cur_fline += diff;
+ }
+}
+
static char controls[] =
/* NUL: never encountered; TAB: not converted */
/**/"\x01\x02\x03\x04\x05\x06\x07\x08" "\x0a\x0b\x0c\x0d\x0e\x0f"
@@ -479,18 +496,9 @@ static void buffer_fill_and_print(void)
/* Move the buffer up and down in the file in order to scroll */
static void buffer_down(int nlines)
{
- int diff;
cur_fline += nlines;
read_lines();
-
- if (cur_fline + max_displayed_line > max_fline + TILDES) {
- cur_fline -= nlines;
- diff = max_fline - (cur_fline + max_displayed_line) + TILDES;
- /* As the number of lines requested was too large, we just move
- to the end of the file */
- if (diff > 0)
- cur_fline += diff;
- }
+ cap_cur_fline(nlines);
buffer_fill_and_print();
}
@@ -763,6 +771,7 @@ static void goto_match(int match)
if (match >= num_matches && eof_error > 0) {
cur_fline = MAXLINES; /* look as far as needed */
read_lines();
+ cap_cur_fline(cur_fline);
}
if (num_matches) {
normalize_match_pos(match);