Blame SOURCES/less-444-Foption.v2.patch

93dbb7
From 21d56469fd4b4558d640ad82c78f2b9748341c11 Mon Sep 17 00:00:00 2001
93dbb7
From: "Vojtech Vitek (V-Teq)" <vvitek@redhat.com>
93dbb7
Date: Mon, 14 May 2012 17:31:20 +0200
93dbb7
Subject: [PATCH] Fix -F option behavior
93dbb7
93dbb7
Original patch written by Jindrich Novy <jnovy@redhat.com>.
93dbb7
93dbb7
Changes and improvements by Zdenek Prikryl <zprikryl@redhat.com>,
93dbb7
Vojtech Vitek <vvitek@redhat.com> and Colin Guthrie <colin@mageia.org>.
93dbb7
---
93dbb7
 forwback.c |   20 ++++++++++++++++++++
93dbb7
 funcs.h    |    1 +
93dbb7
 main.c     |   16 ++++++++++++++++
93dbb7
 screen.c   |    9 +++++++--
93dbb7
 4 files changed, 44 insertions(+), 2 deletions(-)
93dbb7
93dbb7
diff --git a/forwback.c b/forwback.c
93dbb7
index ebe422d..687355f 100644
93dbb7
--- a/forwback.c
93dbb7
+++ b/forwback.c
93dbb7
@@ -422,3 +422,23 @@ get_back_scroll()
93dbb7
 		return (sc_height - 2);
93dbb7
 	return (10000); /* infinity */
93dbb7
 }
93dbb7
+
93dbb7
+/*
93dbb7
+ * Get line count of file up to the screen height + 1 char
93dbb7
+ */
93dbb7
+	public int
93dbb7
+get_line_count()
93dbb7
+{
93dbb7
+	int nlines = 0;
93dbb7
+	POSITION pos;
93dbb7
+
93dbb7
+	pos = ch_zero();
93dbb7
+
93dbb7
+	while (pos != NULL_POSITION && nlines <= sc_height)
93dbb7
+	{
93dbb7
+		pos = forw_line(pos);
93dbb7
+		nlines++;
93dbb7
+	}
93dbb7
+
93dbb7
+	return nlines;
93dbb7
+}
93dbb7
diff --git a/funcs.h b/funcs.h
93dbb7
index 6595232..8ca4656 100644
93dbb7
--- a/funcs.h
93dbb7
+++ b/funcs.h
93dbb7
@@ -136,6 +136,7 @@
93dbb7
 	public void forward ();
93dbb7
 	public void backward ();
93dbb7
 	public int get_back_scroll ();
93dbb7
+	public int get_line_count ();
93dbb7
 	public void del_ifile ();
93dbb7
 	public IFILE next_ifile ();
93dbb7
 	public IFILE prev_ifile ();
93dbb7
diff --git a/main.c b/main.c
93dbb7
index 0af1762..ef69440 100644
93dbb7
--- a/main.c
93dbb7
+++ b/main.c
93dbb7
@@ -55,6 +55,7 @@ static char consoleTitle[256];
93dbb7
 #endif
93dbb7
 
93dbb7
 extern int	less_is_more;
93dbb7
+public int	line_count;
93dbb7
 extern int	missing_cap;
93dbb7
 extern int	know_dumb;
93dbb7
 extern int	quit_if_one_screen;
93dbb7
@@ -277,10 +278,25 @@ main(argc, argv)
93dbb7
 	{
93dbb7
 		if (edit_stdin())  /* Edit standard input */
93dbb7
 			quit(QUIT_ERROR);
93dbb7
+		if (quit_if_one_screen)
93dbb7
+			line_count = get_line_count();
93dbb7
 	} else 
93dbb7
 	{
93dbb7
 		if (edit_first())  /* Edit first valid file in cmd line */
93dbb7
 			quit(QUIT_ERROR);
93dbb7
+		/*
93dbb7
+		 * In case that we have only one file and -F, have to get a line
93dbb7
+		 * count fot init(). If the line count is less then a height of a term,
93dbb7
+		 * the content of the file is printed out and then less quits. Otherwise
93dbb7
+		 * -F can not be used
93dbb7
+		 */
93dbb7
+		if (quit_if_one_screen)
93dbb7
+		{
93dbb7
+			if (nifile() == 1)
93dbb7
+				line_count = get_line_count();
93dbb7
+			else /* In case more than one file, -F can not be used */
93dbb7
+				quit_if_one_screen = FALSE;
93dbb7
+		}
93dbb7
 	}
93dbb7
 
93dbb7
 	init();
93dbb7
diff --git a/screen.c b/screen.c
93dbb7
index b8bc666..1883e3e 100644
93dbb7
--- a/screen.c
93dbb7
+++ b/screen.c
93dbb7
@@ -204,6 +204,7 @@ public int missing_cap = 0;	/* Some capability is missing */
93dbb7
 
93dbb7
 static int attrmode = AT_NORMAL;
93dbb7
 extern int binattr;
93dbb7
+extern int line_count;
93dbb7
 
93dbb7
 #if !MSDOS_COMPILER
93dbb7
 static char *cheaper();
93dbb7
@@ -233,6 +234,7 @@ extern int wscroll;
93dbb7
 extern int screen_trashed;
93dbb7
 extern int tty;
93dbb7
 extern int top_scroll;
93dbb7
+extern int quit_if_one_screen;
93dbb7
 extern int oldbot;
93dbb7
 #if HILITE_SEARCH
93dbb7
 extern int hilite_search;
93dbb7
@@ -1534,7 +1536,9 @@ win32_deinit_term()
93dbb7
 init()
93dbb7
 {
93dbb7
 #if !MSDOS_COMPILER
93dbb7
-	if (!no_init)
93dbb7
+	if (quit_if_one_screen && line_count >= sc_height)
93dbb7
+		quit_if_one_screen = FALSE;
93dbb7
+	if (!no_init && !quit_if_one_screen)
93dbb7
 		tputs(sc_init, sc_height, putchr);
93dbb7
 	if (!no_keypad)
93dbb7
 		tputs(sc_s_keypad, sc_height, putchr);
93dbb7
@@ -1574,8 +1578,9 @@ deinit()
93dbb7
 #if !MSDOS_COMPILER
93dbb7
 	if (!no_keypad)
93dbb7
 		tputs(sc_e_keypad, sc_height, putchr);
93dbb7
-	if (!no_init)
93dbb7
+	if (!no_init && !quit_if_one_screen)
93dbb7
 		tputs(sc_deinit, sc_height, putchr);
93dbb7
+
93dbb7
 #else
93dbb7
 	/* Restore system colors. */
93dbb7
 	SETCOLORS(sy_fg_color, sy_bg_color);
93dbb7
-- 
93dbb7
1.7.7.6
93dbb7