Ricardo Mestre wrote:
> Prodded by theo@ and others offline, the removal of the pager may cause
> some terms to not display the entire text of the instructions for fish(6).
> 
> After some rewording, removal of blank lines and start the paragraphs
> with 2 spaces the text fits at least in a 80x24 screen (sorry, couldn't
> make the paragraphs with tabs otherwise it wouldn't fit).

Heh, funny timing. I have done something different in wump which I only just
showed some other people earlier today.

Reimplement a very basic single function pager. This code can later be
improved and shared; it's just a demo.

Index: wump.c
===================================================================
RCS file: /cvs/src/games/wump/wump.c,v
retrieving revision 1.26
diff -u -p -r1.26 wump.c
--- wump.c      29 Aug 2013 20:22:22 -0000      1.26
+++ wump.c      23 Nov 2015 19:05:08 -0000
@@ -855,6 +855,60 @@ int_compare(const void *a, const void *b
        return(*(const int *)a < *(const int *)b ? -1 : 1);
 }
 
+#include <sys/ioctl.h>
+#include <sys/tty.h>
+int
+pagefile(const char *filename)
+{
+       char buf[1024];
+       FILE *fp;
+       int i, lines = 0;
+       struct termios orig;
+
+       if ((fp = fopen(filename, "r")) == NULL)
+               return -1;
+
+       if (isatty(STDOUT_FILENO)) {
+               struct winsize ws;
+               if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
+                       lines = ws.ws_row;
+       }
+       if (lines) {
+               struct termios ti;
+
+               tcgetattr(1, &orig);
+               ti = orig;
+               ti.c_lflag &= ~(ECHO | ICANON);
+               tcsetattr(1, TCSADRAIN, &ti);
+       }
+
+       i = lines;
+       while (fgets(buf, sizeof(buf), fp)) {
+               i--;
+               if (i == 0) {
+                       char key;
+                       fputs("--- Press Any Key ---", stdout);
+                       fflush(stdout);
+                       read(STDIN_FILENO, &key, 1);
+                       fputs("\r", stdout);
+                       i = lines;
+               }
+               fputs(buf, stdout);
+       }
+       fclose(fp);
+
+       if (lines) {
+               char key;
+               fputs("--- (END) Press Any Key ---", stdout);
+               fflush(stdout);
+               read(STDIN_FILENO, &key, 1);
+               fputs("\n", stdout);
+               tcsetattr(1, TCSADRAIN, &orig);
+       }
+
+       return 0;
+}
+
 void
 instructions(void)
 {
@@ -870,33 +924,10 @@ instructions(void)
        if (!getans("Instructions? (y-n) "))
                return;
 
-       if ((fd = open(_PATH_WUMPINFO, O_RDONLY)) == -1) {
+       if (pagefile(_PATH_WUMPINFO) == -1) {
                (void)printf(
 "Sorry, but the instruction file seems to have disappeared in a\n\
 puff of greasy black smoke! (poof)\n");
-               return;
-       }
-
-       if (!isatty(1))
-               pager = "/bin/cat";
-       else {
-               if (!(pager = getenv("PAGER")) || (*pager == 0))
-                       pager = _PATH_PAGER;
-       }
-       switch (pid = fork()) {
-       case 0: /* child */
-               if (dup2(fd, 0) == -1)
-                       err(1, "dup2");
-               (void)execl(_PATH_BSHELL, "sh", "-c", pager, (char *)NULL);
-               err(1, "exec sh -c %s", pager);
-               /* NOT REACHED */
-       case -1:
-               err(1, "fork");
-               /* NOT REACHED */
-       default:
-               (void)waitpid(pid, &status, 0);
-               close(fd);
-               break;
        }
 }
 

Reply via email to