From 4b63fa35138f68ea409314edaa5611d6d8843d3c Mon Sep 17 00:00:00 2001 From: hjp Date: Sun, 8 Oct 2000 21:33:04 +0000 Subject: [PATCH] Works, but is a bit slower than expected (Linux bug?). --- slowcat/.vimrc | 36 +++++++++++++++++++++++ slowcat/GNUmakefile | 13 +++++++++ slowcat/slowcat.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 slowcat/.vimrc create mode 100644 slowcat/GNUmakefile create mode 100644 slowcat/slowcat.c diff --git a/slowcat/.vimrc b/slowcat/.vimrc new file mode 100644 index 0000000..718e1ff --- /dev/null +++ b/slowcat/.vimrc @@ -0,0 +1,36 @@ +version 5.0 +set nocompatible +let cpo_save=&cpo +set cpo=B +map! +map! +map! +map! +map! +map! +map! +map! +map! +map! +map :cn +map +map +map +map +map +map +map +map +map +map +map!  }I\begin{yyplcwendO +map!  >I<yypa/O +let &cpo=cpo_save +unlet cpo_save +set autoindent +set exrc +set number +set ruler +set shiftwidth=4 +set showmatch +set textwidth=72 diff --git a/slowcat/GNUmakefile b/slowcat/GNUmakefile new file mode 100644 index 0000000..0232bd4 --- /dev/null +++ b/slowcat/GNUmakefile @@ -0,0 +1,13 @@ +include GNUmakevars +include GNUmakerules + +all: slowcat +install: $(BINDIR)/slowcat + +clean: + rm -f *.bak *.o core slowcat + +distclean: clean + rm -f *.d + +-include *.d diff --git a/slowcat/slowcat.c b/slowcat/slowcat.c new file mode 100644 index 0000000..1703f89 --- /dev/null +++ b/slowcat/slowcat.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include + +char *cmnd; + +static void usage(void) { + fprintf(stderr, "Usage: %s [-d delay] file ...\n", cmnd); + exit(1); +} + + +static void do_cat(FILE *fp, double delay) { + int c; + + while ((c = getc(fp)) != EOF) { + putchar(c); + usleep(delay * 1E6); + } +} + + +int main(int argc, char **argv) { + int rc = 0; + int c; + double delay = 0.5; + + cmnd = argv[0]; + + while ((c = getopt(argc, argv, "d:")) != EOF) { + char *p; + switch (c) { + case 'd': + p = NULL; + delay = strtod(optarg, &p); + if (!p || *p) usage(); + if (delay < 0 || delay > ULONG_MAX / 1E6) usage(); + break; + case '?': + usage(); + default: + assert(0); + } + } + + setvbuf(stdout, NULL, _IONBF, 0); + + if (optind == argc) { + do_cat(stdin, delay); + } else { + int i; + + for (i = optind; i < argc; i++) { + FILE *fp = fopen(argv[i], "r"); + if (fp) { + do_cat(fp, delay); + fclose(fp); + } else { + fprintf(stderr, "%s: cannot open %s for reading: %s\n", + argv[0], argv[i], strerror(errno)); + rc++; + } + } + } + return rc; +}