|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 2628 (0xa44)
Types: TextFile
Names: »getmore.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
└─⟦this⟧ »cph85dist/rman/client/getmore.c«
#ifndef lint
static char RCSid[] = "$Header: getmore.c,v 1.5 85/08/27 15:04:44 broome Exp $";
#endif
/*
* $Log: getmore.c,v $
* Revision 1.5 85/08/27 15:04:44 broome
* Final cleanup before sending out.
*
* Revision 1.4 85/08/03 02:35:50 broome
* Changed to use buffered i/o on the temp file - fewer system calls that way.
*
* Revision 1.3 85/07/13 16:07:14 broome
* Fixed for installations where man is setuid to root.
*
* Revision 1.2 85/07/04 20:18:13 broome
*/
#include <stdio.h>
#define eq(a,b) (strcmp (a, b) == 0)
/*
* Get the text from the socket into the temp file
* and invoke ``more''.
*/
getmore ()
{
extern char fname[]; /* name of temp file */
extern FILE *tfp; /* temp file pointer */
extern FILE *sock_rp; /* socket read pointer */
extern char *pager; /* name of output paginator */
char line[BUFSIZ]; /* input buffer */
int pid; /* pid of `more' subprocess */
int lines; /* number of lines fetched */
int more = 1; /* more lines left to fetch */
fseek (tfp, 0L, 0); /* rewind the temp file */
ftruncate (fileno (tfp), 0L); /* and zap the contents */
/*
* We get the first 66 lines (one page) into the temp
* file before forking and invoking more on the temp file.
*/
for (lines = 0; lines < 66; lines++) { /* get the first page or so */
fgets (line, BUFSIZ, sock_rp);
if (eq (line, ".\r\n")) { /* end of the file */
more = 0;
break;
}
(void) fputs (line, tfp);
}
(void) fflush (tfp);
/*
* We now have the first screenful, so start up more..
*/
switch (pid = fork ()) {
case -1: perror ("cannot fork"); return;
case 0:
#ifdef SETUID
setuid (getuid ()); /* running as root? */
#endif
execlp (pager, pager, "-s", fname, 0);
perror (pager);
return;
default: if (more) /* still have more lines to fetch */
while (fgets (line, BUFSIZ, sock_rp)) {
if (eq (line, ".\r\n"))
break;
(void) fputs (line, tfp);
if (++lines % 5 == 0) /* flush every 5 lines */
(void) fflush (tfp);
}
while (wait (0) != pid)
;
}
}