Merge Foption changes by Colin Guthrie to Foption.v2.patch

Resolves: #805735
This commit is contained in:
Vojtech Vitek (V-Teq) 2012-05-14 17:50:22 +02:00
parent 46c01743d8
commit 47da4db53f
2 changed files with 88 additions and 57 deletions

View File

@ -1,5 +1,63 @@
--- less-443/main.c.orig 2011-04-20 12:00:59.624710415 +0200
+++ less-443/main.c 2011-04-20 12:02:47.273436639 +0200
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>.
---
forwback.c | 20 ++++++++++++++++++++
funcs.h | 1 +
main.c | 16 ++++++++++++++++
screen.c | 9 +++++++--
4 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/forwback.c b/forwback.c
index ebe422d..687355f 100644
--- a/forwback.c
+++ b/forwback.c
@@ -422,3 +422,23 @@ 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 --git a/funcs.h b/funcs.h
index 6595232..8ca4656 100644
--- a/funcs.h
+++ b/funcs.h
@@ -136,6 +136,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 --git a/main.c b/main.c
index 0af1762..ef69440 100644
--- a/main.c
+++ b/main.c
@@ -55,6 +55,7 @@ static char consoleTitle[256];
#endif
@ -8,9 +66,13 @@
extern int missing_cap;
extern int know_dumb;
extern int quit_if_one_screen;
--- less-406/main.c.Foption 2007-06-17 18:56:04.000000000 +0200
+++ less-406/main.c 2008-01-11 10:18:46.000000000 +0100
@@ -280,6 +281,16 @@ main(argc, argv)
@@ -277,10 +278,25 @@ 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);
@ -20,16 +82,21 @@
+ * the content of the file is printed out and then less quits. Otherwise
+ * -F can not be used
+ */
+ if (nifile() == 1 && quit_if_one_screen)
+ line_count = get_line_count();
+ else if (nifile() > 1) /* In case more than one file, -F can not be used */
+ quit_if_one_screen = FALSE;
+ 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();
--- less-406/screen.c.Foption 2007-06-17 18:56:04.000000000 +0200
+++ less-406/screen.c 2008-01-11 10:20:00.000000000 +0100
@@ -204,6 +204,7 @@ public int missing_cap = 0; /* Some capa
diff --git a/screen.c b/screen.c
index b8bc666..1883e3e 100644
--- a/screen.c
+++ b/screen.c
@@ -204,6 +204,7 @@ public int missing_cap = 0; /* Some capability is missing */
static int attrmode = AT_NORMAL;
extern int binattr;
@ -52,57 +119,21 @@
- if (!no_init)
+ if (quit_if_one_screen && line_count >= sc_height)
+ quit_if_one_screen = FALSE;
+ if (!no_init && !quit_if_one_screen)
+ if (!no_init && !quit_if_one_screen)
tputs(sc_init, sc_height, putchr);
if (!no_keypad)
tputs(sc_s_keypad, sc_height, putchr);
@@ -1573,8 +1577,9 @@ deinit()
@@ -1574,8 +1578,9 @@ deinit()
#if !MSDOS_COMPILER
if (!no_keypad)
tputs(sc_e_keypad, sc_height, putchr);
- if (!no_init)
- tputs(sc_deinit, sc_height, putchr);
+ if (!no_init && !quit_if_one_screen)
+ tputs(sc_deinit, sc_height, putchr);
+
+ if (!no_init && !quit_if_one_screen)
tputs(sc_deinit, sc_height, putchr);
+
#else
/* Restore system colors. */
SETCOLORS(sy_fg_color, sy_bg_color);
--- less-406/funcs.h.Foption 2007-03-24 07:27:54.000000000 +0100
+++ less-406/funcs.h 2008-01-11 09:36:16.000000000 +0100
@@ -126,6 +126,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 ();
--- less-406/forwback.c.Foption 2007-06-17 18:56:04.000000000 +0200
+++ less-406/forwback.c 2008-01-11 09:37:15.000000000 +0100
@@ -410,3 +410,24 @@ get_back_scroll()
return (sc_height - 2);
return (10000); /* infinity */
}
+
+/*
+ * Get line count of file
+ */
+ public int
+get_line_count()
+{
+ int nlines = 0;
+ POSITION pos;
+
+ pos = position(TOP);
+
+ while (pos != NULL_POSITION && nlines <= sc_height)
+ {
+ pos = forw_line(pos);
+ nlines++;
+ }
+
+ return nlines;
+}
+
--
1.7.7.6

View File

@ -8,7 +8,7 @@ Source: http://www.greenwoodsoftware.com/less/%{name}-%{version}.tar.gz
Source1: lesspipe.sh
Source2: less.sh
Source3: less.csh
Patch1: less-443-Foption.patch
Patch1: less-444-Foption.v2.patch
Patch2: less-394-search.patch
Patch4: less-394-time.patch
Patch5: less-418-fsync.patch
@ -39,7 +39,6 @@ files, and you'll use it frequently.
%patch6 -p1 -b .manpage-add-old-bot-option
%patch8 -p1 -b .help
%patch9 -p1 -b .empty-lessopen-pipe
autoreconf
chmod -R a+w *
@ -72,6 +71,7 @@ rm -rf $RPM_BUILD_ROOT
* Mon May 14 2012 Vojtech Vitek (V-Teq) <vvitek@redhat.com> - 444-7
- Fix less.sh not to override user-defined LESSOPEN variable (#802757)
- Use POSIX regcomp instead of PCRE - revert 406-11, commit 4b961c7 (#643233)
- Merge Foption changes by Colin Guthrie to Foption.v2.patch (#805735)
* Fri Feb 10 2012 Petr Pisar <ppisar@redhat.com> - 444-6
- Rebuild against PCRE 8.30