linux-8086.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juan Perez-Sanchez <lithoxs@gmail.com>
To: linux-8086 <linux-8086@vger.kernel.org>
Subject: {PATCH] Fix to more pager
Date: Sat, 2 Feb 2013 12:50:17 -0600	[thread overview]
Message-ID: <CAD6VGuYV_gicj3XVYUS_ERG6JV6bysCUf0BBB-K9O7f0niAZEg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

Hi,

  Attached is a patch to fix the "more" filter.

The command:

# ls -l | more

did not produced any output. The problem was with the more pager. It
happened that "more" is extremely barebones (and so is this fix) and
did not realize when its input was being redirected to its standard
input.

With the attached patch, the above command works right under QEMU.

Greetings,

Juan

[-- Attachment #2: elkscmdA.patch --]
[-- Type: application/octet-stream, Size: 1217 bytes --]

diff -Nurb elkscmd.orig/file_utils/more.c elkscmd/file_utils/more.c
--- elkscmd.orig/file_utils/more.c	2012-12-11 23:26:18.000000000 -0600
+++ elkscmd/file_utils/more.c	2013-02-02 12:20:41.000000000 -0600
@@ -23,14 +23,16 @@
 	char	**argv;
 {
 	FILE	*fp;
-	int	fd;
+	int	fd, cin;
 	char	*name;
 	char	ch;
 	int	line;
 	int	col;
 	char	buf[80];
 
-	while (argc-- > 1) {
+	cin = 0;
+	do {
+		if(argc >= 2) {
 		name = *(++argv);
 
 		fd = open(name, O_RDONLY);
@@ -42,6 +44,13 @@
 		write(STDOUT_FILENO,"<< ",3);
 		write(STDOUT_FILENO,name,strlen(name));
 		write(STDOUT_FILENO," >>\n",4);
+		} else {
+			fd = 0;
+			cin = open("/dev/tty0", "r");
+			if (!cin)
+				cin = fopen("/dev/console", "r");
+			write(STDOUT_FILENO,"<< stdin >>\n",12);
+		}
 		line = 1;
 		col = 0;
 
@@ -75,7 +84,7 @@
 				line++;
 			}
 
-			if (line < 24)
+			if (line < 25)
 				continue;
 
 			if (col > 0)
@@ -84,7 +93,8 @@
 			write(STDOUT_FILENO,"--More--",8);
 			fflush(stdout);
 
-			if ((read(0, buf, sizeof(buf)) < 0)) {
+			if (read(cin, buf, sizeof(buf)) < 1) {
+				perror("more: ");
 				if (fd > -1)
 					close(fd);
 				exit(0);
@@ -112,6 +122,6 @@
 		}
 		if (fd)
 			close(fd);
-	}
+	} while(--argc > 1);
 	exit(0);
 }

                 reply	other threads:[~2013-02-02 18:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAD6VGuYV_gicj3XVYUS_ERG6JV6bysCUf0BBB-K9O7f0niAZEg@mail.gmail.com \
    --to=lithoxs@gmail.com \
    --cc=linux-8086@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).