Headers cleanup.
Add revoke before shell exit. Fix mail sending procedure. Convert to random() Implement nap.
This commit is contained in:
parent
9f1630189e
commit
850b77e689
@ -37,17 +37,14 @@ static char sccsid[] = "@(#)bill.c 5.2 (Berkeley) 5/28/91";
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "header.h"
|
||||
|
||||
/* bill.c Larn is copyrighted 1986 by Noah Morgan. */
|
||||
|
||||
char *mail[] = {
|
||||
"From: the LRS (Larn Revenue Service)\n",
|
||||
"~s undeclared income\n",
|
||||
"From: dev-null (the LRS - Larn Revenue Service)\n",
|
||||
"Subject: undeclared income\n",
|
||||
"\n We have heard you survived the caverns of Larn. Let me be the",
|
||||
"\nfirst to congratulate you on your success. It was quite a feat.",
|
||||
"\nIt was also very profitable for you...",
|
||||
@ -59,8 +56,8 @@ char *mail[] = {
|
||||
"\nmean penalties. Once again, congratulations, We look forward",
|
||||
"\nto your future successful expeditions.\n",
|
||||
NULL,
|
||||
"From: His Majesty King Wilfred of Larndom\n",
|
||||
"~s a noble deed\n",
|
||||
"From: dev-null (His Majesty King Wilfred of Larndom)\n",
|
||||
"Subject: a noble deed\n",
|
||||
"\n I have heard of your magnificent feat, and I, King Wilfred,",
|
||||
"\nforthwith declare today to be a national holiday. Furthermore,",
|
||||
"\nhence three days, ye be invited to the castle to receive the",
|
||||
@ -68,15 +65,15 @@ char *mail[] = {
|
||||
"\n\nBravery and courage be yours.",
|
||||
"\n\nMay you live in happiness forevermore...\n",
|
||||
NULL,
|
||||
"From: Count Endelford\n",
|
||||
"~s You Bastard!\n",
|
||||
"From: dev-null (Count Endelford)\n",
|
||||
"Subject: You Bastard!\n",
|
||||
"\n I have heard (from sources) of your journey. Congratulations!",
|
||||
"\nYou Bastard! With several attempts I have yet to endure the",
|
||||
" caves,\nand you, a nobody, makes the journey! From this time",
|
||||
" onward, bewarned\nupon our meeting you shall pay the price!\n",
|
||||
NULL,
|
||||
"From: Mainair, Duke of Larnty\n",
|
||||
"~s High Praise\n",
|
||||
"From: dev-null (Mainair, Duke of Larnty)\n",
|
||||
"Subject: High Praise\n",
|
||||
"\n With certainty, a hero I declare to be amongst us! A nod of",
|
||||
"\nfavour I send to thee. Me thinks Count Endelford this day of",
|
||||
"\nright breath'eth fire as of dragon of whom ye are slayer. I",
|
||||
@ -84,8 +81,8 @@ char *mail[] = {
|
||||
"\nunleash some of thy wealth upon those who be unfortunate, I,",
|
||||
"\nDuke Mainair, shall equal thy gift also.\n",
|
||||
NULL,
|
||||
"From: St. Mary's Children's Home\n",
|
||||
"~s these poor children\n",
|
||||
"From: dev-null (St. Mary's Children's Home)\n",
|
||||
"Subject: these poor children\n",
|
||||
"\n News of your great conquests has spread to all of Larndom.",
|
||||
"\nMight I have a moment of a great adventurers's time? We here at",
|
||||
"\nSt. Mary's Children's Home are very poor, and many children are",
|
||||
@ -94,8 +91,8 @@ char *mail[] = {
|
||||
"\nin our plight? Whatever you could give will help much.",
|
||||
"\n(your gift is tax deductible)\n",
|
||||
NULL,
|
||||
"From: The National Cancer Society of Larn\n",
|
||||
"~s hope\n",
|
||||
"From: dev-null (The National Cancer Society of Larn)\n",
|
||||
"Subject: hope\n",
|
||||
"\nCongratulations on your successful expedition. We are sure much",
|
||||
"\ncourage and determination were needed on your quest. There are",
|
||||
"\nmany though, that could never hope to undertake such a journey",
|
||||
@ -129,7 +126,7 @@ mailbill()
|
||||
sprintf(fname, "/tmp/#%dlarnmail", getpid());
|
||||
for (i = 0; i < 6; i++) {
|
||||
if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT),
|
||||
0666) == -1)
|
||||
0660) == -1)
|
||||
exit(0);
|
||||
while (*cp != NULL) {
|
||||
if (*cp[0] == '1') {
|
||||
@ -146,7 +143,7 @@ mailbill()
|
||||
cp++;
|
||||
|
||||
close(fd);
|
||||
sprintf(buf, "mail -I %s < %s > /dev/null",
|
||||
sprintf(buf, "/usr/sbin/sendmail %s < %s > /dev/null",
|
||||
loginname, fname);
|
||||
system(buf);
|
||||
unlink(fname);
|
||||
|
@ -147,7 +147,7 @@ short lastpx,lastpy; /* 0 --- MAXX-1 or 0 --- MAXY-1 */
|
||||
short oldx,oldy;
|
||||
short lasthx=0,lasthy=0; /* location of monster last hit by player */
|
||||
short nobeep=0; /* true if program is not to beep */
|
||||
unsigned long randx=33601; /* the random number seed */
|
||||
/* unsigned long randx=33601; /* the random number seed */
|
||||
long initialtime=0; /* time playing began */
|
||||
long gtime=0; /* the clock for the game */
|
||||
long outstanding_taxes=0; /* present tax bill from score file */
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "header.h"
|
||||
extern int score[],srcount,dropflag;
|
||||
extern int random;/* the random number seed */
|
||||
extern short playerx,playery,lastnum;
|
||||
extern char cheat,level,monstnamelist[];
|
||||
extern char lastmonst[],*what[],*who[];
|
||||
@ -610,12 +609,12 @@ packweight()
|
||||
rnd(x)
|
||||
int x;
|
||||
{
|
||||
return((((randx=randx*1103515245+12345)>>7)%(x))+1);
|
||||
return((random()%x)+1);
|
||||
}
|
||||
|
||||
rund(x)
|
||||
int x;
|
||||
{
|
||||
return((((randx=randx*1103515245+12345)>>7)%(x)) );
|
||||
return(random()%x);
|
||||
}
|
||||
#endif MACRORND
|
||||
|
@ -1,5 +1,11 @@
|
||||
/* header.h Larn is copyrighted 1986 by Noah Morgan. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termcap.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAXLEVEL 11
|
||||
/* max # levels in the dungeon */
|
||||
#define MAXVLEVEL 3
|
||||
@ -345,17 +351,15 @@ extern short iarg[MAXX][MAXY],ivenarg[],lasthx,lasthy,lastnum,lastpx,lastpy;
|
||||
extern short nobeep,oldx,oldy,playerx,playery;
|
||||
extern int dayplay,enable_scroll,srcount,yrepcount,userid,wisid,lfd,fd;
|
||||
extern long initialtime,outstanding_taxes,skill[],gtime,c[],cbak[];
|
||||
extern unsigned long randx;
|
||||
extern struct cel *cell;
|
||||
extern struct monst monster[];
|
||||
extern struct sphere *spheres;
|
||||
extern struct _itm itm[];
|
||||
|
||||
char *fortune(),*getenv(),*getlogin(),*lgetw(),*lgetl(),*ctime();
|
||||
char *tmcapcnv(),*tgetstr(),*tgoto();
|
||||
long paytaxes(),lgetc(),lrint(),time();
|
||||
char *fortune(),*lgetw(),*lgetl();
|
||||
char *tmcapcnv();
|
||||
long paytaxes(),lgetc(),lrint();
|
||||
unsigned long readnum();
|
||||
void *malloc();
|
||||
|
||||
/* macro to create scroll #'s with probability of occurrence */
|
||||
#define newscroll() (scprob[rund(81)])
|
||||
@ -415,9 +419,10 @@ void *malloc();
|
||||
/* macro to output one byte to the output buffer */
|
||||
#define lprc(ch) ((lpnt>=lpend)?(*lpnt++ =(ch), lflush()):(*lpnt++ =(ch)))
|
||||
|
||||
#ifdef MACRORND
|
||||
extern unsigned long randx;
|
||||
/* macro to seed the random number generator */
|
||||
#define srand(x) (randx=x)
|
||||
#ifdef MACRORND
|
||||
/* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
|
||||
#define rnd(x) ((((randx=randx*1103515245+12345)>>7)%(x))+1)
|
||||
#define rund(x) ((((randx=randx*1103515245+12345)>>7)%(x)) )
|
||||
|
@ -157,7 +157,7 @@ newgame()
|
||||
{
|
||||
register long *p,*pe;
|
||||
for (p=c,pe=c+100; p<pe; *p++ =0);
|
||||
time(&initialtime); srand(initialtime);
|
||||
time(&initialtime); srandomdev();
|
||||
lcreat((char*)0); /* open buffering for output to terminal */
|
||||
}
|
||||
|
||||
@ -614,12 +614,12 @@ init_term()
|
||||
switch (tgetent(termbuf, term = getenv("TERM")))
|
||||
{
|
||||
case -1:
|
||||
write(2, "Cannot open termcap file.\n", 26); exit();
|
||||
write(2, "Cannot open termcap file.\n", 26); exit(1);
|
||||
case 0:
|
||||
write(2, "Cannot find entry of ", 21);
|
||||
write(2, term, strlen (term));
|
||||
write(2, " in termcap\n", 12);
|
||||
exit();
|
||||
exit(1);
|
||||
};
|
||||
|
||||
if (gtty(0, &tt) == 0)
|
||||
@ -640,19 +640,19 @@ init_term()
|
||||
{
|
||||
write(2, "Sorry, for a ",13); write(2, term, strlen(term));
|
||||
write(2, ", I can't find the cursor motion entry in termcap\n",50);
|
||||
exit();
|
||||
exit(1);
|
||||
}
|
||||
if (!CE) /* can't find clear to end of line entry */
|
||||
{
|
||||
write(2, "Sorry, for a ",13); write(2, term, strlen(term));
|
||||
write(2,", I can't find the clear to end of line entry in termcap\n",57);
|
||||
exit();
|
||||
exit(1);
|
||||
}
|
||||
if (!CL) /* can't find clear entire screen entry */
|
||||
{
|
||||
write(2, "Sorry, for a ",13); write(2, term, strlen(term));
|
||||
write(2, ", I can't find the clear entire screen entry in termcap\n",56);
|
||||
exit();
|
||||
exit(1);
|
||||
}
|
||||
if ((outbuf=malloc(BUFBIG+16))==0) /* get memory for decoded output buffer*/
|
||||
{
|
||||
@ -852,15 +852,15 @@ lflush()
|
||||
#endif VT100
|
||||
|
||||
#ifndef VT100
|
||||
static int index=0;
|
||||
static int pindex=0;
|
||||
/*
|
||||
* putchar(ch) Print one character in decoded output buffer.
|
||||
*/
|
||||
int putchar(c)
|
||||
int c;
|
||||
{
|
||||
outbuf[index++] = c;
|
||||
if (index >= BUFBIG) flush_buf();
|
||||
outbuf[pindex++] = c;
|
||||
if (pindex >= BUFBIG) flush_buf();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -868,8 +868,8 @@ int c;
|
||||
*/
|
||||
flush_buf()
|
||||
{
|
||||
if (index) write(lfd, outbuf, index);
|
||||
index = 0;
|
||||
if (pindex) write(lfd, outbuf, pindex);
|
||||
pindex = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -58,7 +58,7 @@ main(argc,argv)
|
||||
if ((ptr = getenv("LOGNAME")) == 0)
|
||||
{
|
||||
noone: write(2, "Can't find your logname. Who Are You?\n",39);
|
||||
exit();
|
||||
exit(1);
|
||||
}
|
||||
if (ptr==0) goto noone;
|
||||
if (strlen(ptr)==0) goto noone;
|
||||
@ -93,7 +93,7 @@ main(argc,argv)
|
||||
if (j)
|
||||
{
|
||||
lprcat("Sorry, Larn needs a VT100 family terminal for all it's features.\n"); lflush();
|
||||
exit();
|
||||
exit(1);
|
||||
}
|
||||
#endif VT100
|
||||
|
||||
@ -111,12 +111,12 @@ main(argc,argv)
|
||||
if (argv[i][0] == '-')
|
||||
switch(argv[i][1])
|
||||
{
|
||||
case 's': showscores(); exit(); /* show scoreboard */
|
||||
case 's': showscores(); exit(0); /* show scoreboard */
|
||||
|
||||
case 'l': /* show log file */
|
||||
diedlog(); exit();
|
||||
diedlog(); exit(0);
|
||||
|
||||
case 'i': showallscores(); exit(); /* show all scoreboard */
|
||||
case 'i': showallscores(); exit(0); /* show all scoreboard */
|
||||
|
||||
case 'c': /* anyone with password can create scoreboard */
|
||||
lprcat("Preparing to initialize the scoreboard.\n");
|
||||
@ -124,7 +124,7 @@ main(argc,argv)
|
||||
{
|
||||
makeboard(); lprc('\n'); showscores();
|
||||
}
|
||||
exit();
|
||||
exit(0);
|
||||
|
||||
case 'n': /* no welcome msg */ nowelcome=1; argv[i][0]=0; break;
|
||||
|
||||
@ -134,12 +134,12 @@ main(argc,argv)
|
||||
break;
|
||||
|
||||
case 'h': /* print out command line arguments */
|
||||
write(1,cmdhelp,sizeof(cmdhelp)); exit();
|
||||
write(1,cmdhelp,sizeof(cmdhelp)); exit(0);
|
||||
|
||||
case 'o': /* specify a .larnopts filename */
|
||||
strncpy(optsfile,argv[i]+2,127); break;
|
||||
|
||||
default: printf("Unknown option <%s>\n",argv[i]); exit();
|
||||
default: printf("Unknown option <%s>\n",argv[i]); exit(1);
|
||||
};
|
||||
|
||||
if (argv[i][0] == '+')
|
||||
@ -161,7 +161,7 @@ main(argc,argv)
|
||||
#else UIDSCORE
|
||||
userid = getplid(logname); /* obtain the players id number */
|
||||
#endif UIDSCORE
|
||||
if (userid < 0) { write(2,"Can't obtain playerid\n",22); exit(); }
|
||||
if (userid < 0) { write(2,"Can't obtain playerid\n",22); exit(1); }
|
||||
|
||||
#ifdef HIDEBYLINK
|
||||
/*
|
||||
|
@ -17,7 +17,11 @@ nap(x)
|
||||
{
|
||||
if (x<=0) return; /* eliminate chance for infinite loop */
|
||||
lflush();
|
||||
#if 0
|
||||
if (x > 999) sleep(x/1000); else napms(x);
|
||||
#else
|
||||
usleep(x*1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef NONAP
|
||||
|
@ -487,7 +487,7 @@ died(x)
|
||||
clearvt100(); lflush(); f=0;
|
||||
if (ckpflag) unlink(ckpfile); /* remove checkpoint file if used */
|
||||
if (x<0) { f++; x = -x; } /* if we are not to display the scores */
|
||||
if ((x == 300) || (x == 257)) exit(); /* for quick exit or saved game */
|
||||
if ((x == 300) || (x == 257)) exit(0); /* for quick exit or saved game */
|
||||
if (x == 263) win = 1; else win = 0;
|
||||
c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0;
|
||||
/* now enter the player at the end of the scoreboard */
|
||||
@ -504,7 +504,7 @@ died(x)
|
||||
{
|
||||
lcreat((char*)0);
|
||||
lprcat("\nCan't open record file: I can't post your score.\n");
|
||||
sncbr(); resetscroll(); lflush(); exit();
|
||||
sncbr(); resetscroll(); lflush(); exit(1);
|
||||
}
|
||||
chmod(logfile,0660);
|
||||
}
|
||||
@ -541,9 +541,9 @@ died(x)
|
||||
if (sortboard()) scorerror = writeboard();
|
||||
}
|
||||
}
|
||||
if ((x==256) || (x==257) || (f != 0)) exit();
|
||||
if ((x==256) || (x==257) || (f != 0)) exit(0);
|
||||
if (scorerror == 0) showscores(); /* if we updated the scoreboard */
|
||||
if (x == 263) mailbill(); exit();
|
||||
if (x == 263) mailbill(); exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -40,7 +40,7 @@ yylex()
|
||||
savegame(ckpfile);
|
||||
#else
|
||||
wait(0); /* wait for other forks to finish */
|
||||
if (fork() == 0) { savegame(ckpfile); exit(); }
|
||||
if (fork() == 0) { savegame(ckpfile); exit(0); }
|
||||
#endif
|
||||
|
||||
|
||||
@ -71,7 +71,9 @@ yylex()
|
||||
resetscroll(); clear(); /* scrolling region, home, clear, no attributes */
|
||||
if ((ic=fork())==0) /* child */
|
||||
{
|
||||
execl("/bin/csh",0); exit();
|
||||
/* revoke */
|
||||
setgid(getgid());
|
||||
execl("/bin/csh",0); exit(1);
|
||||
}
|
||||
wait(0);
|
||||
if (ic<0) /* error */
|
||||
|
Loading…
Reference in New Issue
Block a user