|
|
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 m
Length: 1655 (0x677)
Types: TextFile
Names: »more.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Gb/more.c.orig«
#include <stdio.h>
#include <sys/file.h>
#include <sgtty.h>
char *doc_directory = "/b/o/therat/k";
main(c, v)
int c;
char **v;
{
while (*(++v))
doc(*v);
}
doc(s)
char *s;
{
char filename[128], tmpfile[128];
int fd, pid;
long t;
sprintf(filename, "%s/%s.Z", doc_directory, s);
/* could stat the file here to make sure it's there */
time(&t);
sprintf(tmpfile, "/usr/tmp/#GBtrash%05d", (t >> 4) & 0x7fff);
fd = open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC, 0600);
if (fd < 0) {
fprintf(stderr, "doc(): %s: ", filename);
perror("open failed");
return;
}
switch (pid = fork()) {
case -1 :
perror("doc(): fork for zcat failed");
break;
case 0 :
dup2(fd, 1);
execl("/usr/ucb/zcat", "zcat", filename, 0);
perror("doc(): execl for zcat failed");
default :
while (wait(0) != pid)
;
}
close(fd);
page(tmpfile);
unlink(tmpfile);
}
page(file)
char *file;
{
char buf[4096];
FILE *fp;
int line;
fp = fopen(file, "r");
if (!fp) {
fprintf(stderr, "page(): %s: ", file);
perror("open failed");
return;
}
while (fgets(buf, sizeof(buf), fp)) {
++line;
fputs(buf, stdout);
if (line == 23) {
char ch;
fputs(" -- more -- ", stdout);
fflush(stdout);
do
ch = get_a_char();
while (ch != ' ');
fputs("\b\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b", stdout);
line = 0;
}
}
fclose(fp);
}
get_a_char()
{
struct sgttyb foo, bar;
char c;
ioctl(0, TIOCGETP, &foo);
bar = foo;
foo.sg_flags |= CBREAK;
foo.sg_flags &= ~ECHO;
ioctl(0, TIOCSETN, &foo);
c = getchar();
/* while (!read(0, &c, 1)) */
/* ; */
ioctl(0, TIOCSETN, &bar);
return c;
}