bill.c revision 1.4 1 1.4 mrg /* $NetBSD: bill.c,v 1.4 1996/05/22 00:34:35 mrg Exp $ */
2 1.3 cgd
3 1.3 cgd /*-
4 1.3 cgd * Copyright (c) 1991 The Regents of the University of California.
5 1.3 cgd * All rights reserved.
6 1.3 cgd *
7 1.3 cgd * Redistribution and use in source and binary forms, with or without
8 1.3 cgd * modification, are permitted provided that the following conditions
9 1.3 cgd * are met:
10 1.3 cgd * 1. Redistributions of source code must retain the above copyright
11 1.3 cgd * notice, this list of conditions and the following disclaimer.
12 1.3 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.3 cgd * notice, this list of conditions and the following disclaimer in the
14 1.3 cgd * documentation and/or other materials provided with the distribution.
15 1.3 cgd * 3. All advertising materials mentioning features or use of this software
16 1.3 cgd * must display the following acknowledgement:
17 1.3 cgd * This product includes software developed by the University of
18 1.3 cgd * California, Berkeley and its contributors.
19 1.3 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.3 cgd * may be used to endorse or promote products derived from this software
21 1.3 cgd * without specific prior written permission.
22 1.3 cgd *
23 1.3 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.3 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.3 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.3 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.3 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.3 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.3 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.3 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.3 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.3 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.3 cgd * SUCH DAMAGE.
34 1.3 cgd */
35 1.3 cgd
36 1.2 mycroft #ifndef lint
37 1.3 cgd #if 0
38 1.3 cgd static char sccsid[] = "@(#)bill.c 5.2 (Berkeley) 5/28/91";
39 1.3 cgd #else
40 1.4 mrg static char rcsid[] = "$NetBSD: bill.c,v 1.4 1996/05/22 00:34:35 mrg Exp $";
41 1.3 cgd #endif
42 1.2 mycroft #endif /* not lint */
43 1.2 mycroft
44 1.3 cgd #include <sys/file.h>
45 1.3 cgd #include <sys/wait.h>
46 1.3 cgd #include <string.h>
47 1.3 cgd #include <stdlib.h>
48 1.3 cgd #include <stdio.h>
49 1.3 cgd #include <unistd.h>
50 1.1 cgd #include "header.h"
51 1.3 cgd
52 1.3 cgd /* bill.c Larn is copyrighted 1986 by Noah Morgan. */
53 1.3 cgd
54 1.3 cgd char *mail[] = {
55 1.3 cgd "From: the LRS (Larn Revenue Service)\n",
56 1.3 cgd "~s undeclared income\n",
57 1.3 cgd "\n We have heard you survived the caverns of Larn. Let me be the",
58 1.3 cgd "\nfirst to congratulate you on your success. It was quite a feat.",
59 1.3 cgd "\nIt was also very profitable for you...",
60 1.3 cgd "\n\n The Dungeon Master has informed us that you brought",
61 1.3 cgd "1",
62 1.3 cgd "\ncounty of Larn is in dire need of funds, we have spared no time",
63 1.3 cgd "2",
64 1.3 cgd "\nof this notice, and is due within 5 days. Failure to pay will",
65 1.3 cgd "\nmean penalties. Once again, congratulations, We look forward",
66 1.3 cgd "\nto your future successful expeditions.\n",
67 1.3 cgd NULL,
68 1.3 cgd "From: His Majesty King Wilfred of Larndom\n",
69 1.3 cgd "~s a noble deed\n",
70 1.3 cgd "\n I have heard of your magnificent feat, and I, King Wilfred,",
71 1.3 cgd "\nforthwith declare today to be a national holiday. Furthermore,",
72 1.3 cgd "\nhence three days, ye be invited to the castle to receive the",
73 1.3 cgd "\nhonour of Knight of the realm. Upon thy name shall it be written...",
74 1.3 cgd "\n\nBravery and courage be yours.",
75 1.3 cgd "\n\nMay you live in happiness forevermore...\n",
76 1.3 cgd NULL,
77 1.3 cgd "From: Count Endelford\n",
78 1.3 cgd "~s You Bastard!\n",
79 1.3 cgd "\n I have heard (from sources) of your journey. Congratulations!",
80 1.3 cgd "\nYou Bastard! With several attempts I have yet to endure the",
81 1.3 cgd " caves,\nand you, a nobody, makes the journey! From this time",
82 1.3 cgd " onward, bewarned\nupon our meeting you shall pay the price!\n",
83 1.3 cgd NULL,
84 1.3 cgd "From: Mainair, Duke of Larnty\n",
85 1.3 cgd "~s High Praise\n",
86 1.3 cgd "\n With certainty, a hero I declare to be amongst us! A nod of",
87 1.3 cgd "\nfavour I send to thee. Me thinks Count Endelford this day of",
88 1.3 cgd "\nright breath'eth fire as of dragon of whom ye are slayer. I",
89 1.3 cgd "\nyearn to behold his anger and jealously. Should ye choose to",
90 1.3 cgd "\nunleash some of thy wealth upon those who be unfortunate, I,",
91 1.3 cgd "\nDuke Mainair, shall equal thy gift also.\n",
92 1.3 cgd NULL,
93 1.3 cgd "From: St. Mary's Children's Home\n",
94 1.3 cgd "~s these poor children\n",
95 1.3 cgd "\n News of your great conquests has spread to all of Larndom.",
96 1.3 cgd "\nMight I have a moment of a great adventurers's time? We here at",
97 1.3 cgd "\nSt. Mary's Children's Home are very poor, and many children are",
98 1.3 cgd "\nstarving. Disease is widespread and very often fatal without",
99 1.3 cgd "\ngood food. Could you possibly find it in your heart to help us",
100 1.3 cgd "\nin our plight? Whatever you could give will help much.",
101 1.3 cgd "\n(your gift is tax deductible)\n",
102 1.3 cgd NULL,
103 1.3 cgd "From: The National Cancer Society of Larn\n",
104 1.3 cgd "~s hope\n",
105 1.3 cgd "\nCongratulations on your successful expedition. We are sure much",
106 1.3 cgd "\ncourage and determination were needed on your quest. There are",
107 1.3 cgd "\nmany though, that could never hope to undertake such a journey",
108 1.3 cgd "\ndue to an enfeebling disease -- cancer. We at the National",
109 1.3 cgd "\nCancer Society of Larn wish to appeal to your philanthropy in",
110 1.3 cgd "\norder to save many good people -- possibly even yourself a few",
111 1.3 cgd "\nyears from now. Much work needs to be done in researching this",
112 1.3 cgd "\ndreaded disease, and you can help today. Could you please see it",
113 1.3 cgd "\nin your heart to give generously? Your continued good health",
114 1.3 cgd "\ncan be your everlasting reward.\n",
115 1.3 cgd NULL
116 1.3 cgd };
117 1.1 cgd
118 1.1 cgd /*
119 1.1 cgd * function to mail the letters to the player if a winner
120 1.1 cgd */
121 1.3 cgd
122 1.3 cgd void
123 1.1 cgd mailbill()
124 1.3 cgd {
125 1.1 cgd register int i;
126 1.3 cgd char fname[32];
127 1.1 cgd char buf[128];
128 1.3 cgd char **cp;
129 1.3 cgd int fd;
130 1.3 cgd
131 1.3 cgd wait(0);
132 1.3 cgd if (fork() == 0) {
133 1.1 cgd resetscroll();
134 1.3 cgd cp = mail;
135 1.3 cgd sprintf(fname, "/tmp/#%dlarnmail", getpid());
136 1.3 cgd for (i = 0; i < 6; i++) {
137 1.4 mrg if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT,
138 1.4 mrg 0666)) == -1)
139 1.3 cgd exit(0);
140 1.3 cgd while (*cp != NULL) {
141 1.3 cgd if (*cp[0] == '1') {
142 1.3 cgd sprintf(buf, "\n%d gold pieces back with you from your journey. As the",
143 1.3 cgd (long)c[GOLD]);
144 1.3 cgd write(fd, buf, strlen(buf));
145 1.3 cgd } else if (*cp[0] == '2') {
146 1.3 cgd sprintf(buf, "\nin preparing your tax bill. You owe %d gold pieces as", (long)c[GOLD]*TAXRATE);
147 1.3 cgd write(fd, buf, strlen(buf));
148 1.3 cgd } else
149 1.3 cgd write(fd, *cp, strlen(*cp));
150 1.3 cgd cp++;
151 1.3 cgd }
152 1.3 cgd cp++;
153 1.3 cgd
154 1.3 cgd close(fd);
155 1.3 cgd sprintf(buf, "mail -I %s < %s > /dev/null",
156 1.3 cgd loginname, fname);
157 1.3 cgd system(buf);
158 1.3 cgd unlink(fname);
159 1.1 cgd }
160 1.1 cgd }
161 1.3 cgd exit(0);
162 1.3 cgd }
163