diff options
author | Ron Yorston <rmy@pobox.com> | 2015-07-24 14:27:42 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-07-31 16:22:07 +0200 |
commit | 159e032bf4cd24535e57daaf29a381b0d5163368 (patch) | |
tree | c073b9ae7a065cbb9021103b3d3f9f2992e346dd | |
parent | ae1a9e899e0d4695834e8ce7348d41663abcef1e (diff) | |
download | busybox-w32-159e032bf4cd24535e57daaf29a381b0d5163368.tar.gz busybox-w32-159e032bf4cd24535e57daaf29a381b0d5163368.tar.bz2 busybox-w32-159e032bf4cd24535e57daaf29a381b0d5163368.zip |
less: move code to count lines into a separate function
function old new delta
update_num_lines - 159 +159
m_status_print 409 266 -143
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 159/-143) Total: 16 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/less.c | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 4cdfa3bbb..8fd0874e2 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -609,33 +609,15 @@ static int safe_lineno(int fline) | |||
609 | return LINENO(flines[fline]) + 1; | 609 | return LINENO(flines[fline]) + 1; |
610 | } | 610 | } |
611 | 611 | ||
612 | /* Print a status line if -M was specified */ | 612 | /* count number of lines in file */ |
613 | static void m_status_print(void) | 613 | static void update_num_lines(void) |
614 | { | 614 | { |
615 | int first, last; | 615 | int count, fd; |
616 | unsigned percent; | 616 | ssize_t len, i; |
617 | 617 | char buf[4096]; | |
618 | if (less_gets_pos >= 0) /* don't touch statusline while input is done! */ | 618 | struct stat stbuf; |
619 | return; | ||
620 | |||
621 | clear_line(); | ||
622 | printf(HIGHLIGHT"%s", filename); | ||
623 | if (num_files > 1) | ||
624 | printf(" (file %i of %i)", current_file, num_files); | ||
625 | |||
626 | first = safe_lineno(cur_fline); | ||
627 | last = (option_mask32 & FLAG_S) | ||
628 | ? MIN(first + max_displayed_line, max_lineno) | ||
629 | : safe_lineno(cur_fline + max_displayed_line); | ||
630 | printf(" lines %i-%i", first, last); | ||
631 | 619 | ||
632 | if (num_lines == READING_FILE) { | 620 | if (num_lines == READING_FILE) { |
633 | int count, fd; | ||
634 | ssize_t len, i; | ||
635 | char buf[4096]; | ||
636 | struct stat stbuf; | ||
637 | |||
638 | /* count number of lines in file */ | ||
639 | count = 0; | 621 | count = 0; |
640 | fd = open(filename, O_RDONLY); | 622 | fd = open(filename, O_RDONLY); |
641 | if (fd < 0) | 623 | if (fd < 0) |
@@ -654,7 +636,29 @@ static void m_status_print(void) | |||
654 | close(fd); | 636 | close(fd); |
655 | skip: ; | 637 | skip: ; |
656 | } | 638 | } |
639 | } | ||
640 | |||
641 | /* Print a status line if -M was specified */ | ||
642 | static void m_status_print(void) | ||
643 | { | ||
644 | int first, last; | ||
645 | unsigned percent; | ||
646 | |||
647 | if (less_gets_pos >= 0) /* don't touch statusline while input is done! */ | ||
648 | return; | ||
649 | |||
650 | clear_line(); | ||
651 | printf(HIGHLIGHT"%s", filename); | ||
652 | if (num_files > 1) | ||
653 | printf(" (file %i of %i)", current_file, num_files); | ||
654 | |||
655 | first = safe_lineno(cur_fline); | ||
656 | last = (option_mask32 & FLAG_S) | ||
657 | ? MIN(first + max_displayed_line, max_lineno) | ||
658 | : safe_lineno(cur_fline + max_displayed_line); | ||
659 | printf(" lines %i-%i", first, last); | ||
657 | 660 | ||
661 | update_num_lines(); | ||
658 | if (num_lines >= 0) | 662 | if (num_lines >= 0) |
659 | printf("/%i", num_lines); | 663 | printf("/%i", num_lines); |
660 | 664 | ||