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