aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-07-24 14:27:42 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-07-31 16:22:07 +0200
commit159e032bf4cd24535e57daaf29a381b0d5163368 (patch)
treec073b9ae7a065cbb9021103b3d3f9f2992e346dd
parentae1a9e899e0d4695834e8ce7348d41663abcef1e (diff)
downloadbusybox-159e032bf4cd24535e57daaf29a381b0d5163368.tar.gz
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.c52
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)
return LINENO(flines[fline]) + 1;
}
-/* Print a status line if -M was specified */
-static void m_status_print(void)
+/* count number of lines in file */
+static void update_num_lines(void)
{
- int first, last;
- unsigned percent;
-
- if (less_gets_pos >= 0) /* don't touch statusline while input is done! */
- return;
-
- clear_line();
- printf(HIGHLIGHT"%s", filename);
- if (num_files > 1)
- printf(" (file %i of %i)", current_file, num_files);
-
- first = safe_lineno(cur_fline);
- last = (option_mask32 & FLAG_S)
- ? MIN(first + max_displayed_line, max_lineno)
- : safe_lineno(cur_fline + max_displayed_line);
- printf(" lines %i-%i", first, last);
+ int count, fd;
+ ssize_t len, i;
+ char buf[4096];
+ struct stat stbuf;
if (num_lines == READING_FILE) {
- int count, fd;
- ssize_t len, i;
- char buf[4096];
- struct stat stbuf;
-
- /* count number of lines in file */
count = 0;
fd = open(filename, O_RDONLY);
if (fd < 0)
@@ -654,7 +636,29 @@ static void m_status_print(void)
close(fd);
skip: ;
}
+}
+
+/* Print a status line if -M was specified */
+static void m_status_print(void)
+{
+ int first, last;
+ unsigned percent;
+
+ if (less_gets_pos >= 0) /* don't touch statusline while input is done! */
+ return;
+
+ clear_line();
+ printf(HIGHLIGHT"%s", filename);
+ if (num_files > 1)
+ printf(" (file %i of %i)", current_file, num_files);
+
+ first = safe_lineno(cur_fline);
+ last = (option_mask32 & FLAG_S)
+ ? MIN(first + max_displayed_line, max_lineno)
+ : safe_lineno(cur_fline + max_displayed_line);
+ printf(" lines %i-%i", first, last);
+ update_num_lines();
if (num_lines >= 0)
printf("/%i", num_lines);