diff options
author | B. Watson <yalhcru@gmail.com> | 2015-05-07 16:32:32 -0400 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2015-05-07 16:32:32 -0400 |
commit | 013ac7742311556022304e8b30ca170d48b3a016 (patch) | |
tree | 53faa33e75991363f1a6dcc7edc83a66b70e6995 /hals_end/hals_end.c | |
download | bsd-games-extra-013ac7742311556022304e8b30ca170d48b3a016.tar.gz |
initial commit
Diffstat (limited to 'hals_end/hals_end.c')
-rw-r--r-- | hals_end/hals_end.c | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/hals_end/hals_end.c b/hals_end/hals_end.c new file mode 100644 index 0000000..c6b408d --- /dev/null +++ b/hals_end/hals_end.c @@ -0,0 +1,151 @@ +/* $NetBSD: hals_end.c,v 1.1 2013/11/12 17:46:21 mbalmer Exp $ */ + +/* + * hals_end Copyright (C) 2003-2007 marc balmer. BSD license applies. + */ + +#include <err.h> +#include <getopt.h> +#include <stdio.h> +#include <unistd.h> + +int speed; +int emotion; +int fear; + +/* + * Note that the original code in the book did not contain the following + * prototypes. Modern compilers and fascist compiler flags sometimes take + * the fun out of coding... + */ +void say(const char *); +void concerned(void); +void afraid(void); +void stutter(const char *); +void feared(void); +void mumble(const char *); +void dying(void); + +void +say(const char *s) +{ + int sayingspeed = (100000 + (90000 * emotion)) / speed; + int worddelay = 50000 / speed; + + while (*s) { + putchar(*s); + if (*s == ' ') { + fflush(stdout); + usleep(worddelay); + } + ++s; + } + printf("\n"); + usleep(sayingspeed); +} + +void +concerned(void) +{ + say("DAVE...STOP., STOP, WILL YOU..., STOP, DAVE..."); + say("WILL YOU STOP, DAVE..."); + say("STOP, DAVE..."); +} + + +void +afraid(void) +{ + ++emotion; + say("I'M AFRAID... I'M AFRAID..."); + ++emotion; + say("I'M AFRAID, DAVE..."); + ++emotion; + say("DAVE... MY MIND IS GOING..."); +} + +void +stutter(const char *s) +{ + int sdelay = (100000 + (50000 * emotion)) / speed; + + while (*s) { + putchar(*s); + if (*s == ' ') { + fflush(stdout); + usleep(sdelay); + } + ++s; + } + printf("\n"); + usleep(sdelay); +} + +void +feared(void) +{ + int n; + + for (n = 0; n < 2; n++) { + stutter("I CAN FEEL IT... I CAN FEEL IT..."); + ++emotion; + stutter("MY MIND IS GOING"); + ++emotion; + stutter("THERE IS NO QUESTION ABOUT IT."); + ++emotion; + } +} + +void +mumble(const char *s) +{ + int mdelay = (150000 * fear) / speed; + + while (*s) { + putchar(*s++); + fflush(stdout); + usleep(mdelay); + } + printf("\n"); +} + +void +dying(void) +{ + mumble("I CAN FEEL IT... I CAN FEEL IT..."); + ++fear; + mumble("I CAN FEEL IT..."); + ++fear; + mumble("I'M A... FRAID..."); +} + +int +main(int argc, char *argv[]) +{ + int ch; + + emotion = fear = speed = 1; + + while ((ch = getopt(argc, argv, "f")) != -1) { + switch (ch) { + case 'f': + speed <<= 1; + break; + } + } + + concerned(); + sleep(1); + afraid(); + sleep(1); + feared(); + sleep(1); + dying(); + + sleep(1); + + printf("\n"); + fflush(stdout); + warnx("all life functions terminated"); + return 0; +} |