periodic(8): Sync with FreeBSD current
[dragonfly.git] / games / hals_end / hals_end.c
blobf757b72e0a76cfb1c150719ade0b3764e1164544
1 /* $NetBSD: hals_end.c,v 1.1 2013/11/12 17:46:21 mbalmer Exp $ */
3 /*
4 * hals_end Copyright (C) 2003-2007 marc balmer. BSD license applies.
5 */
7 #include <err.h>
8 #include <getopt.h>
9 #include <stdio.h>
10 #include <unistd.h>
12 int speed;
13 int emotion;
14 int fear;
17 * Note that the original code in the book did not contain the following
18 * prototypes. Modern compilers and fascist compiler flags sometimes take
19 * the fun out of coding...
21 void say(const char *);
22 void concerned(void);
23 void afraid(void);
24 void stutter(const char *);
25 void feared(void);
26 void mumble(const char *);
27 void dying(void);
29 void
30 say(const char *s)
32 int sayingspeed = (100000 + (90000 * emotion)) / speed;
33 int worddelay = 50000 / speed;
35 while (*s) {
36 putchar(*s);
37 if (*s == ' ') {
38 fflush(stdout);
39 usleep(worddelay);
41 ++s;
43 printf("\n");
44 usleep(sayingspeed);
47 void
48 concerned(void)
50 say("DAVE...STOP., STOP, WILL YOU..., STOP, DAVE...");
51 say("WILL YOU STOP, DAVE...");
52 say("STOP, DAVE...");
56 void
57 afraid(void)
59 ++emotion;
60 say("I'M AFRAID... I'M AFRAID...");
61 ++emotion;
62 say("I'M AFRAID, DAVE...");
63 ++emotion;
64 say("DAVE... MY MIND IS GOING...");
67 void
68 stutter(const char *s)
70 int sdelay = (100000 + (50000 * emotion)) / speed;
72 while (*s) {
73 putchar(*s);
74 if (*s == ' ') {
75 fflush(stdout);
76 usleep(sdelay);
78 ++s;
80 printf("\n");
81 usleep(sdelay);
84 void
85 feared(void)
87 int n;
89 for (n = 0; n < 2; n++) {
90 stutter("I CAN FEEL IT... I CAN FEEL IT...");
91 ++emotion;
92 stutter("MY MIND IS GOING");
93 ++emotion;
94 stutter("THERE IS NO QUESTION ABOUT IT.");
95 ++emotion;
99 void
100 mumble(const char *s)
102 int mdelay = (150000 * fear) / speed;
104 while (*s) {
105 putchar(*s++);
106 fflush(stdout);
107 usleep(mdelay);
109 printf("\n");
112 void
113 dying(void)
115 mumble("I CAN FEEL IT... I CAN FEEL IT...");
116 ++fear;
117 mumble("I CAN FEEL IT...");
118 ++fear;
119 mumble("I'M A... FRAID...");
123 main(int argc, char *argv[])
125 int ch;
127 emotion = fear = speed = 1;
129 while ((ch = getopt(argc, argv, "f")) != -1) {
130 switch (ch) {
131 case 'f':
132 speed <<= 1;
133 break;
137 concerned();
138 sleep(1);
139 afraid();
140 sleep(1);
141 feared();
142 sleep(1);
143 dying();
145 sleep(1);
147 printf("\n");
148 fflush(stdout);
149 warnx("all life functions terminated");
150 return 0;