From 478be95d8d1ddb2e9cb1831f0115097af1e41bc4 Mon Sep 17 00:00:00 2001 From: dholland Date: Sun, 24 May 2009 23:20:22 +0000 Subject: 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). --- trek/Makefile | 4 ++-- trek/cgetc.c | 48 ------------------------------------------------ trek/computer.c | 8 ++++---- trek/getpar.c | 41 +++++++++++++++++++++++++---------------- trek/torped.c | 6 +++--- trek/trek.h | 5 +---- 6 files changed, 35 insertions(+), 77 deletions(-) delete mode 100644 trek/cgetc.c (limited to 'trek') diff --git a/trek/Makefile b/trek/Makefile index c2b2336c..c577aa9c 100644 --- a/trek/Makefile +++ b/trek/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.12 2008/01/28 07:03:59 dholland Exp $ +# $NetBSD: Makefile,v 1.13 2009/05/24 23:20:22 dholland Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 PROG= trek @@ -9,7 +9,7 @@ SRCS= abandon.c attack.c autover.c capture.c check_out.c checkcond.c \ lose.c lrscan.c main.c move.c nova.c out.c phaser.c play.c ram.c \ ranf.c rest.c schedule.c score.c setup.c setwarp.c \ shield.c snova.c srscan.c systemname.c torped.c \ - visual.c warp.c win.c cgetc.c + visual.c warp.c win.c MAN= trek.6 DPADD= ${LIBM} LDADD= -lm diff --git a/trek/cgetc.c b/trek/cgetc.c deleted file mode 100644 index 420f11b7..00000000 --- a/trek/cgetc.c +++ /dev/null @@ -1,48 +0,0 @@ -/* $NetBSD: cgetc.c,v 1.8 2009/05/24 18:22:27 dholland Exp $ */ - -/* - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cgetc.c 8.1 (Berkeley) 5/31/93"; -#else -__RCSID("$NetBSD: cgetc.c,v 1.8 2009/05/24 18:22:27 dholland Exp $"); -#endif -#endif /* not lint */ - -#include -#include "trek.h" - -char -cgetc(int i __unused) -{ - return getchar(); -} diff --git a/trek/computer.c b/trek/computer.c index 04c62f53..c3c507d4 100644 --- a/trek/computer.c +++ b/trek/computer.c @@ -1,4 +1,4 @@ -/* $NetBSD: computer.c,v 1.14 2009/05/24 22:55:03 dholland Exp $ */ +/* $NetBSD: computer.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[] = "@(#)computer.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: computer.c,v 1.14 2009/05/24 22:55:03 dholland Exp $"); +__RCSID("$NetBSD: computer.c,v 1.15 2009/05/24 23:20:22 dholland Exp $"); #endif #endif /* not lint */ @@ -293,8 +293,8 @@ computer(int v __unused) * means get new computer request; newline means * exit computer mode. */ - while ((i = cgetc(0)) != ';') { - if (i == '\0') + while ((i = getchar()) != ';') { + if (i == EOF) exit(1); if (i == '\n') { ungetc(i, stdin); 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); } diff --git a/trek/torped.c b/trek/torped.c index 388f69e1..24f3de4a 100644 --- a/trek/torped.c +++ b/trek/torped.c @@ -1,4 +1,4 @@ -/* $NetBSD: torped.c,v 1.13 2009/05/24 22:55:03 dholland Exp $ */ +/* $NetBSD: torped.c,v 1.14 2009/05/24 23:20:22 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)torped.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: torped.c,v 1.13 2009/05/24 22:55:03 dholland Exp $"); +__RCSID("$NetBSD: torped.c,v 1.14 2009/05/24 23:20:22 dholland Exp $"); #endif #endif /* not lint */ @@ -104,7 +104,7 @@ torped(int v __unused) } else { /* see if the user wants one */ if (!testnl()) { - k = ungetc(cgetc(0), stdin); + k = ungetc(getchar(), stdin); if (k >= '0' && k <= '9') burst = 1; } diff --git a/trek/trek.h b/trek/trek.h index 26fe2e28..65fcad8b 100644 --- a/trek/trek.h +++ b/trek/trek.h @@ -1,4 +1,4 @@ -/* $NetBSD: trek.h,v 1.15 2009/05/24 22:55:03 dholland Exp $ */ +/* $NetBSD: trek.h,v 1.16 2009/05/24 23:20:22 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -381,9 +381,6 @@ void autover(void); void capture(int); struct kling *selectklingon(void); -/* cgetc.c */ -char cgetc(int); - /* check_out.c */ int check_out(int); -- cgit v1.2.3-56-ge451