diff options
| author | Ron Yorston <rmy@frippery.org> | 2015-07-18 16:20:03 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-07-19 22:48:05 +0200 |
| commit | f06386ad4f5e1e5b5a3aea71ac757d5be8574067 (patch) | |
| tree | f45448523ab56a43efc09aae7ac6d9a3b2d09404 /miscutils | |
| parent | 51aa861843002e92b605be840460e7141d4d86a2 (diff) | |
| download | busybox-w32-f06386ad4f5e1e5b5a3aea71ac757d5be8574067.tar.gz busybox-w32-f06386ad4f5e1e5b5a3aea71ac757d5be8574067.tar.bz2 busybox-w32-f06386ad4f5e1e5b5a3aea71ac757d5be8574067.zip | |
less: fix display of line numbers
Line numbers are displayed incorrectly on lines that have a search
pattern highlighted. The problem can be fixed by moving the call to
lineno_str in print_found above the while loop that alters the value
of the line pointer. However, a more substantial rewrite results in
savings.
function old new delta
buffer_print 688 697 +9
.rodata 156077 156045 -32
lineno_str 85 - -85
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 9/-117) Total: -108 bytes
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/less.c | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index c1755655a..7c46ba5cc 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -677,27 +677,21 @@ static const char ctrlconv[] ALIGN1 = | |||
| 677 | "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x40\x4b\x4c\x4d\x4e\x4f" | 677 | "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x40\x4b\x4c\x4d\x4e\x4f" |
| 678 | "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"; | 678 | "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"; |
| 679 | 679 | ||
| 680 | static void lineno_str(char *nbuf9, const char *line) | 680 | static void print_lineno(const char *line) |
| 681 | { | 681 | { |
| 682 | nbuf9[0] = '\0'; | 682 | const char *fmt = " "; |
| 683 | if (option_mask32 & FLAG_N) { | 683 | unsigned n = n; /* for compiler */ |
| 684 | const char *fmt; | 684 | |
| 685 | unsigned n; | 685 | if (line != empty_line_marker) { |
| 686 | |||
| 687 | if (line == empty_line_marker) { | ||
| 688 | memset(nbuf9, ' ', 8); | ||
| 689 | nbuf9[8] = '\0'; | ||
| 690 | return; | ||
| 691 | } | ||
| 692 | /* Width of 7 preserves tab spacing in the text */ | 686 | /* Width of 7 preserves tab spacing in the text */ |
| 693 | fmt = "%7u "; | 687 | fmt = "%7u "; |
| 694 | n = LINENO(line) + 1; | 688 | n = LINENO(line) + 1; |
| 695 | if (n > 9999999) { | 689 | if (n > 9999999 && MAXLINES > 9999999) { |
| 696 | n %= 10000000; | 690 | n %= 10000000; |
| 697 | fmt = "%07u "; | 691 | fmt = "%07u "; |
| 698 | } | 692 | } |
| 699 | sprintf(nbuf9, fmt, n); | ||
| 700 | } | 693 | } |
| 694 | printf(fmt, n); | ||
| 701 | } | 695 | } |
| 702 | 696 | ||
| 703 | 697 | ||
| @@ -710,7 +704,6 @@ static void print_found(const char *line) | |||
| 710 | regmatch_t match_structs; | 704 | regmatch_t match_structs; |
| 711 | 705 | ||
| 712 | char buf[width]; | 706 | char buf[width]; |
| 713 | char nbuf9[9]; | ||
| 714 | const char *str = line; | 707 | const char *str = line; |
| 715 | char *p = buf; | 708 | char *p = buf; |
| 716 | size_t n; | 709 | size_t n; |
| @@ -760,12 +753,7 @@ static void print_found(const char *line) | |||
| 760 | match_status = 1; | 753 | match_status = 1; |
| 761 | } | 754 | } |
| 762 | 755 | ||
| 763 | lineno_str(nbuf9, line); | 756 | printf("%s%s\n", growline ? growline : "", str); |
| 764 | if (!growline) { | ||
| 765 | printf(CLEAR_2_EOL"%s%s\n", nbuf9, str); | ||
| 766 | return; | ||
| 767 | } | ||
| 768 | printf(CLEAR_2_EOL"%s%s%s\n", nbuf9, growline, str); | ||
| 769 | free(growline); | 757 | free(growline); |
| 770 | } | 758 | } |
| 771 | #else | 759 | #else |
| @@ -775,13 +763,9 @@ void print_found(const char *line); | |||
| 775 | static void print_ascii(const char *str) | 763 | static void print_ascii(const char *str) |
| 776 | { | 764 | { |
| 777 | char buf[width]; | 765 | char buf[width]; |
| 778 | char nbuf9[9]; | ||
| 779 | char *p; | 766 | char *p; |
| 780 | size_t n; | 767 | size_t n; |
| 781 | 768 | ||
| 782 | lineno_str(nbuf9, str); | ||
| 783 | printf(CLEAR_2_EOL"%s", nbuf9); | ||
| 784 | |||
| 785 | while (*str) { | 769 | while (*str) { |
| 786 | n = strcspn(str, controls); | 770 | n = strcspn(str, controls); |
| 787 | if (n) { | 771 | if (n) { |
| @@ -815,6 +799,9 @@ static void buffer_print(void) | |||
| 815 | 799 | ||
| 816 | move_cursor(0, 0); | 800 | move_cursor(0, 0); |
| 817 | for (i = 0; i <= max_displayed_line; i++) { | 801 | for (i = 0; i <= max_displayed_line; i++) { |
| 802 | printf(CLEAR_2_EOL); | ||
| 803 | if (option_mask32 & FLAG_N) | ||
| 804 | print_lineno(buffer[i]); | ||
| 818 | if (pattern_valid) | 805 | if (pattern_valid) |
| 819 | print_found(buffer[i]); | 806 | print_found(buffer[i]); |
| 820 | else | 807 | else |
