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