X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/927a087250c6d788d6df6cc7fcb0359653e2efd3..a8ebb091a7418187b69c5008ac60e7515e9cf803:/trek/getpar.c?ds=inline diff --git a/trek/getpar.c b/trek/getpar.c index 25dcdb61..4a271d32 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.18 2009/08/12 08:54:54 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.18 2009/08/12 08:54:54 dholland Exp $"); #endif #endif /* not lint */ @@ -96,7 +96,7 @@ getfltpar(const char *s) ** get yes/no parameter **/ -const struct cvntab Yntab[] = { +static const struct cvntab Yntab[] = { { "y", "es", (cmdfun)1, 1 }, { "n", "o", (cmdfun)0, 0 }, { NULL, NULL, NULL, 0 } @@ -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) @@ -145,8 +145,8 @@ getcodpar(const char *s, const struct cvntab tab[]) /* if command list, print four per line */ if (input[0] == '?' && input[1] == 0) { c = 4; - for (r = tab; r->abrev; r++) { - strcpy(input, r->abrev); + for (r = tab; r->abbrev; r++) { + strcpy(input, r->abbrev); strcat(input, r->full); printf("%14.14s", input); if (--c > 0) @@ -160,9 +160,9 @@ getcodpar(const char *s, const struct cvntab tab[]) } /* search for in table */ - for (r = tab; r->abrev; r++) { + for (r = tab; r->abbrev; r++) { p = input; - for (q = r->abrev; *q; q++) + for (q = r->abbrev; *q; q++) if (*p++ != *q) break; if (!*q) { @@ -175,7 +175,7 @@ getcodpar(const char *s, const struct cvntab tab[]) } /* check for not found */ - if (!r->abrev) { + if (!r->abbrev) { printf("invalid input; ? for valid inputs\n"); skiptonl(0); } else @@ -197,12 +197,12 @@ getstrpar(const char *s, char *r, int l, const char *t) if (t == 0) t = " \t\n;"; - (void)sprintf(format, "%%%d[^%s]", l, t); + (void)snprintf(format, sizeof(format), "%%%d[^%s]", l, t); while (1) { 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); }