132 lines
3.7 KiB
Diff
132 lines
3.7 KiB
Diff
From 21d56469fd4b4558d640ad82c78f2b9748341c11 Mon Sep 17 00:00:00 2001
|
|
From: "Vojtech Vitek (V-Teq)" <vvitek@redhat.com>
|
|
Date: Mon, 14 May 2012 17:31:20 +0200
|
|
Subject: [PATCH] Fix -F option behavior
|
|
|
|
Original patch written by Jindrich Novy <jnovy@redhat.com>.
|
|
|
|
Changes and improvements by Zdenek Prikryl <zprikryl@redhat.com>,
|
|
Vojtech Vitek <vvitek@redhat.com> and Colin Guthrie <colin@mageia.org>.
|
|
Jozef Mlich <jmlich@redhat.com>
|
|
---
|
|
diff -up ./less-466/forwback.c.Foption ./less-466/forwback.c
|
|
--- ./less-466/forwback.c.Foption 2014-08-24 02:46:52.000000000 +0200
|
|
+++ ./less-466/forwback.c 2014-09-18 13:54:28.804626580 +0200
|
|
@@ -440,3 +440,24 @@ get_back_scroll()
|
|
return (sc_height - 2);
|
|
return (10000); /* infinity */
|
|
}
|
|
+
|
|
+
|
|
+/*
|
|
+ * Get line count of file up to the screen height + 1 char
|
|
+ */
|
|
+ public int
|
|
+get_line_count()
|
|
+{
|
|
+ int nlines = 0;
|
|
+ POSITION pos;
|
|
+
|
|
+ pos = ch_zero();
|
|
+
|
|
+ while (pos != NULL_POSITION && nlines <= sc_height)
|
|
+ {
|
|
+ pos = forw_line(pos);
|
|
+ nlines++;
|
|
+ }
|
|
+
|
|
+ return nlines;
|
|
+}
|
|
diff -up ./less-466/funcs.h.Foption ./less-466/funcs.h
|
|
--- ./less-466/funcs.h.Foption 2014-08-24 02:46:54.000000000 +0200
|
|
+++ ./less-466/funcs.h 2014-09-18 13:55:12.140010010 +0200
|
|
@@ -139,6 +139,7 @@
|
|
public void forward ();
|
|
public void backward ();
|
|
public int get_back_scroll ();
|
|
+ public int get_line_count ();
|
|
public void del_ifile ();
|
|
public IFILE next_ifile ();
|
|
public IFILE prev_ifile ();
|
|
diff -up ./less-466/main.c.Foption ./less-466/main.c
|
|
--- ./less-466/main.c.Foption 2014-08-24 02:46:51.000000000 +0200
|
|
+++ ./less-466/main.c 2014-09-18 14:03:12.868331522 +0200
|
|
@@ -54,8 +54,10 @@ static char consoleTitle[256];
|
|
#endif
|
|
|
|
extern int less_is_more;
|
|
+public int line_count;
|
|
extern int missing_cap;
|
|
extern int know_dumb;
|
|
+extern int quit_if_one_screen;
|
|
extern int pr_type;
|
|
|
|
|
|
@@ -273,10 +275,27 @@ main(argc, argv)
|
|
{
|
|
if (edit_stdin()) /* Edit standard input */
|
|
quit(QUIT_ERROR);
|
|
+ if (quit_if_one_screen)
|
|
+ line_count = get_line_count();
|
|
+
|
|
} else
|
|
{
|
|
if (edit_first()) /* Edit first valid file in cmd line */
|
|
quit(QUIT_ERROR);
|
|
+ /*
|
|
+ * In case that we have only one file and -F, have to get a line
|
|
+ * count fot init(). If the line count is less then a height of a term,
|
|
+ * the content of the file is printed out and then less quits. Otherwise
|
|
+ * -F can not be used
|
|
+ */
|
|
+ if (quit_if_one_screen)
|
|
+ {
|
|
+ if (nifile() == 1)
|
|
+ line_count = get_line_count();
|
|
+ else /* In case more than one file, -F can not be used */
|
|
+ quit_if_one_screen = FALSE;
|
|
+ }
|
|
+
|
|
}
|
|
|
|
init();
|
|
diff -up ./less-466/screen.c.Foption ./less-466/screen.c
|
|
--- ./less-466/screen.c.Foption 2014-08-24 02:46:51.000000000 +0200
|
|
+++ ./less-466/screen.c 2014-09-18 13:58:52.772962165 +0200
|
|
@@ -203,6 +203,7 @@ public int missing_cap = 0; /* Some capa
|
|
|
|
static int attrmode = AT_NORMAL;
|
|
extern int binattr;
|
|
+extern int line_count;
|
|
|
|
#if !MSDOS_COMPILER
|
|
static char *cheaper();
|
|
@@ -232,6 +233,7 @@ extern int wscroll;
|
|
extern int screen_trashed;
|
|
extern int tty;
|
|
extern int top_scroll;
|
|
+extern int quit_if_one_screen;
|
|
extern int oldbot;
|
|
#if HILITE_SEARCH
|
|
extern int hilite_search;
|
|
@@ -1533,7 +1535,9 @@ win32_deinit_term()
|
|
init()
|
|
{
|
|
#if !MSDOS_COMPILER
|
|
- if (!no_init)
|
|
+ if (quit_if_one_screen && line_count >= sc_height)
|
|
+ quit_if_one_screen = FALSE;
|
|
+ if (!no_init && !quit_if_one_screen)
|
|
tputs(sc_init, sc_height, putchr);
|
|
if (!no_keypad)
|
|
tputs(sc_s_keypad, sc_height, putchr);
|
|
@@ -1573,7 +1577,7 @@ deinit()
|
|
#if !MSDOS_COMPILER
|
|
if (!no_keypad)
|
|
tputs(sc_e_keypad, sc_height, putchr);
|
|
- if (!no_init)
|
|
+ if (!no_init && !quit_if_one_screen)
|
|
tputs(sc_deinit, sc_height, putchr);
|
|
#else
|
|
/* Restore system colors. */
|