2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * Pager: Routines to create a "more" running out of a particular file
12 * Copyright 1987, 1988 by MIT Student Information Processing Board
14 * For copyright information, see copyright.h.
17 #include "ss_internal.h"
18 #include "copyright.h"
21 #include <sys/types.h>
25 static char MORE
[] = "more";
26 extern char *_ss_pager_name
;
27 extern char *getenv();
30 * this needs a *lot* of work....
33 * handle SIGINT sensibly
34 * allow finer control -- put-page-break-here
43 if (pipe(filedes
) != 0)
46 switch((int) fork()) {
51 * Child; dup read half to 0, close all but 0, 1, and 2
53 if (dup2(filedes
[0], 0) == -1)
58 * Parent: close "read" side of pipe, return
61 (void) close(filedes
[0]);
65 #else /* don't fork */
69 fd
= open("/dev/tty", O_WRONLY
, 0);
82 * Close all fd's, excepting stdin/stdout/stderr
87 sa
.sa_handler
= SIG_DFL
;
88 sigemptyset(&sa
.sa_mask
);
90 sigaction(SIGINT
, &sa
, (struct sigaction
*)0);
92 (void) signal(SIGINT
, SIG_DFL
);
97 sigaddset(&mask
, SIGINT
);
98 sigprocmask(SIG_UNBLOCK
, &mask
, (sigset_t
*)0);
100 int mask
= sigblock(0);
101 mask
&= ~sigmask(SIGINT
);
105 if (_ss_pager_name
== (char *)NULL
) {
106 if ((_ss_pager_name
= getenv("PAGER")) == (char *)NULL
)
107 _ss_pager_name
= MORE
;
109 (void) execlp(_ss_pager_name
, _ss_pager_name
, (char *) NULL
);
111 /* minimal recovery if pager program isn't found */
114 while ((n
= read(0, buf
, 80)) > 0)
115 write(1, buf
, (unsigned) n
);