summaryrefslogtreecommitdiffstats
path: root/games/adventure
diff options
context:
space:
mode:
authorsteve <steve@FreeBSD.org>1999-04-19 03:59:02 +0000
committersteve <steve@FreeBSD.org>1999-04-19 03:59:02 +0000
commitd59a3ca336bac3dac6ad8918ff6cb28fcbbba718 (patch)
treec2b57d23128f242645f8e3e16274a587229383ec /games/adventure
parent390eb1b3d201760a5e8b76e2431c1f667648718f (diff)
downloadFreeBSD-src-d59a3ca336bac3dac6ad8918ff6cb28fcbbba718.zip
FreeBSD-src-d59a3ca336bac3dac6ad8918ff6cb28fcbbba718.tar.gz
Merge a bunch of cleanups from NetBSD.
PR: 8083 Submitted by: Stephen J. Roznowski <sjr@home.net> Obtained from: a whole slew of NetBSD PRs
Diffstat (limited to 'games/adventure')
-rw-r--r--games/adventure/crc.c10
-rw-r--r--games/adventure/done.c2
-rw-r--r--games/adventure/hdr.h5
-rw-r--r--games/adventure/init.c4
-rw-r--r--games/adventure/io.c56
-rw-r--r--games/adventure/main.c60
-rw-r--r--games/adventure/save.c4
-rw-r--r--games/adventure/setup.c17
-rw-r--r--games/adventure/subr.c29
-rw-r--r--games/adventure/vocab.c50
-rw-r--r--games/adventure/wizard.c29
11 files changed, 122 insertions, 144 deletions
diff --git a/games/adventure/crc.c b/games/adventure/crc.c
index f629325..4f3b971 100644
--- a/games/adventure/crc.c
+++ b/games/adventure/crc.c
@@ -39,9 +39,9 @@ static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 5/31/93";
static char ORIGINAL_sccsid[] = "@(#)crc.c 5.2 (Berkeley) 4/4/91";
#endif /* not lint */
-typedef unsigned long u_long;
+#include <sys/types.h>
-u_long crctab[] = {
+const u_long crctab[] = {
0x7fffffff,
0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e,
@@ -105,7 +105,7 @@ u_long crctab[] = {
*/
u_long crcval;
-int step;
+u_int step;
crc_start()
{
@@ -113,11 +113,11 @@ crc_start()
}
u_long crc(ptr, nr) /* Process nr bytes at a time; ptr points to them */
-char *ptr;
+const char *ptr;
int nr;
{
register int i;
- register char *p;
+ register const char *p;
while (nr > 0)
for (p = ptr; nr--; ++p)
diff --git a/games/adventure/done.c b/games/adventure/done.c
index dcd8e33..90352d6 100644
--- a/games/adventure/done.c
+++ b/games/adventure/done.c
@@ -109,6 +109,7 @@ int entry; /* entry=2 means goto 20000 */ /* 3=19000 */
}
+void
die(entry) /* label 90 */
int entry;
{ register int i;
@@ -135,5 +136,4 @@ int entry;
}
loc=3;
oldloc=loc;
- return(2000);
}
diff --git a/games/adventure/hdr.h b/games/adventure/hdr.h
index 6c8a1fd..d831a11 100644
--- a/games/adventure/hdr.h
+++ b/games/adventure/hdr.h
@@ -53,15 +53,16 @@
/* hdr.h: included by c advent files */
#include <sys/types.h>
+#include <signal.h>
int datfd; /* message file descriptor */
-int delhit;
+volatile sig_atomic_t delhit;
int yea;
extern char data_file[]; /* Virtual data file */
#define TAB 011
#define LF 012
-#define FLUSHLINE while (getchar()!='\n')
+#define FLUSHLINE do { int flushline_ch; while ((flushline_ch = getchar()) != EOF && flushline_ch != '\n'); } while (0)
#define FLUSHLF while (next()!=LF)
int loc,newloc,oldloc,oldlc2,wzdark,gaveup,kq,k,k2;
diff --git a/games/adventure/init.c b/games/adventure/init.c
index 249405e..9e81fb8 100644
--- a/games/adventure/init.c
+++ b/games/adventure/init.c
@@ -197,14 +197,14 @@ linkdata() /* secondary data manipulation */
trapdel() /* come here if he hits a del */
-{ delhit++; /* main checks, treats as QUIT */
+{ delhit = 1; /* main checks, treats as QUIT */
signal(2,trapdel); /* catch subsequent DELs */
}
startup()
{
- demo=Start(0);
+ demo=Start();
srandomdev();
hinted[3]=yes(65,1,0);
newloc=1;
diff --git a/games/adventure/io.c b/games/adventure/io.c
index df1236b..54e41b5 100644
--- a/games/adventure/io.c
+++ b/games/adventure/io.c
@@ -46,6 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <err.h>
getin(wrd1,wrd2) /* get command from user */
@@ -78,6 +79,9 @@ char **wrd1,**wrd2; /* no prompt, usually */
*s=0;
return;
}
+ case EOF:
+ printf("user closed input stream, quitting...\n");
+ exit(0);
default:
if (++numch>=MAXSTR) /* string too long */
{ printf("Give me a break!!\n");
@@ -90,27 +94,19 @@ char **wrd1,**wrd2; /* no prompt, usually */
}
}
-
-confirm(mesg) /* confirm irreversible action */
-char *mesg;
-{ register int result;
- printf("%s",mesg); /* tell him what he did */
- if (getchar()=='y') /* was his first letter a 'y'? */
- result=1;
- else result=0;
- FLUSHLINE;
- return(result);
-}
-
yes(x,y,z) /* confirm with rspeak */
int x,y,z;
{ register int result;
- register char ch;
+ int ch;
for (;;)
{ rspeak(x); /* tell him what we want*/
if ((ch=getchar())=='y')
result=TRUE;
else if (ch=='n') result=FALSE;
+ else if (ch == EOF) {
+ printf("user closed input stream, quitting...\n");
+ exit(0);
+ }
FLUSHLINE;
if (ch=='y'|| ch=='n') break;
printf("Please answer the question.\n");
@@ -123,12 +119,16 @@ int x,y,z;
yesm(x,y,z) /* confirm with mspeak */
int x,y,z;
{ register int result;
- register char ch;
+ int ch;
for (;;)
{ mspeak(x); /* tell him what we want*/
if ((ch=getchar())=='y')
result=TRUE;
else if (ch=='n') result=FALSE;
+ else if (ch == EOF) {
+ printf("user closed input stream, quitting...\n");
+ exit(0);
+ }
FLUSHLINE;
if (ch=='y'|| ch=='n') break;
printf("Please answer the question.\n");
@@ -144,8 +144,8 @@ char *inptr; /* Pointer into virtual disk */
int outsw = 0; /* putting stuff to data file? */
-char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
-char *tape = iotape; /* pointer to encryption tape */
+const char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
+const char *tape = iotape; /* pointer to encryption tape */
next() /* next virtual char, bump adr */
{
@@ -274,8 +274,7 @@ int sect;
break;
case 6: /* random messages */
if (oldloc>RTXSIZ)
- { printf("Too many random msgs\n");
- exit(0);
+ { errx(1, "Too many random msgs");
}
rtext[oldloc].seekadr=seekhere;
rtext[oldloc].txtlen=maystart-seekstart;
@@ -287,15 +286,13 @@ int sect;
break;
case 12: /* magic messages */
if (oldloc>MAGSIZ)
- { printf("Too many magic msgs\n");
- exit(0);
+ { errx(1, "Too many magic msgs");
}
mtext[oldloc].seekadr=seekhere;
mtext[oldloc].txtlen=maystart-seekstart;
break;
default:
- printf("rdesc called with bad section\n");
- exit(0);
+ errx(1, "rdesc called with bad section");
}
seekhere += maystart-seekstart;
}
@@ -331,13 +328,15 @@ rtrav() /* read travel table */
if (locc!=oldloc) /* getting a new entry */
{ t=travel[locc]=(struct travlist *) malloc(sizeof (struct travlist));
/* printf("New travel list for %d\n",locc); */
+ if (t == NULL)
+ errx(1, "Out of memory!");
entries=0;
oldloc=locc;
}
for (s=buf;; *s++) /* get the newloc number /ASCII */
if ((*s=next())==TAB || *s==LF) break;
*s=0;
- len=length(buf)-1; /* quad long number handling */
+ len=strlen(buf); /* quad long number handling */
/* printf("Newloc: %s (%d chars)\n",buf,len); */
if (len<4) /* no "m" conditions */
{ m=0;
@@ -349,7 +348,11 @@ rtrav() /* read travel table */
m=atoi(buf);
}
while (breakch!=LF) /* only do one line at a time */
- { if (entries++) t=t->next=(struct travlist *) malloc(sizeof (struct travlist));
+ { if (entries++) {
+ t=t->next=(struct travlist *) malloc(sizeof (struct travlist));
+ if (t == NULL)
+ errx(1, "Out of memory!");
+ }
t->tverb=rnum();/* get verb from the file */
t->tloc=n; /* table entry mod 1000 */
t->conditions=m;/* table entry / 1000 */
@@ -453,7 +456,7 @@ int msg;
speak(msg) /* read, decrypt, and print a message (not ptext) */
-struct text *msg;/* msg is a pointer to seek address and length of mess */
+const struct text *msg;/* msg is a pointer to seek address and length of mess */
{
register char *s, nonfirst;
@@ -486,7 +489,8 @@ int skip; /* assumes object 1 doesn't have prop 1, obj 2 no prop 2 &c*/
char *tbuf;
msg = &ptext[m];
- if ((tbuf=(char *) malloc(msg->txtlen + 1)) == 0) bug(108);
+ if ((tbuf=(char *) malloc(msg->txtlen + 1)) == 0)
+ errx(1, "Out of memory!");
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
s = tbuf;
diff --git a/games/adventure/main.c b/games/adventure/main.c
index 6f7277d..bdd37f7 100644
--- a/games/adventure/main.c
+++ b/games/adventure/main.c
@@ -51,6 +51,7 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
#include <sys/file.h>
#include <signal.h>
#include <stdio.h>
+#include <string.h>
#include "hdr.h"
@@ -68,7 +69,7 @@ char **argv;
setgid(getgid());
init(); /* Initialize everything */
- signal(2,trapdel);
+ signal(SIGINT,trapdel);
if (argc > 1) /* Restore file specified */
{ /* Restart is label 8305 (Fortran) */
@@ -76,15 +77,15 @@ char **argv;
switch(i)
{
case 0: /* The restore worked fine */
- yea=Start(0);
+ yea=Start();
k=null;
unlink(argv[1]);/* Don't re-use the save */
goto l8; /* Get where we're going */
case 1: /* Couldn't open it */
- exit(0); /* So give up */
+ exit(1); /* So give up */
case 2: /* Oops -- file was altered */
rspeak(202); /* You dissolve */
- exit(0); /* File could be non-adventure */
+ exit(1); /* File could be non-adventure */
} /* So don't unlink it. */
}
@@ -105,7 +106,7 @@ char **argv;
kk = &stext[loc];
if ((abb[loc]%abbnum)==0 || kk->seekadr==0)
kk = &ltext[loc];
- if (!forced(loc) && dark(0))
+ if (!forced(loc) && dark())
{ if (wzdark && pct(35))
{ die(90);
goto l2000;
@@ -118,7 +119,7 @@ char **argv;
if (forced(loc))
goto l8;
if (loc==33 && pct(25)&&!closng) rspeak(8);
- if (!dark(0))
+ if (!dark())
{ abb[loc]++;
for (i=atloc[loc]; i!=0; i=linkx[i]) /*2004 */
{ obj=i;
@@ -153,12 +154,12 @@ char **argv;
if (toting(i)&&prop[i]<0) /*2604 */
prop[i] = -1-prop[i];
}
- wzdark=dark(0); /* 2605 */
+ wzdark=dark(); /* 2605 */
if (knfloc>0 && knfloc!=loc) knfloc=1;
getin(&wd1,&wd2);
if (delhit) /* user typed a DEL */
{ delhit=0; /* reset counter */
- copystr("quit",wd1); /* pretend he's quitting*/
+ strcpy(wd1,"quit"); /* pretend he's quitting*/
*wd2=0;
}
l2608: if ((foobar = -foobar)>0) foobar=0; /* 2608 */
@@ -210,16 +211,16 @@ char **argv;
}
l19999: k=43;
if (liqloc(loc)==water) k=70;
- if (weq(wd1,"enter") &&
- (weq(wd2,"strea")||weq(wd2,"water")))
+ if (!strncmp(wd1,"enter",5) &&
+ (!strncmp(wd2,"strea",5)||!strncmp(wd2,"water",5)))
goto l2010;
- if (weq(wd1,"enter") && *wd2!=0) goto l2800;
- if ((!weq(wd1,"water")&&!weq(wd1,"oil"))
- || (!weq(wd2,"plant")&&!weq(wd2,"door")))
+ if (!strncmp(wd1,"enter",5) && *wd2!=0) goto l2800;
+ if ((strncmp(wd1,"water",5)&&strncmp(wd1,"oil",3))
+ || (strncmp(wd2,"plant",5)&&strncmp(wd2,"door",4)))
goto l2610;
- if (at(vocab(wd2,1))) copystr("pour",wd2);
+ if (at(vocab(wd2,1))) strcpy(wd2,"pour");
- l2610: if (weq(wd1,"west"))
+ l2610: if (!strncmp(wd1,"west",4))
if (++iwest==10) rspeak(17);
l2630: i=vocab(wd1,-1);
if (i== -1)
@@ -237,22 +238,19 @@ char **argv;
case 3: goto l4000;
case 4: goto l2010;
default:
- printf("Error 22\n");
- exit(0);
+ bug(22);
}
l8:
switch(march())
{ case 2: continue; /* i.e. goto l2 */
case 99:
- switch(die(99))
- { case 2000: goto l2000;
- default: bug(111);
- }
+ die(99);
+ goto l2000;
default: bug(110);
}
- l2800: copystr(wd2,wd1);
+ l2800: strcpy(wd1,wd2);
*wd2=0;
goto l2610;
@@ -355,7 +353,7 @@ char **argv;
if (here(tablet)) obj=obj*100+tablet;
if (here(messag)) obj=obj*100+messag;
if (closed&&toting(oyster)) obj=oyster;
- if (obj>100||obj==0||dark(0)) goto l8000;
+ if (obj>100||obj==0||dark()) goto l8000;
goto l9270;
case 30: /* suspend=8300 */
spk=201;
@@ -366,7 +364,7 @@ char **argv;
printf(" %d minutes before continuing.",latncy);
if (!yes(200,54,54)) goto l2012;
datime(&saved,&savet);
- ciao(argv[0]); /* Do we quit? */
+ ciao(); /* Do we quit? */
continue; /* Maybe not */
case 31: /* hours=8310 */
printf("Colossal cave is closed 9am-5pm Mon ");
@@ -418,7 +416,7 @@ char **argv;
l9080: if (!here(lamp)) goto l2011;
prop[lamp]=0;
rspeak(40);
- if (dark(0)) rspeak(16);
+ if (dark()) rspeak(16);
goto l2012;
case 9: /* wave */
@@ -443,7 +441,7 @@ char **argv;
default: bug(112);
}
l9130: case 13: /* pour */
- if (obj==bottle||obj==0) obj=liq(0);
+ if (obj==bottle||obj==0) obj=liq();
if (obj==0) goto l8000;
if (!toting(obj)) goto l2011;
spk=78;
@@ -472,10 +470,10 @@ char **argv;
||obj==bear) spk=71;
goto l2011;
l9150: case 15: /* 9150 - drink */
- if (obj==0&&liqloc(loc)!=water&&(liq(0)!=water
+ if (obj==0&&liqloc(loc)!=water&&(liq()!=water
||!here(bottle))) goto l8000;
if (obj!=0&&obj!=water) spk=110;
- if (spk==110||liq(0)!=water||!here(bottle))
+ if (spk==110||liq()!=water||!here(bottle))
goto l2011;
prop[bottle]=1;
place[water]=0;
@@ -494,7 +492,7 @@ char **argv;
default: bug(113);
}
case 19: case 20: /* 9190: find, invent */
- if (at(obj)||(liq(0)==obj&&at(bottle))
+ if (at(obj)||(liq()==obj&&at(bottle))
||k==liqloc(loc)) spk=94;
for (i=1; i<=5; i++)
if (dloc[i]==loc&&dflag>=2&&obj==dwarf)
@@ -522,7 +520,7 @@ char **argv;
rspeak(bonus);
done(2);
l9270: case 27: /* read */
- if (dark(0)) goto l5190;
+ if (dark()) goto l5190;
if (obj==magzin) spk=190;
if (obj==tablet) spk=196;
if (obj==messag) spk=191;
@@ -566,7 +564,7 @@ char **argv;
l5110: if (k!=dwarf) goto l5120;
for (i=1; i<=5; i++)
if (dloc[i]==loc&&dflag>=2) goto l5010;
- l5120: if ((liq(0)==k&&here(bottle))||k==liqloc(loc)) goto l5010;
+ l5120: if ((liq()==k&&here(bottle))||k==liqloc(loc)) goto l5010;
if (obj!=plant||!at(plant2)||prop[plant2]==0) goto l5130;
obj=plant2;
goto l5010;
diff --git a/games/adventure/save.c b/games/adventure/save.c
index 5277380..907d5bf 100644
--- a/games/adventure/save.c
+++ b/games/adventure/save.c
@@ -118,7 +118,7 @@ struct savestruct save_array[] =
};
save(outfile) /* Two passes on data: first to get checksum, second */
-char *outfile; /* to output the data using checksum to start random #s */
+const char *outfile; /* to output the data using checksum to start random #s */
{
FILE *out;
struct savestruct *p;
@@ -151,7 +151,7 @@ char *outfile; /* to output the data using checksum to start random #s */
}
restore(infile)
-char *infile;
+const char *infile;
{
FILE *in;
struct savestruct *p;
diff --git a/games/adventure/setup.c b/games/adventure/setup.c
index da1c09f..c67d4c7 100644
--- a/games/adventure/setup.c
+++ b/games/adventure/setup.c
@@ -59,15 +59,14 @@ static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
#include <stdio.h>
#include <stdlib.h>
+#include <err.h>
#include "hdr.h" /* SEED lives in there; keep them coordinated. */
-#define USAGE "Usage: setup file > data.c (file is typically glorkz)\n"
+#define USAGE "Usage: setup file > data.c (file is typically glorkz)"
#define YES 1
#define NO 0
-void fatal();
-
#define LINE 10 /* How many values do we get on a line? */
main(argc, argv)
@@ -77,10 +76,10 @@ char *argv[];
FILE *infile;
int c, count, linestart;
- if (argc != 2) fatal(USAGE);
+ if (argc != 2) errx(1, USAGE);
if ((infile = fopen(argv[1], "r")) == NULL)
- fatal("Can't read file %s.\n", argv[1]);
+ err(1, "Can't read file %s", argv[1]);
puts("/*\n * data.c: created by setup from the ascii data file.");
puts(SIG1);
puts(SIG2);
@@ -118,11 +117,3 @@ char *argv[];
fclose(infile);
exit(0);
}
-
-
-void fatal(format, arg)
-char *format;
-{
- fprintf(stderr, format, arg);
- exit(1);
-}
diff --git a/games/adventure/subr.c b/games/adventure/subr.c
index d723512..26d7c1e 100644
--- a/games/adventure/subr.c
+++ b/games/adventure/subr.c
@@ -43,6 +43,7 @@ static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93";
/* Re-coding of advent in C: subroutines from main */
#include <stdio.h>
+#include <string.h>
# include "hdr.h"
/* Statement functions */
@@ -69,7 +70,7 @@ int pbotl;
{ return((1-pbotl)*water+(pbotl/2)*(water+oil));
}
-liq(foo)
+liq()
{ register int i;
i=prop[bottle];
if (i>-1-i) return(liq2(i));
@@ -98,7 +99,7 @@ int locc;
return(FALSE);
}
-dark(foo)
+dark()
{ if ((cond[loc]%2)==0 && (prop[lamp]==0 || !here(lamp)))
return(TRUE);
return(FALSE);
@@ -373,6 +374,7 @@ trbridge() /* 30300 */
}
+int
badmove() /* 20 */
{ spk=12;
if (k>=43 && k<=50) spk=9;
@@ -383,16 +385,17 @@ badmove() /* 20 */
if (k==62||k==65) spk=42;
if (k==17) spk=80;
rspeak(spk);
- return(2);
}
+int
bug(n)
int n;
{ printf("Please tell jim@rand.org that fatal bug %d happened.\n",n);
- exit(0);
+ exit(1);
}
+void
checkhints() /* 2600 &c */
{ register int hint;
for (hint=4; hint<=hntmax; hint++)
@@ -433,7 +436,7 @@ checkhints() /* 2600 &c */
trsay() /* 9030 */
{ register int i;
- if (*wd2!=0) copystr(wd2,wd1);
+ if (*wd2!=0) strcpy(wd1,wd2);
i=vocab(wd1,-1);
if (i==62||i==65||i==71||i==2025)
{ *wd2=0;
@@ -454,7 +457,7 @@ trtake() /* 9010 */
if (obj==chain&&prop[bear]!=0) spk=170;
if (fixed[obj]!=0) return(2011);
if (obj==water||obj==oil)
- { if (here(bottle)&&liq(0)==obj)
+ { if (here(bottle)&&liq()==obj)
{ obj=bottle;
goto l9017;
}
@@ -484,14 +487,14 @@ l9017: if (holdng>=7)
l9014: if ((obj==bird||obj==cage)&&prop[bird]!=0)
carry(bird+cage-obj,loc);
carry(obj,loc);
- k=liq(0);
+ k=liq();
if (obj==bottle && k!=0) place[k] = -1;
return(2009);
}
dropper() /* 9021 */
-{ k=liq(0);
+{ k=liq();
if (k==obj) obj=bottle;
if (obj==bottle&&k!=0) place[k]=0;
if (obj==cage&&prop[bird]!=0) drop(bird,loc);
@@ -640,7 +643,7 @@ trkill() /* 9120 */
verb=0;
obj=0;
getin(&wd1,&wd2);
- if (!weq(wd1,"y")&&!weq(wd1,"yes")) return(2608);
+ if (strncmp(wd1,"y",1)&&strncmp(wd1,"yes",3)) return(2608);
pspeak(dragon,1);
prop[dragon]=2;
prop[rug]=0;
@@ -764,16 +767,17 @@ trfill() /* 9220 */
if (obj==0&&!here(bottle)) return(8000);
spk=107;
if (liqloc(loc)==0) spk=106;
- if (liq(0)!=0) spk=105;
+ if (liq()!=0) spk=105;
if (spk!=107) return(2011);
prop[bottle]=((cond[loc]%4)/2)*2;
- k=liq(0);
+ k=liq();
if (toting(bottle)) place[k]= -1;
if (k==oil) spk=108;
return(2011);
}
+void
closing() /* 10000 */
{ register int i;
@@ -795,10 +799,10 @@ closing() /* 10000 */
rspeak(129);
clock1 = -1;
closng=TRUE;
- return(19999);
}
+void
caveclose() /* 11000 */
{ register int i;
prop[bottle]=put(bottle,115,1);
@@ -825,5 +829,4 @@ caveclose() /* 11000 */
if (toting(i)) dstroy(i);
rspeak(132);
closed=TRUE;
- return(2);
}
diff --git a/games/adventure/vocab.c b/games/adventure/vocab.c
index 357e238..deb5c53 100644
--- a/games/adventure/vocab.c
+++ b/games/adventure/vocab.c
@@ -44,6 +44,7 @@ static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
#include <stdio.h>
#include <stdlib.h>
+#include <err.h>
#include "hdr.h"
dstroy(object)
@@ -113,11 +114,12 @@ int object,where;
vocab(word,type,value) /* look up or store a word */
-char *word;
+const char *word;
int type; /* -2 for store, -1 for user word, >=0 for canned lookup*/
int value; /* used for storing only */
{ register int adr;
- register char *s,*t;
+ const char *s;
+ register char *t;
int hash, i;
struct hashtab *h;
@@ -134,13 +136,15 @@ int value; /* used for storing only */
if (h->val) /* already got an entry? */
goto exitloop2;
h->val=value;
- h->atab=malloc(length(word));
+ h->atab=malloc(strlen(word)+1);
+ if (h->atab == NULL)
+ errx(1, "Out of memory!");
for (s=word,t=h->atab; *s;)
*t++ = *s++ ^ '=';
*t=0^'=';
/* encrypt slightly to thwart core reader */
/* printf("Stored \"%s\" (%d ch) as entry %d\n", */
- /* word, length(word), adr); */
+ /* word, strlen(word)+1, adr); */
return(0); /* entry unused */
case -1: /* looking up user word */
if (h->val==0) return(-1); /* not found */
@@ -152,8 +156,7 @@ int value; /* used for storing only */
return(h->val);
default: /* looking up known word */
if (h->val==0)
- { printf("Unable to find %s in vocab\n",word);
- exit(0);
+ { errx(1, "Unable to find %s in vocab", word);
}
for (s=word, t=h->atab;*t ^ '=';)
if ((*s++ ^ '=') != *t++) goto exitloop2;
@@ -164,44 +167,11 @@ int value; /* used for storing only */
exitloop2: /* hashed entry does not match */
if (adr+1==hash || (adr==HTSIZE && hash==0))
- { printf("Hash table overflow\n");
- exit(0);
+ { errx(1, "Hash table overflow");
}
}
}
-
-copystr(w1,w2) /* copy one string to another */
-char *w1,*w2;
-{ register char *s,*t;
- for (s=w1,t=w2; *s;)
- *t++ = *s++;
- *t=0;
-}
-
-weq(w1,w2) /* compare words */
-char *w1,*w2; /* w1 is user, w2 is system */
-{ register char *s,*t;
- register int i;
- s=w1;
- t=w2;
- for (i=0; i<5; i++) /* compare at most 5 chars */
- { if (*t==0 && *s==0)
- return(TRUE);
- if (*s++ != *t++) return(FALSE);
- }
- return(TRUE);
-}
-
-
-length(str) /* includes 0 at end */
-char *str;
-{ register char *s;
- register int n;
- for (n=0,s=str; *s++;) n++;
- return(n+1);
-}
-
prht() /* print hash table */
{ register int i,j,l;
char *c;
diff --git a/games/adventure/wizard.c b/games/adventure/wizard.c
index 17eedb1..326cc94 100644
--- a/games/adventure/wizard.c
+++ b/games/adventure/wizard.c
@@ -56,9 +56,15 @@ int *d,*t;
time(&tvec);
tptr=localtime(&tvec);
- *d=tptr->tm_yday+365*(tptr->tm_year-77); /* day since 1977 (mod leap) */
- *t=tptr->tm_hour*60+tptr->tm_min; /* and minutes since midnite */
-} /* pretty painless */
+ /* day since 1977 */
+ *d = (tptr->tm_yday + 365 * (tptr->tm_year - 77)
+ + (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100
+ + (tptr->tm_year + 299) / 400);
+ /* bug: this will overflow in the year 2066 AD (with 16 bit int) */
+ /* it will be attributed to Wm the C's millenial celebration */
+ /* and minutes since midnite */
+ *t=tptr->tm_hour*60+tptr->tm_min;
+}
char magic[6];
@@ -69,7 +75,7 @@ poof()
latncy = 45;
}
-Start(n)
+Start()
{ int d,t,delay;
datime(&d,&t);
@@ -100,7 +106,7 @@ wizard() /* not as complex as advent/10 (for now) */
if (!yesm(16,0,7)) return(FALSE);
mspeak(17);
getin(&word,&x);
- if (!weq(word,magic))
+ if (strncmp(word,magic,5))
{ mspeak(20);
return(FALSE);
}
@@ -108,16 +114,21 @@ wizard() /* not as complex as advent/10 (for now) */
return(TRUE);
}
-ciao(cmdfile)
-char *cmdfile;
+ciao()
{ register char *c;
register int outfd, size;
char fname[80], buf[512];
extern unsigned filesize;
printf("What would you like to call the saved version?\n");
- for (c=fname;; c++)
- if ((*c=getchar())=='\n') break;
+ /* XXX - should use fgetln to avoid arbitrary limit */
+ for (c = fname; c < fname + sizeof fname - 1; c++) {
+ int ch;
+ ch = getchar();
+ if (ch == '\n' || ch == EOF)
+ break;
+ *c = ch;
+ }
*c=0;
if (save(fname) != 0) return; /* Save failed */
printf("To resume, say \"adventure %s\".\n", fname);
OpenPOWER on IntegriCloud