Module Name:    src
Committed By:   dholland
Date:           Thu Jun 25 05:33:02 UTC 2015

Modified Files:
        src/games/atc: extern.h graphics.c main.c update.c

Log Message:
Move game logic out of the file with the curses code.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/games/atc/extern.h
cvs rdiff -u -r1.19 -r1.20 src/games/atc/graphics.c
cvs rdiff -u -r1.23 -r1.24 src/games/atc/main.c
cvs rdiff -u -r1.26 -r1.27 src/games/atc/update.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/atc/extern.h
diff -u src/games/atc/extern.h:1.18 src/games/atc/extern.h:1.19
--- src/games/atc/extern.h:1.18	Fri Jun 19 06:02:31 2015
+++ src/games/atc/extern.h	Thu Jun 25 05:33:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.18 2015/06/19 06:02:31 dholland Exp $	*/
+/*	$NetBSD: extern.h,v 1.19 2015/06/25 05:33:02 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -64,6 +64,13 @@ extern struct termios	tty_start, tty_new
 
 extern DISPLACEMENT	displacement[MAXDIR];
 
+/* in graphics.c */
+void shutdown_gr(void);
+void ioaskquit(void);
+void ionoquit(void);
+void losermsg(const PLANE *p, const char *msg);
+
+/* misc */
 void		addplane(void);
 void		append(LIST *, PLANE *);
 void		check_adir(int, int, int);
@@ -88,7 +95,6 @@ char		name(const PLANE *);
 int		number(int);
 void		open_score_file(void);
 void		planewin(void);
-void		quit(int);
 void		redraw(void);
 void		setup_screen(const C_SCREEN *);
 void		update(int);

Index: src/games/atc/graphics.c
diff -u src/games/atc/graphics.c:1.19 src/games/atc/graphics.c:1.20
--- src/games/atc/graphics.c:1.19	Fri Jun 19 06:02:31 2015
+++ src/games/atc/graphics.c	Thu Jun 25 05:33:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: graphics.c,v 1.19 2015/06/19 06:02:31 dholland Exp $	*/
+/*	$NetBSD: graphics.c,v 1.20 2015/06/25 05:33:02 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)graphics.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: graphics.c,v 1.19 2015/06/19 06:02:31 dholland Exp $");
+__RCSID("$NetBSD: graphics.c,v 1.20 2015/06/25 05:33:02 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -136,6 +136,15 @@ init_gr(void)
 }
 
 void
+shutdown_gr(void)
+{
+	(void)clear();	/* move to top of screen */
+	(void)refresh();
+	(void)fflush(stdout);
+	(void)endwin();
+}
+
+void
 setup_screen(const C_SCREEN *scp)
 {
 	int	i, j;
@@ -293,43 +302,25 @@ ioerror(int pos, int len, const char *st
 	(void)fflush(stdout);
 }
 
-/* ARGSUSED */
+static int ioquit_x, ioquit_y;
+
 void
-quit(int dummy __unused)
+ioaskquit(void)
 {
-	int			c, y, x;
-#ifdef BSD
-	struct itimerval	itv;
-#endif
-
-	getyx(input, y, x);
+	getyx(input, ioquit_y, ioquit_x);
 	(void)wmove(input, 2, 0);
 	(void)waddstr(input, "Really quit? (y/n) ");
 	(void)wclrtobot(input);
 	(void)wrefresh(input);
 	(void)fflush(stdout);
+}
 
-	c = getchar();
-	if (c == EOF || c == 'y') {
-		/* disable timer */
-#ifdef BSD
-		itv.it_value.tv_sec = 0;
-		itv.it_value.tv_usec = 0;
-		(void)setitimer(ITIMER_REAL, &itv, NULL);
-#endif
-#ifdef SYSV
-		alarm(0);
-#endif
-		(void)fflush(stdout);
-		(void)clear();
-		(void)refresh();
-		(void)endwin();
-		(void)log_score(0);
-		exit(0);
-	}
+void
+ionoquit(void)
+{
 	(void)wmove(input, 2, 0);
 	(void)wclrtobot(input);
-	(void)wmove(input, y, x);
+	(void)wmove(input, ioquit_y, ioquit_x);
 	(void)wrefresh(input);
 	(void)fflush(stdout);
 }
@@ -378,42 +369,20 @@ planewin(void)
 }
 
 void
