summaryrefslogtreecommitdiff
path: root/games/adventure
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-04-07 18:19:38 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-04-07 18:19:38 +0000
commitc9eae24eceba05cbd55018c71ec59d0df9c081f8 (patch)
tree58a10e14efdc064a99b0ae7f8829d0600068eab1 /games/adventure
parentdafa347d401328cc9c6464983dd6468413efb1e1 (diff)
Change wd1 and wd2 from pointers to arrays. This removes the need
for getin() to have static buffers and allows us to do "sizeof wd1". Also fix saved game path. It was removing the first 2 chars of the filename due to a bug. tdeval@ OK
Diffstat (limited to 'games/adventure')
-rw-r--r--games/adventure/extern.h4
-rw-r--r--games/adventure/hdr.h5
-rw-r--r--games/adventure/io.c43
-rw-r--r--games/adventure/main.c24
-rw-r--r--games/adventure/subr.c12
-rw-r--r--games/adventure/wizard.c14
6 files changed, 51 insertions, 51 deletions
diff --git a/games/adventure/extern.h b/games/adventure/extern.h
index e7ab5385a6f..a583db00c21 100644
--- a/games/adventure/extern.h
+++ b/games/adventure/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.5 2003/04/06 18:50:33 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.6 2003/04/07 18:19:37 millert Exp $ */
/* $NetBSD: extern.h,v 1.3 1997/10/11 01:55:27 lukem Exp $ */
/*
@@ -50,7 +50,7 @@ void trapdel(int);
void startup(void);
/* io.c */
-void getin(char **, char **);
+void getin(char *, size_t, char *, size_t);
int yes(int, int, int);
int yesm(int, int, int);
int next(void);
diff --git a/games/adventure/hdr.h b/games/adventure/hdr.h
index cf2c71511eb..94757696201 100644
--- a/games/adventure/hdr.h
+++ b/games/adventure/hdr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hdr.h,v 1.9 2002/02/19 19:39:36 millert Exp $ */
+/* $OpenBSD: hdr.h,v 1.10 2003/04/07 18:19:37 millert Exp $ */
/* $NetBSD: hdr.h,v 1.2 1995/03/21 12:05:02 cgd Exp $ */
/*-
@@ -70,7 +70,6 @@ extern char data_file[]; /* Virtual data file */
#define FLUSHLF while (next()!=LF)
int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2;
-char *wd1,*wd2; /* the complete words */
int verb, obj, spk;
extern int blklin;
time_t savet;
@@ -79,6 +78,8 @@ int mxscor, latncy;
#define SHORT 50 /* How short is a demo game? */
#define MAXSTR 20 /* max length of user's words */
+char wd1[MAXSTR]; /* the complete words */
+char wd2[MAXSTR];
#define HTSIZE 512 /* max number of vocab words */
struct hashtab { /* hash table for vocabulary */
diff --git a/games/adventure/io.c b/games/adventure/io.c
index ad685424cda..f0ba2b30273 100644
--- a/games/adventure/io.c
+++ b/games/adventure/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.11 2002/02/18 06:38:42 deraadt Exp $ */
+/* $OpenBSD: io.c,v 1.12 2003/04/07 18:19:37 millert Exp $ */
/* $NetBSD: io.c,v 1.3 1995/04/24 12:21:37 cgd Exp $ */
/*-
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: io.c,v 1.11 2002/02/18 06:38:42 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: io.c,v 1.12 2003/04/07 18:19:37 millert Exp $";
#endif
#endif /* not lint */
@@ -58,31 +58,32 @@ static char rcsid[] = "$OpenBSD: io.c,v 1.11 2002/02/18 06:38:42 deraadt Exp $";
void
-getin(wrd1, wrd2) /* get command from user */
- char **wrd1, **wrd2; /* no prompt, usually */
+getin(wrd1, siz1, wrd2, siz2) /* get command from user */
+ char *wrd1; /* no prompt, usually */
+ size_t siz1;
+ char *wrd2;
+ size_t siz2;
{
- char *s;
- static char wd1buf[MAXSTR], wd2buf[MAXSTR];
- int first, numch;
-
- *wrd1 = wd1buf; /* return ptr to internal string*/
- *wrd2 = wd2buf;
- wd2buf[0] = 0; /* in case it isn't set here */
- for (s = wd1buf, first = 1, numch = 0;;) {
- if ((*s = getchar()) >= 'A' && *s <= 'Z')
- *s = *s - ('A' - 'a');
+ char *s, *slast;
+ int ch, first;
+
+ *wrd2 = 0; /* in case it isn't set here */
+ for (s = wrd1, first = 1, slast = wrd1 + siz1 - 1;;) {
+ if ((ch = getchar()) >= 'A' && ch <= 'Z')
+ ch = ch - ('A' - 'a');
/* convert to upper case */
- switch (*s) { /* start reading from user */
+ switch (ch) { /* start reading from user */
case '\n':
*s = 0;
return;
case ' ':
- if (s == wd1buf || s == wd2buf) /* initial blank */
+ if (s == wrd1 || s == wrd2) /* initial blank */
continue;
*s = 0;
if (first) { /* finished 1st wd; start 2nd */
- first = numch = 0;
- s = wd2buf;
+ first = 0;
+ s = wrd2;
+ slast = wrd2 + siz2 - 1;
break;
} else { /* finished 2nd word */
FLUSHLINE;
@@ -93,13 +94,13 @@ getin(wrd1, wrd2) /* get command from user */
printf("user closed input stream, quitting...\n");
exit(0);
default:
- if (++numch >= MAXSTR) { /* string too long */
+ if (s == slast) { /* string too long */
printf("Give me a break!!\n");
- wd1buf[0] = wd2buf[0] = 0;
+ *wrd1 = *wrd2 = 0;
FLUSHLINE;
return;
}
- s++;
+ *s++ = ch;
}
}
}
diff --git a/games/adventure/main.c b/games/adventure/main.c
index c383bbb1a2d..139023ca19a 100644
--- a/games/adventure/main.c
+++ b/games/adventure/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.13 2003/04/06 18:50:33 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.14 2003/04/07 18:19:37 millert Exp $ */
/* $NetBSD: main.c,v 1.5 1996/05/21 21:53:09 mrg Exp $ */
/*-
@@ -49,7 +49,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.13 2003/04/06 18:50:33 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.14 2003/04/07 18:19:37 millert Exp $";
#endif
#endif /* not lint */
@@ -169,12 +169,12 @@ l2600: checkhints(); /* to 2600-2602 */
wzdark = dark(); /* 2605 */
if (knfloc > 0 && knfloc != loc)
knfloc = 1;
- getin(&wd1, &wd2);
+ getin(wd1, sizeof(wd1), wd2, sizeof(wd2));
if (delhit) { /* user typed a DEL */
delhit = 0; /* reset counter */
/* pretend he's quitting */
- strcpy(wd1, "quit");
- *wd2 = 0;
+ strlcpy(wd1, "quit", sizeof(wd1));
+ wd2[0] = 0;
}
l2608: if ((foobar = -foobar) > 0)
foobar = 0; /* 2608 */
@@ -183,7 +183,7 @@ l2608: if ((foobar = -foobar) > 0)
if (demo && turns >= SHORT)
done(1); /* to 13000 */
- if (verb == say && *wd2 != 0)
+ if (verb == say && wd2[0] != 0)
verb = 0;
if (verb == say)
goto l4090;
@@ -280,16 +280,16 @@ l8:
default: bug(110);
}
-l2800: strcpy(wd1, wd2);
- *wd2 = 0;
+l2800: strlcpy(wd1, wd2, sizeof(wd1));
+ wd2[0] = 0;
goto l2610;
l4000: verb = k;
spk = actspk[verb];
- if (*wd2 != 0 && verb != say)
+ if (wd2[0] != 0 && verb != say)
goto l2800;
if (verb == say)
- obj= *wd2;
+ obj = wd2[0];
if (obj != 0)
goto l4090;
l4080:
@@ -644,7 +644,7 @@ l5000:
obj = k;
if (fixed[k] != loc && !here(k))
goto l5100;
-l5010: if (*wd2 != 0)
+l5010: if (wd2[0] != 0)
goto l2800;
if (verb != 0)
goto l4090;
@@ -678,7 +678,7 @@ l5140: if (obj != rod || !here(rod2))
goto l5190;
obj = rod2;
goto l5010;
-l5190: if ((verb == find || verb == invent) && *wd2 == 0)
+l5190: if ((verb == find || verb == invent) && wd2[0] == 0)
goto l5010;
printf("I see no %s here\n", wd1);
goto l2012;
diff --git a/games/adventure/subr.c b/games/adventure/subr.c
index 921a63c9185..3d7d44969ab 100644
--- a/games/adventure/subr.c
+++ b/games/adventure/subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr.c,v 1.5 2003/04/06 18:50:33 deraadt Exp $ */
+/* $OpenBSD: subr.c,v 1.6 2003/04/07 18:19:37 millert Exp $ */
/* $NetBSD: subr.c,v 1.2 1995/03/21 12:05:11 cgd Exp $ */
/*-
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: subr.c,v 1.5 2003/04/06 18:50:33 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: subr.c,v 1.6 2003/04/07 18:19:37 millert Exp $";
#endif
#endif /* not lint */
@@ -555,11 +555,11 @@ trsay() /* 9030 */
{
int i;
- if (*wd2 != 0)
- strcpy(wd1, wd2);
+ if (wd2[0] != 0)
+ strlcpy(wd1, wd2, sizeof(wd1));
i = vocab(wd1, -1, 0);
if (i == 62 || i == 65 || i == 71 || i == 2025) {
- *wd2 = 0;
+ wd2[0] = 0;
obj = 0;
return (2630);
}
@@ -833,7 +833,7 @@ trkill() /* 9120 */
rspeak(49);
verb = 0;
obj = 0;
- getin(&wd1, &wd2);
+ getin(wd1, sizeof(wd1), wd2, sizeof(wd2));
if (!weq(wd1, "y") && !weq(wd1, "yes"))
return (2608);
pspeak(dragon, 1);
diff --git a/games/adventure/wizard.c b/games/adventure/wizard.c
index 2d94312145f..fd011127e5e 100644
--- a/games/adventure/wizard.c
+++ b/games/adventure/wizard.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wizard.c,v 1.10 2003/04/06 18:50:33 deraadt Exp $ */
+/* $OpenBSD: wizard.c,v 1.11 2003/04/07 18:19:37 millert Exp $ */
/* $NetBSD: wizard.c,v 1.3 1995/04/24 12:21:41 cgd Exp $ */
/*-
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 6/2/93";
#else
-static char rcsid[] = "$OpenBSD: wizard.c,v 1.10 2003/04/06 18:50:33 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: wizard.c,v 1.11 2003/04/07 18:19:37 millert Exp $";
#endif
#endif /* not lint */
@@ -113,13 +113,11 @@ Start()
int
wizard() /* not as complex as advent/10 (for now) */
{
- char *word, *x;
-
if (!yesm(16, 0, 7))
return (FALSE);
mspeak(17);
- getin(&word, &x);
- if (!weq(word, magic)) {
+ getin(wd1, sizeof(wd1), wd2, sizeof(wd2));
+ if (!weq(wd1, magic)) {
mspeak(20);
return (FALSE);
}
@@ -136,9 +134,9 @@ ciao()
printf("What would you like to call the saved version?\n");
for (c = fname; c - fname < MAXPATHLEN; c++) {
- *c = ch = getchar();
- if ((*c = getchar()) == '\n' || ch == EOF)
+ if ((ch = getchar()) == '\n' || ch == EOF)
break;
+ *c = ch;
}
if (c - fname == MAXPATHLEN) {
c--;