summaryrefslogtreecommitdiff
path: root/games/atc
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>2001-02-04 02:15:29 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>2001-02-04 02:15:29 +0000
commit42df3673ec79a02f2eabe4da012bf880b0134df3 (patch)
tree58f18ebe53e6f5b5a701b84834e79c69f4e17596 /games/atc
parent2c77bdd3c30c4e2793dacc2c5be32d4d251d75d3 (diff)
Tidying: change a constant to a #define, stop logging hostnames with the
score, use strlcpy(), and make it work with long usernames.
Diffstat (limited to 'games/atc')
-rw-r--r--games/atc/Makefile6
-rw-r--r--games/atc/atc.66
-rw-r--r--games/atc/def.h11
-rw-r--r--games/atc/extern.h4
-rw-r--r--games/atc/include.h3
-rw-r--r--games/atc/log.c45
-rw-r--r--games/atc/struct.h5
-rw-r--r--games/atc/tunable.c63
8 files changed, 42 insertions, 101 deletions
diff --git a/games/atc/Makefile b/games/atc/Makefile
index ed3898f5b2f..dc9f76bb7d1 100644
--- a/games/atc/Makefile
+++ b/games/atc/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.9 1998/09/21 07:36:04 pjanzen Exp $
+# $OpenBSD: Makefile,v 1.10 2001/02/04 02:15:28 pjanzen Exp $
PROG= atc
-CFLAGS+=-DBSD -I${.CURDIR} -I.
+CFLAGS+=-I${.CURDIR} -I.
SRCS= extern.c grammar.c graphics.c input.c lex.c list.c log.c \
- main.c tunable.c update.c
+ main.c update.c
MAN= atc.6
LDADD= -ll -lm -lcurses
DPADD= ${LIBL} ${LIBM} ${LIBCURSES}
diff --git a/games/atc/atc.6 b/games/atc/atc.6
index fc46223fa88..43595f9bbed 100644
--- a/games/atc/atc.6
+++ b/games/atc/atc.6
@@ -1,4 +1,4 @@
-.\" $OpenBSD: atc.6,v 1.5 1999/07/31 20:08:29 pjanzen Exp $
+.\" $OpenBSD: atc.6,v 1.6 2001/02/04 02:15:28 pjanzen Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -70,6 +70,10 @@ Print a list of available games and exit.
The first game name printed is the default game.
.It Fl s
Print the score list (formerly the Top Ten list).
+The scoring information is the game time in
+.Dq radar updates ,
+the wall-clock game time, and the number of planes that were
+successfully dealt with.
.It Fl t
Same as
.Fl s .
diff --git a/games/atc/def.h b/games/atc/def.h
index b0a2baac0c4..409008d0606 100644
--- a/games/atc/def.h
+++ b/games/atc/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.3 1999/03/22 05:36:57 pjanzen Exp $ */
+/* $OpenBSD: def.h,v 1.4 2001/02/04 02:15:28 pjanzen Exp $ */
/* $NetBSD: def.h,v 1.3 1995/03/21 15:03:47 cgd Exp $ */
/*-
@@ -83,3 +83,12 @@
#define INPUT_LINES 3
#define PLANE_COLS 20
+
+
+/*
+ * NUM_SCORES - Number of scores that are kept track of.
+ * Keep this greater than 0.
+ * 4 lines are printed above the score, one below + your prompt, so
+ * to prevent scrolling: 6 + NUM_SCORES <= 24 (lines on an average terminal).
+ */
+#define NUM_SCORES 18
diff --git a/games/atc/extern.h b/games/atc/extern.h
index e783fc808f2..923de71e342 100644
--- a/games/atc/extern.h
+++ b/games/atc/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.3 1999/09/01 00:27:07 pjanzen Exp $ */
+/* $OpenBSD: extern.h,v 1.4 2001/02/04 02:15:28 pjanzen Exp $ */
/* $NetBSD: extern.h,v 1.4 1995/04/27 21:22:22 mycroft Exp $ */
/*-
@@ -63,8 +63,6 @@ extern struct termios tty_start, tty_new;
extern DISPLACEMENT displacement[MAXDIR];
-extern int NUM_SCORES;
-
int addplane __P((void));
void append __P((LIST *, PLANE *));
void check_adir __P((int, int, int));
diff --git a/games/atc/include.h b/games/atc/include.h
index 9b32a15f7a2..44604c3dba0 100644
--- a/games/atc/include.h
+++ b/games/atc/include.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: include.h,v 1.4 1998/09/21 07:36:05 pjanzen Exp $ */
+/* $OpenBSD: include.h,v 1.5 2001/02/04 02:15:28 pjanzen Exp $ */
/* $NetBSD: include.h,v 1.5 1995/04/27 21:22:23 mycroft Exp $ */
/*-
@@ -50,6 +50,7 @@
#include <sys/types.h>
#include <sys/file.h>
+#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/utsname.h>
diff --git a/games/atc/log.c b/games/atc/log.c
index 4ac3723c37c..1ca21606f54 100644
--- a/games/atc/log.c
+++ b/games/atc/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.6 1999/09/01 00:27:08 pjanzen Exp $ */
+/* $OpenBSD: log.c,v 1.7 2001/02/04 02:15:28 pjanzen Exp $ */
/* $NetBSD: log.c,v 1.3 1995/03/21 15:04:21 cgd Exp $ */
/*-
@@ -50,7 +50,7 @@
#if 0
static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: log.c,v 1.6 1999/09/01 00:27:08 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: log.c,v 1.7 2001/02/04 02:15:28 pjanzen Exp $";
#endif
#endif not lint
@@ -80,7 +80,7 @@ compar(va, vb)
#define SECADAY (SECAHOUR * HOURADAY)
#define DAY(t) ((t) / SECADAY)
#define HOUR(t) (((t) % SECADAY) / SECAHOUR)
-#define MIN(t) (((t) % SECAHOUR) / SECAMIN)
+#define MINUTES(t) (((t) % SECAHOUR) / SECAMIN)
#define SEC(t) ((t) % SECAMIN)
const char *
@@ -92,9 +92,9 @@ timestr(t)
if (DAY(t) > 0)
(void)sprintf(s, "%dd+%02dhrs", DAY(t), HOUR(t));
else if (HOUR(t) > 0)
- (void)sprintf(s, "%d:%02d:%02d", HOUR(t), MIN(t), SEC(t));
- else if (MIN(t) > 0)
- (void)sprintf(s, "%d:%02d", MIN(t), SEC(t));
+ (void)sprintf(s, "%d:%02d:%02d", HOUR(t), MINUTES(t), SEC(t));
+ else if (MINUTES(t) > 0)
+ (void)sprintf(s, "%d:%02d", MINUTES(t), SEC(t));
else if (SEC(t) > 0)
(void)sprintf(s, ":%02d", SEC(t));
else
@@ -130,12 +130,12 @@ open_score_file()
int
log_score(list_em)
+ int list_em;
{
int i, num_scores = 0, good, changed = 0, found = 0;
struct passwd *pw;
char *cp;
- SCORE score[100], thisscore;
- struct utsname name;
+ SCORE score[NUM_SCORES], thisscore;
if (score_fp == NULL)
return (-1);
@@ -150,14 +150,13 @@ log_score(list_em)
return (-1);
}
for (;;) {
- good = fscanf(score_fp, "%s %s %s %d %d %d",
+ good = fscanf(score_fp, "%s %s %d %d %d",
score[num_scores].name,
- score[num_scores].host,
score[num_scores].game,
&score[num_scores].planes,
&score[num_scores].time,
&score[num_scores].real_time);
- if (good != 6 || ++num_scores >= NUM_SCORES)
+ if (good != 5 || ++num_scores >= NUM_SCORES)
break;
}
if (!test_mode && !list_em) {
@@ -167,17 +166,15 @@ log_score(list_em)
getuid());
return (-1);
}
- strcpy(thisscore.name, pw->pw_name);
- uname(&name);
- strcpy(thisscore.host, name.nodename);
+ strlcpy(thisscore.name, pw->pw_name, sizeof(thisscore.name));
cp = strrchr(file, '/');
if (cp == NULL) {
- fprintf(stderr, "log: where's the '/' in %s?\n", file);
+ warnx("log: where's the '/' in %s?", file);
return (-1);
}
cp++;
- strcpy(thisscore.game, cp);
+ strlcpy(thisscore.game, cp, sizeof(thisscore.game));
thisscore.time = clck;
thisscore.planes = safe_planes;
@@ -185,7 +182,6 @@ log_score(list_em)
for (i = 0; i < num_scores; i++) {
if (strcmp(thisscore.name, score[i].name) == 0 &&
- strcmp(thisscore.host, score[i].host) == 0 &&
strcmp(thisscore.game, score[i].game) == 0) {
if (thisscore.time > score[i].time) {
score[i].time = thisscore.time;
@@ -228,8 +224,8 @@ log_score(list_em)
qsort(score, num_scores, sizeof (*score), compar);
rewind(score_fp);
for (i = 0; i < num_scores; i++)
- fprintf(score_fp, "%s %s %s %d %d %d\n",
- score[i].name, score[i].host,
+ fprintf(score_fp, "%s %s %d %d %d\n",
+ score[i].name,
score[i].game, score[i].planes,
score[i].time, score[i].real_time);
} else {
@@ -253,15 +249,12 @@ log_score(list_em)
fsync(fileno(score_fp));
rewind(score_fp);
#endif
- printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host",
- "game", "time", "real time", "planes safe");
+ printf("%2s: %-31s %-18s %4s %9s %4s\n", "#", "name",
+ "game", "time", "real time", "safe");
puts("-------------------------------------------------------------------------------");
for (i = 0; i < num_scores; i++) {
- cp = strchr(score[i].host, '.');
- if (cp != NULL)
- *cp = '\0';
- printf("%2d: %-8s %-8s %-18s %4d %9s %4d\n", i + 1,
- score[i].name, score[i].host, score[i].game,
+ printf("%2d: %-31s %-18s %4d %9s %4d\n", i + 1,
+ score[i].name, score[i].game,
score[i].time, timestr(score[i].real_time),
score[i].planes);
}
diff --git a/games/atc/struct.h b/games/atc/struct.h
index b99e385f9ae..dd5b9c71aee 100644
--- a/games/atc/struct.h
+++ b/games/atc/struct.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: struct.h,v 1.2 1998/09/21 07:36:07 pjanzen Exp $ */
+/* $OpenBSD: struct.h,v 1.3 2001/02/04 02:15:28 pjanzen Exp $ */
/* $NetBSD: struct.h,v 1.3 1995/03/21 15:04:31 cgd Exp $ */
/*-
@@ -100,8 +100,7 @@ typedef struct {
} LIST;
typedef struct {
- char name[10];
- char host[256];
+ char name[MAXLOGNAME];
char game[256];
int planes;
int time;
diff --git a/games/atc/tunable.c b/games/atc/tunable.c
deleted file mode 100644
index 739807d4c81..00000000000
--- a/games/atc/tunable.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/* $OpenBSD: tunable.c,v 1.2 1998/09/21 07:36:07 pjanzen Exp $ */
-/* $NetBSD: tunable.c,v 1.3 1995/03/21 15:04:33 cgd Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ed James.
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- */
-
-/*
- * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
- *
- * Copy permission is hereby granted provided that this notice is
- * retained on all partial or complete copies.
- *
- * For more info on this and all of my stuff, mail edjames@berkeley.edu.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)tunable.c 8.1 (Berkeley) 5/31/93";
-#else
-static char rcsid[] = "$OpenBSD: tunable.c,v 1.2 1998/09/21 07:36:07 pjanzen Exp $";
-#endif
-#endif /* not lint */
-
-/*
- * NUM_SCORES - Number of scores that are kept track of.
- * Keep this greater than 0, but less than 100.
- * 4 lines are printed above the score, one below + your prompt, so
- * to prevent scrolling: 6 + NUM_SCORES <= 24 (lines on an average terminal).
- */
-int NUM_SCORES = 18;