diff options
Diffstat (limited to 'games/adventure/io.c')
-rw-r--r-- | games/adventure/io.c | 43 |
1 files changed, 22 insertions, 21 deletions
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; } } } |