diff options
Diffstat (limited to 'games/battlestar/getcom.c')
-rw-r--r-- | games/battlestar/getcom.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/games/battlestar/getcom.c b/games/battlestar/getcom.c index 2635a1b2e15..5a25a42c5c2 100644 --- a/games/battlestar/getcom.c +++ b/games/battlestar/getcom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getcom.c,v 1.4 1997/09/01 18:13:18 millert Exp $ */ +/* $OpenBSD: getcom.c,v 1.5 1998/09/13 01:30:32 pjanzen Exp $ */ /* $NetBSD: getcom.c,v 1.3 1995/03/21 15:07:30 cgd Exp $ */ /* @@ -38,23 +38,25 @@ #if 0 static char sccsid[] = "@(#)getcom.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: getcom.c,v 1.3 1995/03/21 15:07:30 cgd Exp $"; +static char rcsid[] = "$OpenBSD: getcom.c,v 1.5 1998/09/13 01:30:32 pjanzen Exp $"; #endif #endif /* not lint */ -#include <stdio.h> -#include <ctype.h> #include "extern.h" -char * +char * getcom(buf, size, prompt, error) - char *buf; - int size; - char *prompt, *error; + char *buf; + int size; + char *prompt, *error; { for (;;) { fputs(prompt, stdout); if (fgets(buf, size, stdin) == 0) { + if (feof(stdin)) { + printf("user closed input stream, quitting...\n"); + exit(0); + } clearerr(stdin); continue; } @@ -73,10 +75,10 @@ getcom(buf, size, prompt, error) * shifts to UPPERCASE if flag > 0, lowercase if flag < 0, * and leaves it unchanged if flag = 0 */ -char * +char * getword(buf1, buf2, flag) - register char *buf1, *buf2; - register int flag; + char *buf1, *buf2; + int flag; { while (isspace(*buf1)) buf1++; @@ -86,18 +88,19 @@ getword(buf1, buf2, flag) return (0); } while (*buf1 && !isspace(*buf1) && *buf1 != ',') - if (flag < 0) + if (flag < 0) { if (isupper(*buf1)) *buf2++ = tolower(*buf1++); else *buf2++ = *buf1++; - else if (flag > 0) - if (islower(*buf1)) - *buf2++ = toupper(*buf1++); - else + } else + if (flag > 0) { + if (islower(*buf1)) + *buf2++ = toupper(*buf1++); + else + *buf2++ = *buf1++; + } else *buf2++ = *buf1++; - else - *buf2++ = *buf1++; } else *buf2++ = *buf1++; *buf2 = 0; |