less/less-444-Foption.v2.patch

132 lines
3.7 KiB
Diff
Raw Normal View History

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>.
2014-12-17 16:43:11 +00:00
Jozef Mlich <jmlich@redhat.com>
---
2014-12-17 16:43:11 +00:00
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 */
}
+
2014-12-17 16:43:11 +00:00
+
+/*
+ * Get line count of file up to the screen height + 1 char
+ */
+ public int
+get_line_count()
+{
2014-12-17 16:43:11 +00:00
+ int nlines = 0;
+ POSITION pos;
+
2014-12-17 16:43:11 +00:00
+ pos = ch_zero();
+
2014-12-17 16:43:11 +00:00
+ while (pos != NULL_POSITION && nlines <= sc_height)
+ {
+ pos = forw_line(pos);
+ nlines++;
+ }
+
2014-12-17 16:43:11 +00:00
+ return nlines;
+}
2014-12-17 16:43:11 +00:00
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 ();
2014-12-17 16:43:11 +00:00
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;
2014-12-17 16:43:11 +00:00
+public int line_count;
extern int missing_cap;
extern int know_dumb;
2014-12-17 16:43:11 +00:00
+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();
2014-12-17 16:43:11 +00:00
+
} else
2008-01-18 13:18:39 +00:00
{
if (edit_first()) /* Edit first valid file in cmd line */
quit(QUIT_ERROR);
2014-12-17 16:43:11 +00:00
+ /*
+ * 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;
+ }
2014-12-17 16:43:11 +00:00
+
2008-01-18 13:18:39 +00:00
}
init();
2014-12-17 16:43:11 +00:00
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
2008-01-18 13:18:39 +00:00
static int attrmode = AT_NORMAL;
extern int binattr;
+extern int line_count;
#if !MSDOS_COMPILER
static char *cheaper();
2014-12-17 16:43:11 +00:00
@@ -232,6 +233,7 @@ extern int wscroll;
extern int screen_trashed;
extern int tty;
extern int top_scroll;
+extern int quit_if_one_screen;
2007-06-26 10:09:21 +00:00
extern int oldbot;
#if HILITE_SEARCH
extern int hilite_search;
2014-12-17 16:43:11 +00:00
@@ -1533,7 +1535,9 @@ win32_deinit_term()
2008-01-18 13:18:39 +00:00
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)
2008-01-18 13:18:39 +00:00
tputs(sc_init, sc_height, putchr);
if (!no_keypad)
tputs(sc_s_keypad, sc_height, putchr);
2014-12-17 16:43:11 +00:00
@@ -1573,7 +1577,7 @@ deinit()
2005-10-21 14:42:56 +00:00
#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);
2005-10-21 14:42:56 +00:00
#else
/* Restore system colors. */