From 68d4fdd27d94764d7e4f1a1e40f9ada5f69d0fbd Mon Sep 17 00:00:00 2001 From: dholland Date: Sun, 15 Mar 2009 00:35:42 +0000 Subject: Move all curses bits to pl_7.c. --- sail/display.h | 19 ++++-------------- sail/pl_5.c | 25 +++++++---------------- sail/pl_7.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 43 deletions(-) (limited to 'sail') diff --git a/sail/display.h b/sail/display.h index 034b477e..98995609 100644 --- a/sail/display.h +++ b/sail/display.h @@ -1,4 +1,4 @@ -/* $NetBSD: display.h,v 1.4 2009/03/14 19:35:13 dholland Exp $ */ +/* $NetBSD: display.h,v 1.5 2009/03/15 00:35:42 dholland Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -29,17 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifdef SIGTSTP -#define SCREENTEST() (initscr() != NULL && \ - signal(SIGTSTP, SIG_DFL) != SIG_ERR && \ - STAT_R < COLS && SCROLL_Y > 0) -#else -#define SCREENTEST() (initscr() != NULL && STAT_R < COLS && SCROLL_Y > 0) -#endif - -extern WINDOW *view_w; -extern WINDOW *slot_w; -extern WINDOW *scroll_w; -extern WINDOW *stat_w; -extern WINDOW *turn_w; - +void display_show_obp(int which, bool show); +void display_show_dbp(int which, bool show); +void display_refresh_slot_w(void); diff --git a/sail/pl_5.c b/sail/pl_5.c index 09dd902f..2e72116a 100644 --- a/sail/pl_5.c +++ b/sail/pl_5.c @@ -1,4 +1,4 @@ -/* $NetBSD: pl_5.c,v 1.23 2009/03/14 22:52:52 dholland Exp $ */ +/* $NetBSD: pl_5.c,v 1.24 2009/03/15 00:35:42 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,12 +34,11 @@ #if 0 static char sccsid[] = "@(#)pl_5.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: pl_5.c,v 1.23 2009/03/14 22:52:52 dholland Exp $"); +__RCSID("$NetBSD: pl_5.c,v 1.24 2009/03/15 00:35:42 dholland Exp $"); #endif #endif /* not lint */ #include -#include #include #include #include @@ -237,27 +236,17 @@ parties(struct ship *to, int *crew, int isdefense, int buf) send_obp(ms, j, turn, to->file->index, men); } if (isdefense) { - wmove(slot_w, 2, 0); for (k=0; k < NBP; k++) - if (temp[k] && !crew[k]) - waddch(slot_w, k + '1'); - else - wmove(slot_w, 2, 1 + k); - mvwaddstr(slot_w, 3, 0, "DBP"); + display_show_dbp(k, + temp[k] && !crew[k]); makemsg(ms, "repelling boarders"); } else { - wmove(slot_w, 0, 0); for (k=0; k < NBP; k++) - if (temp[k] && !crew[k]) - waddch(slot_w, k + '1'); - else - wmove(slot_w, 0, 1 + k); - mvwaddstr(slot_w, 1, 0, "OBP"); + display_show_obp(k, + temp[k] && !crew[k]); makesignal(ms, "boarding the $$", to); } - blockalarm(); - wrefresh(slot_w); - unblockalarm(); + display_refresh_slot_w(); } else Msg("Sending no crew sections."); } diff --git a/sail/pl_7.c b/sail/pl_7.c index cc2134e4..4be1df7c 100644 --- a/sail/pl_7.c +++ b/sail/pl_7.c @@ -1,4 +1,4 @@ -/* $NetBSD: pl_7.c,v 1.32 2009/03/14 22:52:53 dholland Exp $ */ +/* $NetBSD: pl_7.c,v 1.33 2009/03/15 00:35:42 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: pl_7.c,v 1.32 2009/03/14 22:52:53 dholland Exp $"); +__RCSID("$NetBSD: pl_7.c,v 1.33 2009/03/15 00:35:42 dholland Exp $"); #endif #endif /* not lint */ @@ -63,11 +63,11 @@ static const char *sc_prompt; static const char *sc_buf; static int sc_line; -WINDOW *view_w; -WINDOW *slot_w; -WINDOW *scroll_w; -WINDOW *stat_w; -WINDOW *turn_w; +static WINDOW *view_w; +static WINDOW *slot_w; +static WINDOW *scroll_w; +static WINDOW *stat_w; +static WINDOW *turn_w; int done_curses; int loaded, fired, changed, repaired; @@ -82,22 +82,40 @@ struct shipspecs *mc; /* ms->specs */ void initscreen(void) { - if (!SCREENTEST()) { + if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) { + err(1, "signal(SIGTSTP)"); + } + + if (initscr() == NULL) { errx(1, "Can't sail on this terminal."); } - /* initscr() already done in SCREENTEST() */ + if (STAT_R >= COLS || SCROLL_Y <= 0) { + errx(1, "Window/terminal not large enough."); + } + view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L); slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L); scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L); stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L); turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L); - done_curses++; + + if (view_w == NULL || + slot_w == NULL || + scroll_w == NULL || + stat_w == NULL || + turn_w == NULL) { + endwin(); + errx(1, "Curses initialization failed."); + } + leaveok(view_w, 1); leaveok(slot_w, 1); leaveok(stat_w, 1); leaveok(turn_w, 1); noecho(); cbreak(); + + done_curses++; } void @@ -477,6 +495,31 @@ draw_board(void) refresh(); } +/* Called after show_[od]bp. Shouldn't really exist... XXX */ +void +display_refresh_slot_w(void) +{ + blockalarm(); + wrefresh(slot_w); + unblockalarm(); +} + +void +display_show_obp(int which, bool show) +{ + wmove(slot_w, 0, which); + waddch(slot_w, show ? '1' + which : ' '); + mvwaddstr(slot_w, 1, 0, "OBP"); +} + +void +display_show_dbp(int which, bool show) +{ + wmove(slot_w, 2, which); + waddch(slot_w, show ? '1' + which : ' '); + mvwaddstr(slot_w, 3, 0, "DBP"); +} + void centerview(void) { -- cgit v1.2.3-56-ge451