diff options
author | dholland <dholland@NetBSD.org> | 2009-05-24 23:20:22 +0000 |
---|---|---|
committer | dholland <dholland@NetBSD.org> | 2009-05-24 23:20:22 +0000 |
commit | 478be95d8d1ddb2e9cb1831f0115097af1e41bc4 (patch) | |
tree | 81172dfe5cc4fc359e2a3a3e251e366c5c2d1706 /trek/getpar.c | |
parent | 5a874af0513d6e4a0b2b796da83651a4c2351310 (diff) | |
download | bsdgames-darwin-478be95d8d1ddb2e9cb1831f0115097af1e41bc4.tar.gz bsdgames-darwin-478be95d8d1ddb2e9cb1831f0115097af1e41bc4.tar.zst bsdgames-darwin-478be95d8d1ddb2e9cb1831f0115097af1e41bc4.zip |
Abolish cgetc(). It contained one line of code, which was wrong.
Call getchar() directly, and handle EOF properly instead of looping
(in some cases) or pretending that EOF is 0 (which it isn't).
Diffstat (limited to 'trek/getpar.c')
-rw-r--r-- | trek/getpar.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/trek/getpar.c b/trek/getpar.c index 25dcdb61..cc1ed999 100644 --- a/trek/getpar.c +++ b/trek/getpar.c @@ -1,4 +1,4 @@ -/* $NetBSD: getpar.c,v 1.14 2009/05/24 21:44:56 dholland Exp $ */ +/* $NetBSD: getpar.c,v 1.15 2009/05/24 23:20:22 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getpar.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: getpar.c,v 1.14 2009/05/24 21:44:56 dholland Exp $"); +__RCSID("$NetBSD: getpar.c,v 1.15 2009/05/24 23:20:22 dholland Exp $"); #endif #endif /* not lint */ @@ -133,7 +133,7 @@ getcodpar(const char *s, const struct cvntab tab[]) printf("%s: ", s); if (f) { /* throw out the newline */ - cgetc(0); + getchar(); } scanf("%*[ \t;]"); if ((c = scanf("%99[^ \t;\n]", input)) < 0) @@ -202,7 +202,7 @@ getstrpar(const char *s, char *r, int l, const char *t) if ((f = testnl()) && s) printf("%s: ", s); if (f) - cgetc(0); + getchar(); scanf("%*[\t ;]"); i = scanf(format, r); if (i < 0) @@ -220,15 +220,19 @@ getstrpar(const char *s, char *r, int l, const char *t) int testnl(void) { - char c; + int c; - while ((c = cgetc(0)) != '\n') + while ((c = getchar()) != '\n') { + if (c == EOF) { + exit(1); + } if ((c >= '0' && c <= '9') || c == '.' || c == '!' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '-') { ungetc(c, stdin); return(0); } + } ungetc(c, stdin); return (1); } @@ -241,9 +245,12 @@ testnl(void) void skiptonl(int c) { - while (c != '\n') - if (!(c = cgetc(0))) - return; + while (c != '\n') { + c = getchar(); + if (c == EOF) { + exit(1); + } + } ungetc('\n', stdin); return; } @@ -256,10 +263,12 @@ skiptonl(int c) static int testterm(void) { - char c; + int c; - if (!(c = cgetc(0))) - return (1); + c = getchar(); + if (c == EOF) { + exit(1); + } if (c == '.') return (0); if (c == '\n' || c == ';') @@ -279,15 +288,15 @@ testterm(void) int readdelim(int d) { - char c; + int c; - while ((c = cgetc(0)) != '\0') { + while ((c = getchar()) != EOF) { if (c == d) return (1); if (c == ' ') continue; ungetc(c, stdin); - break; + return 0; } - return (0); + exit(1); } |