POSIX compliance patch preventing exit on EOF without -e flag.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 

I hope you don't mind my sending you this patch. I ran into a problem
with a piece of software that relies on POSIX compliant implementation
of more, that only exits on EOF with the addition of a -e flag.

Having checked the POSIX documentation for more this would appear to be
correct behavior:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/more.html

Best regards,

Ian
>From 65ee6afeeb4940d7ea0a83dcb3c2c3d2d78f2503 Mon Sep 17 00:00:00 2001
From: Ian Jones <ian@xxxxxxxxxxxxxxxxx>
Date: Thu, 24 Jun 2021 13:40:52 +0100
Subject: [PATCH] Implemented -e and changed default behavior to be POSIX
 compliant:
 https://pubs.opengroup.org/onlinepubs/9699919799/utilities/more.html

---
 text-utils/more.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/text-utils/more.c b/text-utils/more.c
index 6299e8d82..a5faea286 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -207,6 +207,7 @@ struct more_control {
 		eat_newline:1,		/* is newline ignored after 80 cols */
 		erase_input_ok:1,	/* is erase input supported */
 		erase_previous_ok:1,	/* is erase previous supported */
+		exit_on_eof:1,	    /* exit on EOF */
 		first_file:1,		/* is the input file the first in list */
 		fold_long_lines:1,	/* fold long lines */
 		hard_tabs:1,		/* print spaces instead of '\t' */
@@ -243,6 +244,7 @@ static void __attribute__((__noreturn__)) usage(void)
 	printf("%s\n", _(" -l, --no-pause        suppress pause after form feed"));
 	printf("%s\n", _(" -c, --print-over      do not scroll, display text and clean line ends"));
 	printf("%s\n", _(" -p, --clean-print     do not scroll, clean screen and display text"));
+	printf("%s\n", _(" -e, --exit-on-eof     exit on EOF"));
 	printf("%s\n", _(" -s, --squeeze         squeeze multiple blank lines into one"));
 	printf("%s\n", _(" -u, --plain           suppress underlining and bold"));
 	printf("%s\n", _(" -n, --lines <number>  the number of lines per screenful"));
@@ -264,6 +266,7 @@ static void argscan(struct more_control *ctl, int as_argc, char **as_argv)
 		{ "no-pause",    no_argument,       NULL, 'l' },
 		{ "print-over",  no_argument,       NULL, 'c' },
 		{ "clean-print", no_argument,       NULL, 'p' },
+		{ "exit-on-eof", no_argument,       NULL, 'e' },
 		{ "squeeze",     no_argument,       NULL, 's' },
 		{ "plain",       no_argument,       NULL, 'u' },
 		{ "lines",       required_argument, NULL, 'n' },
@@ -324,7 +327,8 @@ static void argscan(struct more_control *ctl, int as_argc, char **as_argv)
 		case 'n':
 			ctl->lines_per_screen = strtou16_or_err(optarg, _("argument error"));
 			break;
-		case 'e':	/* ignored silently to be posix compliant */
+		case 'e':
+            ctl->exit_on_eof = 1;
 			break;
 		case 'V':
 			print_version(EXIT_SUCCESS);
@@ -1809,7 +1813,7 @@ static void screen(struct more_control *ctl, int num_lines)
 
 	for (;;) {
 		while (num_lines > 0 && !ctl->is_paused) {
-			if ((nchars = get_line(ctl, &length)) == EOF) {
+			if ((nchars = get_line(ctl, &length)) == EOF && ctl->exit_on_eof) {
 				if (ctl->clear_line_ends)
 					putp(ctl->clear_rest);
 				return;
@@ -1834,7 +1838,7 @@ static void screen(struct more_control *ctl, int num_lines)
 			num_lines--;
 		}
 		fflush(NULL);
-		if ((c = more_getc(ctl)) == EOF) {
+		if ((c = more_getc(ctl)) == EOF && ctl->exit_on_eof) {
 			if (ctl->clear_line_ends)
 				putp(ctl->clear_rest);
 			return;
-- 
2.20.1


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux