From f68dad69ec60a4ba2680cb05ad03cdfc19aaa06a Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 25 Jul 2006 15:59:54 +0000 Subject: [PATCH] First stepn towards factoring out the curses interface. --- compmove.c | 1 - display.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++- edit.c | 1 + empire.c | 4 +- extern.h | 22 +++---- game.c | 27 +------- usermove.c | 2 +- util.c | 156 +--------------------------------------------- 8 files changed, 196 insertions(+), 195 deletions(-) diff --git a/compmove.c b/compmove.c index 462e46b..52a8dc7 100644 --- a/compmove.c +++ b/compmove.c @@ -23,7 +23,6 @@ For each move the user wants us to make, we do the following: #include #endif -#include #include "empire.h" #include "extern.h" diff --git a/display.c b/display.c index 59e4907..99abea7 100644 --- a/display.c +++ b/display.c @@ -1,4 +1,4 @@ -/* $Id: display.c,v 1.7 2000/07/28 05:12:50 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: display.c,v 1.8 2002/04/19 09:17:01 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -513,3 +513,179 @@ display_score () pos_str (1, cols-12, " User Comp",0,0,0,0,0,0,0,0); pos_str (2, cols-12, "%5d %5d", user_score, comp_score,0,0,0,0,0,0); } + +/* +Clear the end of a specified line starting at the specified column. +*/ + +void +clreol(linep, colp) +int linep, colp; +{ + (void) move (linep, colp); + (void) clrtoeol(); +} + +/* +Initialize the terminal. +*/ + +void +ttinit() +{ + (void) initscr(); + (void) noecho(); + (void) crmode(); +#ifdef A_COLOR + init_colors(); +#endif /* A_COLOR */ + lines = LINES; + cols = COLS; + if (lines > MAP_HEIGHT + NUMTOPS + 1) + lines = MAP_HEIGHT + NUMTOPS + 1; + if (cols > MAP_WIDTH + NUMSIDES) + cols = MAP_WIDTH + NUMSIDES; +} + + +/* +Clear the screen. We must also kill information maintained about the +display. +*/ + +void +clear_screen () { + (void) clear (); + (void) refresh (); + kill_display (); +} + +/* +Redraw the screen. +*/ + +void +redraw () { + (void) clearok (curscr, TRUE); + (void) refresh (); +} + +/* +Wait a little bit to give user a chance to see a message. We refresh +the screen and pause for a few milliseconds. +*/ + +void +delay () { + int t = delay_time; + int i = 500; + (void) refresh (); + if (t > i) { + (void) move (LINES - 1, 0); + } + for (; t > 0; t -= i) { + (void) napms ((t > i) ? i : t); /* pause a bit */ + if (t > i) { + addstr ("*"); + refresh (); + } + } +} + +/* +Clean up the display. This routine gets called as we leave the game. +*/ + +void +close_disp() +{ + (void) move (LINES - 1, 0); + (void) clrtoeol (); + (void) refresh (); + (void) endwin (); +} + +/* +Position the cursor and output a string. +*/ + +void +pos_str1 (row, col, str, a, b, c, d, e, f, g, h) +int row, col; +char *str, *a; +int b, c, d, e, f, g, h; +{ + (void) move (row, col); + addprintf1 (str, a, b, c, d, e, f, g, h); +} +void +pos_str (row, col, str, a, b, c, d, e, f, g, h) +int row, col; +char *str; +int a, b, c, d, e, f, g, h; +{ + (void) move (row, col); + addprintf (str, a, b, c, d, e, f, g, h); +} + +void +/* VARARGS1 */ +addprintf (str, a, b, c, d, e, f, g, h) +char *str; +int a, b, c, d, e, f, g, h; +{ + char junkbuf[STRSIZE]; + + (void) sprintf (junkbuf, str, a, b, c, d, e, f, g, h); + (void) addstr (junkbuf); +} +void +/* VARARGS1 */ +addprintf1 (str, a, b, c, d, e, f, g, h) +char *str; +char *a; +int b, c, d, e, f, g, h; +{ + char junkbuf[STRSIZE]; + + (void) sprintf (junkbuf, str, a, b, c, d, e, f, g, h); + (void) addstr (junkbuf); +} +void +/* VARARGS1 */ +addprintf2 (str, a, b, c, d, e, f, g, h) +char *str; +char *a, *e, *f; +int b, c, d, g, h; +{ + char junkbuf[STRSIZE]; + + (void) sprintf (junkbuf, str, a, b, c, d, e, f, g, h); + (void) addstr (junkbuf); +} + +/* +Print a single cell in condensed format. +*/ + +extern char zoom_list[]; + +void +print_movie_cell (mbuf, row, col, row_inc, col_inc) +char *mbuf; +int row, col; +int row_inc, col_inc; +{ + int r, c; + char cell; + + cell = ' '; + for (r = row; r < row + row_inc; r++) + for (c = col; c < col + col_inc; c++) + if (strchr (zoom_list, mbuf[row_col_loc(r,c)]) + < strchr (zoom_list, cell)) + cell = mbuf[row_col_loc(r,c)]; + + (void) move (row/row_inc + NUMTOPS, col/col_inc); + (void) addch ((chtype)cell); +} diff --git a/edit.c b/edit.c index 093a5de..bcfab51 100644 --- a/edit.c +++ b/edit.c @@ -11,6 +11,7 @@ edit.c -- Routines to handle edit mode commands. */ +#include #ifdef SYSV #include #else diff --git a/empire.c b/empire.c index 79e415f..dadd14a 100644 --- a/empire.c +++ b/empire.c @@ -1,4 +1,4 @@ -/* $Id: empire.c,v 1.3 1994/12/01 15:54:33 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: empire.c,v 1.4 2000/07/28 05:12:51 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -32,7 +32,7 @@ empire () { clear_screen (); /* nothing on screen */ (void) move (7, 0); - ver (); + version (); pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n",0,0,0,0,0,0,0,0); (void) refresh (); diff --git a/extern.h b/extern.h index bac6b74..978fdf9 100644 --- a/extern.h +++ b/extern.h @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.6 2002/08/01 18:58:21 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: extern.h,v 1.7 2006/07/25 15:19:49 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -154,6 +154,15 @@ void display_score (); #ifdef A_COLOR void init_colors (); #endif /* A_COLOR */ +void redraw (); +void clear_screen (); +void delay (); +void close_disp (); +void pos_str (int row, int col, char *str, int a, int b, int c, int d, int e, int f, int g, int h); +void pos_str1 (int row, int col, char *str, char *a, int b, int c, int d, int e, int f, int g, int h); +void addprintf (char *str, int a, int b, int c, int d, int e, int f, int g, int h); +void addprintf1 (char *str, char *a, int b, int c, int d, int e, int f, int g, int h); +void addprintf2 (char *str, char *a, int b, int c, int d, char *e, char *f, int g, int h); void init_game (); /* game routines */ void save_game (); @@ -219,18 +228,9 @@ void ksend1 (char *buf, char *a, int b, int c, int d, int e, int f, int g, int h /* utility routines */ void ttinit (); -void redraw (); -void clear_screen (); -void delay (); -void close_disp (); -void pos_str (int row, int col, char *str, int a, int b, int c, int d, int e, int f, int g, int h); -void pos_str1 (int row, int col, char *str, char *a, int b, int c, int d, int e, int f, int g, int h); -void addprintf (char *str, int a, int b, int c, int d, int e, int f, int g, int h); -void addprintf1 (char *str, char *a, int b, int c, int d, int e, int f, int g, int h); -void addprintf2 (char *str, char *a, int b, int c, int d, char *e, char *f, int g, int h); void assert (char *expression, char *file, int line); void empend (); -void ver (); +void version (); char upper (char c); void tupper (char *str); void check (); diff --git a/game.c b/game.c index db36375..dd43760 100644 --- a/game.c +++ b/game.c @@ -17,8 +17,8 @@ game.c -- Routines to initialize, save, and restore a game. #include #endif +#include #include -#include #include "empire.h" #include "extern.h" @@ -832,28 +832,3 @@ int round; pos_str (0, 0, "Round %3d", (round + 1) / 2,0,0,0,0,0,0,0); } -/* -Print a single cell in condensed format. -*/ - -extern char zoom_list[]; - -void -print_movie_cell (mbuf, row, col, row_inc, col_inc) -char *mbuf; -int row, col; -int row_inc, col_inc; -{ - int r, c; - char cell; - - cell = ' '; - for (r = row; r < row + row_inc; r++) - for (c = col; c < col + col_inc; c++) - if (strchr (zoom_list, mbuf[row_col_loc(r,c)]) - < strchr (zoom_list, cell)) - cell = mbuf[row_col_loc(r,c)]; - - (void) move (row/row_inc + NUMTOPS, col/col_inc); - (void) addch ((chtype)cell); -} diff --git a/usermove.c b/usermove.c index 7b3edac..d858885 100644 --- a/usermove.c +++ b/usermove.c @@ -11,7 +11,7 @@ usermove.c -- Let the user move her troops. */ -#include +#include #include #include "empire.h" #include "extern.h" diff --git a/util.c b/util.c index 30a7f59..f7efa50 100644 --- a/util.c +++ b/util.c @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.3 2000/07/28 05:12:54 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: util.c,v 1.4 2006/07/25 15:20:30 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -11,7 +11,7 @@ util.c -- various utility routines. */ -#include +#include #include #include #include "empire.h" @@ -48,156 +48,6 @@ char c; else return c; } -/* -Clear the end of a specified line starting at the specified column. -*/ - -void -clreol(linep, colp) -int linep, colp; -{ - (void) move (linep, colp); - (void) clrtoeol(); -} - -/* -Initialize the terminal. -*/ - -void -ttinit() -{ - (void) initscr(); - (void) noecho(); - (void) crmode(); -#ifdef A_COLOR - init_colors(); -#endif /* A_COLOR */ - lines = LINES; - cols = COLS; - if (lines > MAP_HEIGHT + NUMTOPS + 1) - lines = MAP_HEIGHT + NUMTOPS + 1; - if (cols > MAP_WIDTH + NUMSIDES) - cols = MAP_WIDTH + NUMSIDES; -} - - -/* -Clear the screen. We must also kill information maintained about the -display. -*/ - -void -clear_screen () { - (void) clear (); - (void) refresh (); - kill_display (); -} - -/* -Redraw the screen. -*/ - -void -redraw () { - (void) clearok (curscr, TRUE); - (void) refresh (); -} - -/* -Wait a little bit to give user a chance to see a message. We refresh -the screen and pause for a few milliseconds. -*/ - -void -delay () { - int t = delay_time; - int i = 500; - (void) refresh (); - if (t > i) { - (void) move (LINES - 1, 0); - } - for (; t > 0; t -= i) { - (void) napms ((t > i) ? i : t); /* pause a bit */ - if (t > i) { - addstr ("*"); - refresh (); - } - } -} - -/* -Clean up the display. This routine gets called as we leave the game. -*/ - -void -close_disp() -{ - (void) move (LINES - 1, 0); - (void) clrtoeol (); - (void) refresh (); - (void) endwin (); -} - -/* -Position the cursor and output a string. -*/ - -void -pos_str1 (row, col, str, a, b, c, d, e, f, g, h) -int row, col; -char *str, *a; -int b, c, d, e, f, g, h; -{ - (void) move (row, col); - addprintf1 (str, a, b, c, d, e, f, g, h); -} -void -pos_str (row, col, str, a, b, c, d, e, f, g, h) -int row, col; -char *str; -int a, b, c, d, e, f, g, h; -{ - (void) move (row, col); - addprintf (str, a, b, c, d, e, f, g, h); -} - -void -/* VARARGS1 */ -addprintf (str, a, b, c, d, e, f, g, h) -char *str; -int a, b, c, d, e, f, g, h; -{ - char junkbuf[STRSIZE]; - - (void) sprintf (junkbuf, str, a, b, c, d, e, f, g, h); - (void) addstr (junkbuf); -} -void -/* VARARGS1 */ -addprintf1 (str, a, b, c, d, e, f, g, h) -char *str; -char *a; -int b, c, d, e, f, g, h; -{ - char junkbuf[STRSIZE]; - - (void) sprintf (junkbuf, str, a, b, c, d, e, f, g, h); - (void) addstr (junkbuf); -} -void -/* VARARGS1 */ -addprintf2 (str, a, b, c, d, e, f, g, h) -char *str; -char *a, *e, *f; -int b, c, d, g, h; -{ - char junkbuf[STRSIZE]; - - (void) sprintf (junkbuf, str, a, b, c, d, e, f, g, h); - (void) addstr (junkbuf); -} - /* Report a bug. */ @@ -239,7 +89,7 @@ empend () */ void -ver () +version () { (void) addstr ("EMPIRE, Version 5.00 site Amdahl 1-Apr-1988"); } -- 2.43.0