-loser(const PLANE *p, const char *s)
+losermsg(const PLANE *p, const char *msg)
 {
-	int			c;
-#ifdef BSD
-	struct itimerval	itv;
-#endif
-
-	/* disable timer */
-#ifdef BSD
-	itv.it_value.tv_sec = 0;
-	itv.it_value.tv_usec = 0;
-	(void)setitimer(ITIMER_REAL, &itv, NULL);
-#endif
-#ifdef SYSV
-	alarm(0);
-#endif
-
 	(void)wmove(input, 0, 0);
 	(void)wclrtobot(input);
 	/* p may be NULL if we ran out of memory */
 	if (p == NULL)
 		(void)wprintw(input, "%s\n\nHit space for top players list...",
-		    s);
+		    msg);
 	else {
-		(void)wprintw(input, "Plane '%c' %s\n\n", name(p), s);
+		(void)wprintw(input, "Plane '%c' %s\n\n", name(p), msg);
 		(void)wprintw(input, "Hit space for top players list...");
 	}
 	(void)wrefresh(input);
 	(void)fflush(stdout);
-	while ((c = getchar()) != EOF && c != ' ')
-		;
-	(void)clear();	/* move to top of screen */
-	(void)refresh();
-	(void)endwin();
-	(void)log_score(0);
-	exit(0);
 }
 
 void

Index: src/games/atc/main.c
diff -u src/games/atc/main.c:1.23 src/games/atc/main.c:1.24
--- src/games/atc/main.c:1.23	Fri Jun 19 06:02:31 2015
+++ src/games/atc/main.c	Thu Jun 25 05:33:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.23 2015/06/19 06:02:31 dholland Exp $	*/
+/*	$NetBSD: main.c,v 1.24 2015/06/25 05:33:02 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: main.c,v 1.23 2015/06/19 06:02:31 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.24 2015/06/25 05:33:02 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -75,6 +75,7 @@ static int read_file(const char *);
 static const char *default_game(void);
 static const char *okay_game(const char *);
 static int list_games(void);
+static void quit(int);
 
 int
 main(int argc, char *argv[])
@@ -327,3 +328,30 @@ list_games(void)
 	}
 	return (0);
 }
+
+/* ARGSUSED */
+static void
+quit(int dummy __unused)
+{
+	int c;
+#ifdef BSD
+	struct itimerval	itv;
+#endif
+	ioaskquit();
+	c = getAChar();
+	if (c == EOF || c == 'y') {
+		/* disable timer */
+#ifdef BSD
+		itv.it_value.tv_sec = 0;
+		itv.it_value.tv_usec = 0;
+		(void)setitimer(ITIMER_REAL, &itv, NULL);
+#endif
+#ifdef SYSV
+		alarm(0);
+#endif
+		shutdown_gr();
+		(void)log_score(0);
+		exit(0);
+	}
+	ionoquit();
+}

Index: src/games/atc/update.c
diff -u src/games/atc/update.c:1.26 src/games/atc/update.c:1.27
--- src/games/atc/update.c:1.26	Fri Jun 19 06:02:31 2015
+++ src/games/atc/update.c	Thu Jun 25 05:33:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: update.c,v 1.26 2015/06/19 06:02:31 dholland Exp $	*/
+/*	$NetBSD: update.c,v 1.27 2015/06/25 05:33:02 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)update.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: update.c,v 1.26 2015/06/19 06:02:31 dholland Exp $");
+__RCSID("$NetBSD: update.c,v 1.27 2015/06/25 05:33:02 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -232,6 +232,32 @@ update(int dummy __unused)
 #endif
 }
 
+void
+loser(const PLANE *p, const char *s)
+{
+	int			c;
+#ifdef BSD
+	struct itimerval	itv;
+#endif
+
+	/* disable timer */
+#ifdef BSD
+	itv.it_value.tv_sec = 0;
+	itv.it_value.tv_usec = 0;
+	(void)setitimer(ITIMER_REAL, &itv, NULL);
+#endif
+#ifdef SYSV
+	alarm(0);
+#endif
+
+	losermsg(p, s);
+	while ((c = getAChar()) != EOF && c != ' ')
+		;
+	shutdown_gr();
+	(void)log_score(0);
+	exit(0);
+}
+
 const char *
 command(const PLANE *pp)
 {

Reply via email to