{PATCH] Fix to more pager

Juan Perez-Sanchez <[email protected]>
Newsgroups org.kernel.vger.linux-8086
Message-ID <CAD6VGuYV_gicj3XVYUS_ERG6JV6bysCUf0BBB-K9O7f0niAZEg@mail.gmail.com>
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
elkscmdA.patch (application/octet-stream, 1.2 KB)
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);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.