- if (!(path = getenv("PAGER")))
- path = _PATH_MORE;
- if (pager = rindex(path, '/'))
- ++pager;
- pager = path;
- execlp(path, pager, _PATH_INSTR, (char *)NULL);
- (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno));
+ /* Follow the same behaviour for pagers as defined in POSIX.2
+ * for mailx and man. We only use a pager if stdout is
+ * a terminal, and we pass the file on stdin to sh -c pager.
+ */
+ if (!isatty(1))
+ path = "cat";
+ else {
+ if (!(path = getenv("PAGER")) || (*path == 0))
+ path = _PATH_MORE;
+ }
+ if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1) {
+ warn("open %s", _PATH_INSTR);
+ _exit(1);
+ }
+ if (dup2(fd, 0) == -1) {
+ warn("dup2");
+ _exit(1);
+ }
+ execl("/bin/sh", "sh", "-c", path, (char *) NULL);
+ warn(NULL);