diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-14 20:49:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-14 20:49:14 +0000 |
commit | b30418ac19a45d188cb7c2e2f7e5879aa5f1f169 (patch) | |
tree | d8c63450bd048ad6f9fe5e085a09ffc7e8320752 /miscutils/less.c | |
parent | ae30210d909ba52328385b75891754b0c93ec780 (diff) | |
download | busybox-w32-b30418ac19a45d188cb7c2e2f7e5879aa5f1f169.tar.gz busybox-w32-b30418ac19a45d188cb7c2e2f7e5879aa5f1f169.tar.bz2 busybox-w32-b30418ac19a45d188cb7c2e2f7e5879aa5f1f169.zip |
less: support xterm's home/end; improve forward search
Diffstat (limited to 'miscutils/less.c')
-rw-r--r-- | miscutils/less.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 9aae81fa4..1be5d3520 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -48,6 +48,8 @@ enum { | |||
48 | REAL_PAGE_DOWN = '6', | 48 | REAL_PAGE_DOWN = '6', |
49 | REAL_KEY_HOME = '7', | 49 | REAL_KEY_HOME = '7', |
50 | REAL_KEY_END = '8', | 50 | REAL_KEY_END = '8', |
51 | REAL_KEY_HOME_XTERM = 'H', | ||
52 | REAL_KEY_END_XTERM = 'F', | ||
51 | 53 | ||
52 | /* These are the special codes assigned by this program to the special keys */ | 54 | /* These are the special codes assigned by this program to the special keys */ |
53 | KEY_UP = 20, | 55 | KEY_UP = 20, |
@@ -196,6 +198,7 @@ static void read_lines(void) | |||
196 | terminated = 0; | 198 | terminated = 0; |
197 | while (1) { | 199 | while (1) { |
198 | char c; | 200 | char c; |
201 | /* if no unprocessed chars left, eat more */ | ||
199 | if (readpos >= readeof) { | 202 | if (readpos >= readeof) { |
200 | ndelay_on(0); | 203 | ndelay_on(0); |
201 | eof_error = safe_read(0, readbuf, sizeof(readbuf)); | 204 | eof_error = safe_read(0, readbuf, sizeof(readbuf)); |
@@ -507,6 +510,8 @@ static void buffer_line(int linenum) | |||
507 | read_lines(); | 510 | read_lines(); |
508 | if (linenum + max_displayed_line > max_fline) | 511 | if (linenum + max_displayed_line > max_fline) |
509 | linenum = max_fline - max_displayed_line + TILDES; | 512 | linenum = max_fline - max_displayed_line + TILDES; |
513 | if (linenum < 0) | ||
514 | linenum = 0; | ||
510 | cur_fline = linenum; | 515 | cur_fline = linenum; |
511 | buffer_fill_and_print(); | 516 | buffer_fill_and_print(); |
512 | } | 517 | } |
@@ -607,6 +612,10 @@ static int less_getch(void) | |||
607 | i = input[2] - REAL_PAGE_UP; | 612 | i = input[2] - REAL_PAGE_UP; |
608 | if (i < 4) | 613 | if (i < 4) |
609 | return 24 + i; | 614 | return 24 + i; |
615 | if (input[2] == REAL_KEY_HOME_XTERM) | ||
616 | return KEY_HOME; | ||
617 | if (input[2] == REAL_KEY_END_XTERM) | ||
618 | return KEY_END; | ||
610 | return 0; | 619 | return 0; |
611 | } | 620 | } |
612 | /* Reject almost all control chars */ | 621 | /* Reject almost all control chars */ |
@@ -735,20 +744,30 @@ static void colon_process(void) | |||
735 | } | 744 | } |
736 | 745 | ||
737 | #if ENABLE_FEATURE_LESS_REGEXP | 746 | #if ENABLE_FEATURE_LESS_REGEXP |
738 | static int normalize_match_pos(int match) | 747 | static void normalize_match_pos(int match) |
739 | { | 748 | { |
740 | match_pos = match; | ||
741 | if (match >= num_matches) | 749 | if (match >= num_matches) |
742 | match_pos = num_matches - 1; | 750 | match = num_matches - 1; |
743 | if (match < 0) | 751 | if (match < 0) |
744 | match_pos = 0; | 752 | match = 0; |
745 | return match_pos; | 753 | match_pos = match; |
746 | } | 754 | } |
747 | 755 | ||
748 | static void goto_match(int match) | 756 | static void goto_match(int match) |
749 | { | 757 | { |
750 | if (num_matches) | 758 | if (!pattern_valid) |
751 | buffer_line(match_lines[normalize_match_pos(match)]); | 759 | return; |
760 | if (match < 0) | ||
761 | match = 0; | ||
762 | /* Try to find next match if eof isn't reached yet */ | ||
763 | if (match >= num_matches && eof_error > 0) { | ||
764 | cur_fline = MAXLINES; /* look as far as needed */ | ||
765 | read_lines(); | ||
766 | } | ||
767 | if (num_matches) { | ||
768 | normalize_match_pos(match); | ||
769 | buffer_line(match_lines[match_pos]); | ||
770 | } | ||
752 | } | 771 | } |
753 | 772 | ||
754 | static void fill_match_lines(unsigned pos) | 773 | static void fill_match_lines(unsigned pos) |
@@ -817,7 +836,8 @@ static void regex_process(void) | |||
817 | } | 836 | } |
818 | if (option_mask32 & LESS_STATE_MATCH_BACKWARDS) | 837 | if (option_mask32 & LESS_STATE_MATCH_BACKWARDS) |
819 | match_pos--; | 838 | match_pos--; |
820 | buffer_line(match_lines[normalize_match_pos(match_pos)]); | 839 | normalize_match_pos(match_pos); |
840 | buffer_line(match_lines[match_pos]); | ||
821 | } | 841 | } |
822 | #endif | 842 | #endif |
823 | 843 | ||