Module Name: src
Committed By: dholland
Date: Sun May 24 23:20:22 UTC 2009
Modified Files:
src/games/trek: Makefile computer.c getpar.c torped.c trek.h
Removed Files:
src/games/trek: cgetc.c
Log Message:
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).
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/games/trek/Makefile
cvs rdiff -u -r1.8 -r0 src/games/trek/cgetc.c
cvs rdiff -u -r1.14 -r1.15 src/games/trek/computer.c src/games/trek/getpar.c
cvs rdiff -u -r1.13 -r1.14 src/games/trek/torped.c
cvs rdiff -u -r1.15 -r1.16 src/games/trek/trek.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/games/trek/Makefile
diff -u src/games/trek/Makefile:1.12 src/games/trek/Makefile:1.13
--- src/games/trek/Makefile:1.12 Mon Jan 28 07:03:59 2008
+++ src/games/trek/Makefile Sun May 24 23:20:22 2009
@@ -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 @@
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
Index: src/games/trek/computer.c
diff -u src/games/trek/computer.c:1.14 src/games/trek/computer.c:1.15
--- src/games/trek/computer.c:1.14 Sun May 24 22:55:03 2009
+++ src/games/trek/computer.c Sun May 24 23:20:22 2009
@@ -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 @@
* 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);
Index: src/games/trek/getpar.c
diff -u src/games/trek/getpar.c:1.14 src/games/trek/getpar.c:1.15
--- src/games/trek/getpar.c:1.14 Sun May 24 21:44:56 2009
+++ src/games/trek/getpar.c Sun May 24 23:20:22 2009
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
}
Index: src/games/trek/torped.c
diff -u src/games/trek/torped.c:1.13 src/games/trek/torped.c:1.14
--- src/games/trek/torped.c:1.13 Sun May 24 22:55:03 2009
+++ src/games/trek/torped.c Sun May 24 23:20:22 2009
@@ -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 @@
} 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;
}
Index: src/games/trek/trek.h
diff -u src/games/trek/trek.h:1.15 src/games/trek/trek.h:1.16
--- src/games/trek/trek.h:1.15 Sun May 24 22:55:03 2009
+++ src/games/trek/trek.h Sun May 24 23:20:22 2009
@@ -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 capture(int);
struct kling *selectklingon(void);
-/* cgetc.c */
-char cgetc(int);
-
/* check_out.c */
int check_out(int);