summaryrefslogtreecommitdiffstats
path: root/trek
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-05-24 23:20:22 +0000
committerdholland <dholland@NetBSD.org>2009-05-24 23:20:22 +0000
commit478be95d8d1ddb2e9cb1831f0115097af1e41bc4 (patch)
tree81172dfe5cc4fc359e2a3a3e251e366c5c2d1706 /trek
parent5a874af0513d6e4a0b2b796da83651a4c2351310 (diff)
downloadbsdgames-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')
-rw-r--r--trek/Makefile4
-rw-r--r--trek/cgetc.c48
-rw-r--r--trek/computer.c8
-rw-r--r--trek/getpar.c41
-rw-r--r--trek/torped.c6
-rw-r--r--trek/trek.h5
6 files changed, 35 insertions, 77 deletions
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 <sys/cdefs.h>
-#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 <stdio.h>
-#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);