[git commit] less: move code to count lines into a separate function

Denys Vlasenko vda.linux at googlemail.com
Fri Jul 31 14:22:07 UTC 2015


commit: http://git.busybox.net/busybox/commit/?id=159e032bf4cd24535e57daaf29a381b0d5163368
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/less.c |   52 ++++++++++++++++++++++++++++------------------------
 1 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/miscutils/less.c b/miscutils/less.c
index 4cdfa3b..8fd0874 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);
 


More information about the busybox-cvs mailing list