1*49917Ssellgren /*-
2*49917Ssellgren * Copyright (c) 1991 The Regents of the University of California.
3*49917Ssellgren * All rights reserved.
4*49917Ssellgren *
5*49917Ssellgren * %sccs.include.redist.c%
636979Sbostic */
736979Sbostic
8*49917Ssellgren #ifndef lint
9*49917Ssellgren static char sccsid[] = "@(#)bill.c 5.2 (Berkeley) 05/28/91";
10*49917Ssellgren #endif /* not lint */
1136979Sbostic
12*49917Ssellgren #include <sys/file.h>
13*49917Ssellgren #include <sys/wait.h>
14*49917Ssellgren #include <string.h>
15*49917Ssellgren #include <stdlib.h>
16*49917Ssellgren #include <stdio.h>
17*49917Ssellgren #include <unistd.h>
18*49917Ssellgren #include "header.h"
1936979Sbostic
20*49917Ssellgren /* bill.c Larn is copyrighted 1986 by Noah Morgan. */
2136979Sbostic
22*49917Ssellgren char *mail[] = {
23*49917Ssellgren "From: the LRS (Larn Revenue Service)\n",
24*49917Ssellgren "~s undeclared income\n",
25*49917Ssellgren "\n We have heard you survived the caverns of Larn. Let me be the",
26*49917Ssellgren "\nfirst to congratulate you on your success. It was quite a feat.",
27*49917Ssellgren "\nIt was also very profitable for you...",
28*49917Ssellgren "\n\n The Dungeon Master has informed us that you brought",
29*49917Ssellgren "1",
30*49917Ssellgren "\ncounty of Larn is in dire need of funds, we have spared no time",
31*49917Ssellgren "2",
32*49917Ssellgren "\nof this notice, and is due within 5 days. Failure to pay will",
33*49917Ssellgren "\nmean penalties. Once again, congratulations, We look forward",
34*49917Ssellgren "\nto your future successful expeditions.\n",
35*49917Ssellgren NULL,
36*49917Ssellgren "From: His Majesty King Wilfred of Larndom\n",
37*49917Ssellgren "~s a noble deed\n",
38*49917Ssellgren "\n I have heard of your magnificent feat, and I, King Wilfred,",
39*49917Ssellgren "\nforthwith declare today to be a national holiday. Furthermore,",
40*49917Ssellgren "\nhence three days, ye be invited to the castle to receive the",
41*49917Ssellgren "\nhonour of Knight of the realm. Upon thy name shall it be written...",
42*49917Ssellgren "\n\nBravery and courage be yours.",
43*49917Ssellgren "\n\nMay you live in happiness forevermore...\n",
44*49917Ssellgren NULL,
45*49917Ssellgren "From: Count Endelford\n",
46*49917Ssellgren "~s You Bastard!\n",
47*49917Ssellgren "\n I have heard (from sources) of your journey. Congratulations!",
48*49917Ssellgren "\nYou Bastard! With several attempts I have yet to endure the",
49*49917Ssellgren " caves,\nand you, a nobody, makes the journey! From this time",
50*49917Ssellgren " onward, bewarned\nupon our meeting you shall pay the price!\n",
51*49917Ssellgren NULL,
52*49917Ssellgren "From: Mainair, Duke of Larnty\n",
53*49917Ssellgren "~s High Praise\n",
54*49917Ssellgren "\n With certainty, a hero I declare to be amongst us! A nod of",
55*49917Ssellgren "\nfavour I send to thee. Me thinks Count Endelford this day of",
56*49917Ssellgren "\nright breath'eth fire as of dragon of whom ye are slayer. I",
57*49917Ssellgren "\nyearn to behold his anger and jealously. Should ye choose to",
58*49917Ssellgren "\nunleash some of thy wealth upon those who be unfortunate, I,",
59*49917Ssellgren "\nDuke Mainair, shall equal thy gift also.\n",
60*49917Ssellgren NULL,
61*49917Ssellgren "From: St. Mary's Children's Home\n",
62*49917Ssellgren "~s these poor children\n",
63*49917Ssellgren "\n News of your great conquests has spread to all of Larndom.",
64*49917Ssellgren "\nMight I have a moment of a great adventurers's time? We here at",
65*49917Ssellgren "\nSt. Mary's Children's Home are very poor, and many children are",
66*49917Ssellgren "\nstarving. Disease is widespread and very often fatal without",
67*49917Ssellgren "\ngood food. Could you possibly find it in your heart to help us",
68*49917Ssellgren "\nin our plight? Whatever you could give will help much.",
69*49917Ssellgren "\n(your gift is tax deductible)\n",
70*49917Ssellgren NULL,
71*49917Ssellgren "From: The National Cancer Society of Larn\n",
72*49917Ssellgren "~s hope\n",
73*49917Ssellgren "\nCongratulations on your successful expedition. We are sure much",
74*49917Ssellgren "\ncourage and determination were needed on your quest. There are",
75*49917Ssellgren "\nmany though, that could never hope to undertake such a journey",
76*49917Ssellgren "\ndue to an enfeebling disease -- cancer. We at the National",
77*49917Ssellgren "\nCancer Society of Larn wish to appeal to your philanthropy in",
78*49917Ssellgren "\norder to save many good people -- possibly even yourself a few",
79*49917Ssellgren "\nyears from now. Much work needs to be done in researching this",
80*49917Ssellgren "\ndreaded disease, and you can help today. Could you please see it",
81*49917Ssellgren "\nin your heart to give generously? Your continued good health",
82*49917Ssellgren "\ncan be your everlasting reward.\n",
83*49917Ssellgren NULL
84*49917Ssellgren };
8536979Sbostic
8636979Sbostic /*
8736979Sbostic * function to mail the letters to the player if a winner
8836979Sbostic */
89*49917Ssellgren
90*49917Ssellgren void
mailbill()9136979Sbostic mailbill()
92*49917Ssellgren {
9336979Sbostic register int i;
94*49917Ssellgren char fname[32];
9536979Sbostic char buf[128];
96*49917Ssellgren char **cp;
97*49917Ssellgren int fd;
98*49917Ssellgren
99*49917Ssellgren wait(0);
100*49917Ssellgren if (fork() == 0) {
10136979Sbostic resetscroll();
102*49917Ssellgren cp = mail;
103*49917Ssellgren sprintf(fname, "/tmp/#%dlarnmail", getpid());
104*49917Ssellgren for (i = 0; i < 6; i++) {
105*49917Ssellgren if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT),
106*49917Ssellgren 0666) == -1)
107*49917Ssellgren exit(0);
108*49917Ssellgren while (*cp != NULL) {
109*49917Ssellgren if (*cp[0] == '1') {
110*49917Ssellgren sprintf(buf, "\n%d gold pieces back with you from your journey. As the",
111*49917Ssellgren (long)c[GOLD]);
112*49917Ssellgren write(fd, buf, strlen(buf));
113*49917Ssellgren } else if (*cp[0] == '2') {
114*49917Ssellgren sprintf(buf, "\nin preparing your tax bill. You owe %d gold pieces as", (long)c[GOLD]*TAXRATE);
115*49917Ssellgren write(fd, buf, strlen(buf));
116*49917Ssellgren } else
117*49917Ssellgren write(fd, *cp, strlen(*cp));
118*49917Ssellgren cp++;
119*49917Ssellgren }
120*49917Ssellgren cp++;
121*49917Ssellgren
122*49917Ssellgren close(fd);
123*49917Ssellgren sprintf(buf, "mail -I %s < %s > /dev/null",
124*49917Ssellgren loginname, fname);
125*49917Ssellgren system(buf);
126*49917Ssellgren unlink(fname);
12736979Sbostic }
12836979Sbostic }
129*49917Ssellgren exit(0);
130*49917Ssellgren }
131