svn commit: trunk/busybox/miscutils
vda at busybox.net
vda at busybox.net
Wed Feb 14 12:49:15 PST 2007
Author: vda
Date: 2007-02-14 12:49:14 -0800 (Wed, 14 Feb 2007)
New Revision: 17889
Log:
less: support xterm's home/end; improve forward search
Modified:
trunk/busybox/miscutils/less.c
Changeset:
Modified: trunk/busybox/miscutils/less.c
===================================================================
--- trunk/busybox/miscutils/less.c 2007-02-14 19:53:54 UTC (rev 17888)
+++ trunk/busybox/miscutils/less.c 2007-02-14 20:49:14 UTC (rev 17889)
@@ -48,6 +48,8 @@
REAL_PAGE_DOWN = '6',
REAL_KEY_HOME = '7',
REAL_KEY_END = '8',
+ REAL_KEY_HOME_XTERM = 'H',
+ REAL_KEY_END_XTERM = 'F',
/* These are the special codes assigned by this program to the special keys */
KEY_UP = 20,
@@ -196,6 +198,7 @@
terminated = 0;
while (1) {
char c;
+ /* if no unprocessed chars left, eat more */
if (readpos >= readeof) {
ndelay_on(0);
eof_error = safe_read(0, readbuf, sizeof(readbuf));
@@ -507,6 +510,8 @@
read_lines();
if (linenum + max_displayed_line > max_fline)
linenum = max_fline - max_displayed_line + TILDES;
+ if (linenum < 0)
+ linenum = 0;
cur_fline = linenum;
buffer_fill_and_print();
}
@@ -607,6 +612,10 @@
i = input[2] - REAL_PAGE_UP;
if (i < 4)
return 24 + i;
+ if (input[2] == REAL_KEY_HOME_XTERM)
+ return KEY_HOME;
+ if (input[2] == REAL_KEY_END_XTERM)
+ return KEY_END;
return 0;
}
/* Reject almost all control chars */
@@ -735,20 +744,30 @@
}
#if ENABLE_FEATURE_LESS_REGEXP
-static int normalize_match_pos(int match)
+static void normalize_match_pos(int match)
{
- match_pos = match;
if (match >= num_matches)
- match_pos = num_matches - 1;
+ match = num_matches - 1;
if (match < 0)
- match_pos = 0;
- return match_pos;
+ match = 0;
+ match_pos = match;
}
static void goto_match(int match)
{
- if (num_matches)
- buffer_line(match_lines[normalize_match_pos(match)]);
+ if (!pattern_valid)
+ return;
+ if (match < 0)
+ match = 0;
+ /* Try to find next match if eof isn't reached yet */
+ if (match >= num_matches && eof_error > 0) {
+ cur_fline = MAXLINES; /* look as far as needed */
+ read_lines();
+ }
+ if (num_matches) {
+ normalize_match_pos(match);
+ buffer_line(match_lines[match_pos]);
+ }
}
static void fill_match_lines(unsigned pos)
@@ -817,7 +836,8 @@
}
if (option_mask32 & LESS_STATE_MATCH_BACKWARDS)
match_pos--;
- buffer_line(match_lines[normalize_match_pos(match_pos)]);
+ normalize_match_pos(match_pos);
+ buffer_line(match_lines[match_pos]);
}
#endif
More information about the busybox-cvs
mailing list