diff options
author | peter <peter@FreeBSD.org> | 2001-05-17 08:21:06 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2001-05-17 08:21:06 +0000 |
commit | b7ada7f2444f41b672faef4f93e446bdf8584cf9 (patch) | |
tree | e83b2ef47811e687a6c54035c9af6d4a2b7f14e1 /contrib/ncurses/test | |
parent | a81407a537bfd1ab9e48c69007eb6b30e66d271b (diff) | |
download | FreeBSD-src-b7ada7f2444f41b672faef4f93e446bdf8584cf9.zip FreeBSD-src-b7ada7f2444f41b672faef4f93e446bdf8584cf9.tar.gz |
Import ncurses-5.2-20010512 onto the vendor branch
Obtained from: ftp://dickey.his.com/ncurses/
Diffstat (limited to 'contrib/ncurses/test')
-rw-r--r-- | contrib/ncurses/test/Makefile.in | 14 | ||||
-rw-r--r-- | contrib/ncurses/test/bs.c | 812 | ||||
-rw-r--r-- | contrib/ncurses/test/cardfile.c | 8 | ||||
-rwxr-xr-x | contrib/ncurses/test/configure | 114 | ||||
-rw-r--r-- | contrib/ncurses/test/configure.in | 8 | ||||
-rw-r--r-- | contrib/ncurses/test/filter.c | 5 | ||||
-rw-r--r-- | contrib/ncurses/test/gdc.c | 5 | ||||
-rw-r--r-- | contrib/ncurses/test/hashtest.c | 314 | ||||
-rw-r--r-- | contrib/ncurses/test/knight.c | 667 | ||||
-rw-r--r-- | contrib/ncurses/test/lrtest.c | 27 | ||||
-rw-r--r-- | contrib/ncurses/test/ncurses.c | 77 | ||||
-rw-r--r-- | contrib/ncurses/test/newdemo.c | 492 | ||||
-rw-r--r-- | contrib/ncurses/test/railroad.c | 7 | ||||
-rw-r--r-- | contrib/ncurses/test/tclock.c | 26 | ||||
-rw-r--r-- | contrib/ncurses/test/test.priv.h | 4 | ||||
-rw-r--r-- | contrib/ncurses/test/testcurs.c | 8 | ||||
-rw-r--r-- | contrib/ncurses/test/testscanw.c | 47 | ||||
-rw-r--r-- | contrib/ncurses/test/view.c | 56 | ||||
-rw-r--r-- | contrib/ncurses/test/worm.c | 7 |
19 files changed, 1441 insertions, 1257 deletions
diff --git a/contrib/ncurses/test/Makefile.in b/contrib/ncurses/test/Makefile.in index 9f573ba..b99957b 100644 --- a/contrib/ncurses/test/Makefile.in +++ b/contrib/ncurses/test/Makefile.in @@ -1,6 +1,6 @@ -# $Id: Makefile.in,v 1.58 2000/05/28 01:28:39 tom Exp $ +# $Id: Makefile.in,v 1.61 2001/03/24 19:53:31 tom Exp $ ############################################################################## -# Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. # +# Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -45,6 +45,8 @@ exec_prefix = @exec_prefix@ libdir = @libdir@ includedir = @includedir@ +LIBTOOL = @LIBTOOL@ + CC = @CC@ CPP = @CPP@ @@ -53,6 +55,7 @@ CPPFLAGS = -I../test -I$(srcdir) @CPPFLAGS@ -DHAVE_CONFIG_H CCFLAGS = $(CPPFLAGS) $(CFLAGS) +CFLAGS_LIBTOOL = $(CCFLAGS) CFLAGS_NORMAL = $(CCFLAGS) CFLAGS_DEBUG = $(CCFLAGS) @CC_G_OPT@ -DTRACE CFLAGS_PROFILE = $(CCFLAGS) -pg @@ -66,10 +69,11 @@ LOCAL_LIBS = @TEST_DEPS@ MATH_LIB = @MATH_LIB@ LD = @LD@ -LINK = @LINK_TESTS@ $(CC) +LINK = @LINK_TESTS@ $(LIBTOOL) $(CC) LDFLAGS = @LD_MODEL@ @TEST_ARGS@ @LIBS@ @EXTRA_LIBS@ @LOCAL_LDFLAGS@ @LDFLAGS@ +LDFLAGS_LIBTOOL = $(LDFLAGS) LDFLAGS_NORMAL = $(LDFLAGS) LDFLAGS_DEBUG = $(LDFLAGS) @CC_G_OPT@ LDFLAGS_PROFILE = $(LDFLAGS) -pg @@ -197,10 +201,10 @@ uninstall.libs: uninstall.test: mostlyclean :: - -rm -f core tags TAGS *~ *.ln *.atac trace + -rm -f core tags TAGS *~ *.i *.ln *.atac trace clean :: mostlyclean - -rm -rf *.o screendump *.lis $(TESTS) + -rm -rf *.o screendump *.lis $(TESTS) .libs distclean :: clean -rm -f Makefile ncurses_cfg.h config.* diff --git a/contrib/ncurses/test/bs.c b/contrib/ncurses/test/bs.c index 368abcd..3a22c1d 100644 --- a/contrib/ncurses/test/bs.c +++ b/contrib/ncurses/test/bs.c @@ -7,7 +7,7 @@ * v2.0 featuring strict ANSI/POSIX conformance, November 1993. * v2.1 with ncurses mouse support, September 1995 * - * $Id: bs.c,v 1.24 1999/08/21 23:14:38 tom Exp $ + * $Id: bs.c,v 1.29 2001/04/14 22:36:05 Erik.Sigra Exp $ */ #include <test.priv.h> @@ -22,7 +22,7 @@ #define SIGIOT SIGABRT #endif -#ifndef A_UNDERLINE /* BSD curses */ +#ifndef A_UNDERLINE /* BSD curses */ #define beep() write(1,"\007",1); #define cbreak crmode #define saveterm savetty @@ -57,7 +57,7 @@ static int getcoord(int); /* display symbols */ #define SHOWHIT '*' #define SHOWSPLASH ' ' -#define IS_SHIP(c) (isupper(c) ? TRUE : FALSE) +#define IS_SHIP(c) (isupper(CharOf(c)) ? TRUE : FALSE) /* how to position us on player board */ #define PYBASE 3 @@ -79,12 +79,12 @@ static int getcoord(int); /* other board locations */ #define COLWIDTH 80 -#define PROMPTLINE 21 /* prompt line */ +#define PROMPTLINE 21 /* prompt line */ #define SYBASE CYBASE + BDEPTH + 3 /* move key diagram */ #define SXBASE 63 -#define MYBASE SYBASE - 1 /* diagram caption */ +#define MYBASE SYBASE - 1 /* diagram caption */ #define MXBASE 64 -#define HYBASE SYBASE - 1 /* help area */ +#define HYBASE SYBASE - 1 /* help area */ #define HXBASE 0 /* this will need to be changed if BWIDTH changes */ @@ -108,15 +108,16 @@ static char dftname[] = "stranger"; #define NW 5 #define N 6 #define NE 7 -static int xincr[8] = {1, 1, 0, -1, -1, -1, 0, 1}; -static int yincr[8] = {0, 1, 1, 1, 0, -1, -1, -1}; +static int xincr[8] = +{1, 1, 0, -1, -1, -1, 0, 1}; +static int yincr[8] = +{0, 1, 1, 1, 0, -1, -1, -1}; /* current ship position and direction */ static int curx = (BWIDTH / 2); static int cury = (BDEPTH / 2); -typedef struct -{ +typedef struct { char *name; /* name of the ship type */ int hits; /* how many times has this ship been hit? */ char symbol; /* symbol for game purposes */ @@ -124,60 +125,60 @@ typedef struct char x, y; /* coordinates of ship start point */ unsigned char dir; /* direction of `bow' */ bool placed; /* has it been placed on the board? */ -} -ship_t; +} ship_t; -static bool checkplace(int b, ship_t *ss, int vis); +static bool checkplace(int b, ship_t * ss, int vis); #define SHIPIT(name, symbol, length) { name, 0, symbol, length, 0,0, 0, FALSE } static ship_t plyship[SHIPTYPES] = { - SHIPIT(carrier, 'A', 5), - SHIPIT(battle, 'B', 4), - SHIPIT(destroy, 'D', 3), - SHIPIT(sub, 'S', 3), - SHIPIT(ptboat, 'P', 2), + SHIPIT(carrier, 'A', 5), + SHIPIT(battle, 'B', 4), + SHIPIT(destroy, 'D', 3), + SHIPIT(sub, 'S', 3), + SHIPIT(ptboat, 'P', 2), }; static ship_t cpuship[SHIPTYPES] = { - SHIPIT(carrier, 'A', 5), - SHIPIT(battle, 'B', 4), - SHIPIT(destroy, 'D', 3), - SHIPIT(sub, 'S', 3), - SHIPIT(ptboat, 'P', 2), + SHIPIT(carrier, 'A', 5), + SHIPIT(battle, 'B', 4), + SHIPIT(destroy, 'D', 3), + SHIPIT(sub, 'S', 3), + SHIPIT(ptboat, 'P', 2), }; /* "Hits" board, and main board. */ static char hits[2][BWIDTH][BDEPTH]; static char board[2][BWIDTH][BDEPTH]; -static int turn; /* 0=player, 1=computer */ -static int plywon=0, cpuwon=0; /* How many games has each won? */ +static int turn; /* 0=player, 1=computer */ +static int plywon = 0, cpuwon = 0; /* How many games has each won? */ static int salvo, blitz, closepack; #define PR (void)addstr -static RETSIGTYPE uninitgame(int sig) GCC_NORETURN; +static RETSIGTYPE +uninitgame(int sig) GCC_NORETURN; -static RETSIGTYPE uninitgame(int sig GCC_UNUSED) + static RETSIGTYPE uninitgame(int sig GCC_UNUSED) /* end the game, either normally or due to signal */ { clear(); - (void)refresh(); - (void)resetterm(); - (void)echo(); - (void)endwin(); + (void) refresh(); + (void) resetterm(); + (void) echo(); + (void) endwin(); exit(EXIT_FAILURE); } -static void announceopts(void) +static void +announceopts(void) /* announce which game options are enabled */ { - if (salvo || blitz || closepack) - { + if (salvo || blitz || closepack) { (void) printw("Playing optional game ("); if (salvo) (void) printw("salvo, "); @@ -191,45 +192,43 @@ static void announceopts(void) (void) printw("closepack)"); else (void) printw("noclosepack)"); - } - else + } else (void) printw( - "Playing standard game (noblitz, nosalvo, noclosepack)"); + "Playing standard game (noblitz, nosalvo, noclosepack)"); } -static void intro(void) +static void +intro(void) { char *tmpname; - srand((unsigned)(time(0L)+getpid())); /* Kick the random number generator */ + srand((unsigned) (time(0L) + getpid())); /* Kick the random number generator */ - (void) signal(SIGINT,uninitgame); - (void) signal(SIGINT,uninitgame); - (void) signal(SIGIOT,uninitgame); /* for assert(3) */ - if(signal(SIGQUIT,SIG_IGN) != SIG_IGN) - (void)signal(SIGQUIT,uninitgame); + (void) signal(SIGINT, uninitgame); + (void) signal(SIGINT, uninitgame); + (void) signal(SIGIOT, uninitgame); /* for assert(3) */ + if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) + (void) signal(SIGQUIT, uninitgame); - if((tmpname = getlogin()) != 0) - { - (void)strcpy(name,tmpname); + if ((tmpname = getlogin()) != 0) { + (void) strcpy(name, tmpname); name[0] = toupper(name[0]); - } - else - (void)strcpy(name,dftname); + } else + (void) strcpy(name, dftname); - (void)initscr(); + (void) initscr(); #ifdef KEY_MIN keypad(stdscr, TRUE); #endif /* KEY_MIN */ - (void)saveterm(); - (void)nonl(); - (void)cbreak(); - (void)noecho(); + (void) saveterm(); + (void) nonl(); + (void) cbreak(); + (void) noecho(); #ifdef PENGUIN - (void)clear(); - (void)mvaddstr(4,29,"Welcome to Battleship!"); - (void)move(8,0); + (void) clear(); + (void) mvaddstr(4, 29, "Welcome to Battleship!"); + (void) move(8, 0); PR(" \\\n"); PR(" \\ \\ \\\n"); PR(" \\ \\ \\ \\ \\_____________\n"); @@ -241,7 +240,8 @@ static void intro(void) PR(" \\ /\n"); PR(" \\___________________________________________________/\n"); - (void) mvaddstr(22,27,"Hit any key to continue..."); (void)refresh(); + (void) mvaddstr(22, 27, "Hit any key to continue..."); + (void) refresh(); (void) getch(); #endif /* PENGUIN */ @@ -259,12 +259,13 @@ static void intro(void) #endif /* A_COLOR */ #ifdef NCURSES_MOUSE_VERSION - (void) mousemask(BUTTON1_CLICKED, (mmask_t *)NULL); -#endif /* NCURSES_MOUSE_VERSION*/ -} + (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL); +#endif /* NCURSES_MOUSE_VERSION */ +} /* VARARGS1 */ -static void prompt(int n, NCURSES_CONST char *f, const char *s) +static void +prompt(int n, NCURSES_CONST char *f, const char *s) /* print a message at the prompt line */ { (void) move(PROMPTLINE + n, 0); @@ -273,92 +274,90 @@ static void prompt(int n, NCURSES_CONST char *f, const char *s) (void) refresh(); } -static void error(NCURSES_CONST char *s) +static void +error(NCURSES_CONST char *s) { (void) move(PROMPTLINE + 2, 0); (void) clrtoeol(); - if (s) - { + if (s) { (void) addstr(s); (void) beep(); } } -static void placeship(int b, ship_t *ss, int vis) +static void +placeship(int b, ship_t * ss, int vis) { int l; - for(l = 0; l < ss->length; ++l) - { + for (l = 0; l < ss->length; ++l) { int newx = ss->x + l * xincr[ss->dir]; int newy = ss->y + l * yincr[ss->dir]; board[b][newx][newy] = ss->symbol; - if (vis) - { + if (vis) { pgoto(newy, newx); - (void) addch((chtype)ss->symbol); + (void) addch((chtype) ss->symbol); } } ss->hits = 0; } -static int rnd(int n) +static int +rnd(int n) { - return(((rand() & 0x7FFF) % n)); + return (((rand() & 0x7FFF) % n)); } -static void randomplace(int b, ship_t *ss) +static void +randomplace(int b, ship_t * ss) /* generate a valid random ship placement into px,py */ { - register int bwidth = BWIDTH - ss->length; - register int bdepth = BDEPTH - ss->length; do { - ss->y = rnd(bdepth); - ss->x = rnd(bwidth); ss->dir = rnd(2) ? E : S; + ss->x = rnd(BWIDTH - (ss->dir == E ? ss->length : 0)); + ss->y = rnd(BDEPTH - (ss->dir == S ? ss->length : 0)); } while (!checkplace(b, ss, FALSE)); } -static void initgame(void) +static void +initgame(void) { int i, j, unplaced; ship_t *ss; (void) clear(); - (void) mvaddstr(0,35,"BATTLESHIPS"); + (void) mvaddstr(0, 35, "BATTLESHIPS"); (void) move(PROMPTLINE + 2, 0); announceopts(); memset(board, 0, sizeof(char) * BWIDTH * BDEPTH * 2); - memset(hits, 0, sizeof(char) * BWIDTH * BDEPTH * 2); - for (i = 0; i < SHIPTYPES; i++) - { + memset(hits, 0, sizeof(char) * BWIDTH * BDEPTH * 2); + for (i = 0; i < SHIPTYPES; i++) { ss = cpuship + i; ss->x = - ss->y = - ss->dir = - ss->hits = 0; + ss->y = + ss->dir = + ss->hits = 0; ss->placed = FALSE; ss = plyship + i; ss->x = - ss->y = - ss->dir = - ss->hits = 0; + ss->y = + ss->dir = + ss->hits = 0; ss->placed = FALSE; } /* draw empty boards */ (void) mvaddstr(PYBASE - 2, PXBASE + 5, "Main Board"); - (void) mvaddstr(PYBASE - 1, PXBASE - 3,numbers); - for(i=0; i < BDEPTH; ++i) - { - (void) mvaddch(PYBASE + i, PXBASE - 3, (chtype)(i + 'A')); + (void) mvaddstr(PYBASE - 1, PXBASE - 3, numbers); + for (i = 0; i < BDEPTH; ++i) { + (void) mvaddch(PYBASE + i, PXBASE - 3, (chtype) (i + 'A')); #ifdef A_COLOR if (has_colors()) attron(COLOR_PAIR(COLOR_BLUE)); @@ -370,14 +369,13 @@ static void initgame(void) attrset(0); #endif /* A_COLOR */ (void) addch(' '); - (void) addch((chtype)(i + 'A')); + (void) addch((chtype) (i + 'A')); } - (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3,numbers); - (void) mvaddstr(CYBASE - 2, CXBASE + 7,"Hit/Miss Board"); + (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3, numbers); + (void) mvaddstr(CYBASE - 2, CXBASE + 7, "Hit/Miss Board"); (void) mvaddstr(CYBASE - 1, CXBASE - 3, numbers); - for(i=0; i < BDEPTH; ++i) - { - (void) mvaddch(CYBASE + i, CXBASE - 3, (chtype)(i + 'A')); + for (i = 0; i < BDEPTH; ++i) { + (void) mvaddch(CYBASE + i, CXBASE - 3, (chtype) (i + 'A')); #ifdef A_COLOR if (has_colors()) attron(COLOR_PAIR(COLOR_BLUE)); @@ -389,39 +387,38 @@ static void initgame(void) attrset(0); #endif /* A_COLOR */ (void) addch(' '); - (void) addch((chtype)(i + 'A')); + (void) addch((chtype) (i + 'A')); } - (void) mvaddstr(CYBASE + BDEPTH,CXBASE - 3,numbers); + (void) mvaddstr(CYBASE + BDEPTH, CXBASE - 3, numbers); - (void) mvprintw(HYBASE, HXBASE, + (void) mvprintw(HYBASE, HXBASE, "To position your ships: move the cursor to a spot, then"); - (void) mvprintw(HYBASE+1,HXBASE, + (void) mvprintw(HYBASE + 1, HXBASE, "type the first letter of a ship type to select it, then"); - (void) mvprintw(HYBASE+2,HXBASE, + (void) mvprintw(HYBASE + 2, HXBASE, "type a direction ([hjkl] or [4862]), indicating how the"); - (void) mvprintw(HYBASE+3,HXBASE, + (void) mvprintw(HYBASE + 3, HXBASE, "ship should be pointed. You may also type a ship letter"); - (void) mvprintw(HYBASE+4,HXBASE, + (void) mvprintw(HYBASE + 4, HXBASE, "followed by `r' to position it randomly, or type `R' to"); - (void) mvprintw(HYBASE+5,HXBASE, + (void) mvprintw(HYBASE + 5, HXBASE, "place all remaining ships randomly."); - (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:"); - (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9"); - (void) mvaddstr(SYBASE+1, SXBASE, " \\|/ \\|/ "); - (void) mvaddstr(SYBASE+2, SXBASE, "h-+-l 4-+-6"); - (void) mvaddstr(SYBASE+3, SXBASE, " /|\\ /|\\ "); - (void) mvaddstr(SYBASE+4, SXBASE, "b j n 1 2 3"); + (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:"); + (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9"); + (void) mvaddstr(SYBASE + 1, SXBASE, " \\|/ \\|/ "); + (void) mvaddstr(SYBASE + 2, SXBASE, "h-+-l 4-+-6"); + (void) mvaddstr(SYBASE + 3, SXBASE, " /|\\ /|\\ "); + (void) mvaddstr(SYBASE + 4, SXBASE, "b j n 1 2 3"); /* have the computer place ships */ - for(ss = cpuship; ss < cpuship + SHIPTYPES; ss++) - { + for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++) { randomplace(COMPUTER, ss); placeship(COMPUTER, ss, FALSE); } - ss = (ship_t *)NULL; + ss = (ship_t *) NULL; do { char c, docked[SHIPTYPES + 2], *cp = docked; @@ -433,7 +430,7 @@ static void initgame(void) *cp = '\0'; /* get a command letter */ - prompt(1, "Type one of [%s] to pick a ship.", docked+1); + prompt(1, "Type one of [%s] to pick a ship.", docked + 1); do { c = getcoord(PLAYER); } while @@ -441,8 +438,7 @@ static void initgame(void) if (c == 'R') (void) ungetch('R'); - else - { + else { /* map that into the corresponding symbol */ for (ss = plyship; ss < plyship + SHIPTYPES; ss++) if (ss->symbol == c) @@ -457,48 +453,50 @@ static void initgame(void) } while (!strchr("hjklrR", c) || c == FF); - if (c == FF) - { - (void)clearok(stdscr, TRUE); - (void)refresh(); - } - else if (c == 'r') - { + if (c == FF) { + (void) clearok(stdscr, TRUE); + (void) refresh(); + } else if (c == 'r') { prompt(1, "Random-placing your %s", ss->name); randomplace(PLAYER, ss); placeship(PLAYER, ss, TRUE); - error((char *)NULL); + error((char *) NULL); ss->placed = TRUE; - } - else if (c == 'R') - { + } else if (c == 'R') { prompt(1, "Placing the rest of your fleet at random...", ""); for (ss = plyship; ss < plyship + SHIPTYPES; ss++) - if (!ss->placed) - { + if (!ss->placed) { randomplace(PLAYER, ss); placeship(PLAYER, ss, TRUE); ss->placed = TRUE; } - error((char *)NULL); - } - else if (strchr("hjkl8462", c)) - { + error((char *) NULL); + } else if (strchr("hjkl8462", c)) { ss->x = curx; ss->y = cury; - switch(c) - { - case 'k': case '8': ss->dir = N; break; - case 'j': case '2': ss->dir = S; break; - case 'h': case '4': ss->dir = W; break; - case 'l': case '6': ss->dir = E; break; - } + switch (c) { + case 'k': + case '8': + ss->dir = N; + break; + case 'j': + case '2': + ss->dir = S; + break; + case 'h': + case '4': + ss->dir = W; + break; + case 'l': + case '6': + ss->dir = E; + break; + } - if (checkplace(PLAYER, ss, TRUE)) - { + if (checkplace(PLAYER, ss, TRUE)) { placeship(PLAYER, ss, TRUE); - error((char *)NULL); + error((char *) NULL); ss->placed = TRUE; } } @@ -510,116 +508,128 @@ static void initgame(void) turn = rnd(2); - (void) mvprintw(HYBASE, HXBASE, + (void) mvprintw(HYBASE, HXBASE, "To fire, move the cursor to your chosen aiming point "); - (void) mvprintw(HYBASE+1, HXBASE, + (void) mvprintw(HYBASE + 1, HXBASE, "and strike any key other than a motion key. "); - (void) mvprintw(HYBASE+2, HXBASE, + (void) mvprintw(HYBASE + 2, HXBASE, " "); - (void) mvprintw(HYBASE+3, HXBASE, + (void) mvprintw(HYBASE + 3, HXBASE, " "); - (void) mvprintw(HYBASE+4, HXBASE, + (void) mvprintw(HYBASE + 4, HXBASE, " "); - (void) mvprintw(HYBASE+5, HXBASE, + (void) mvprintw(HYBASE + 5, HXBASE, " "); (void) prompt(0, "Press any key to start...", ""); (void) getch(); } -static int getcoord(int atcpu) +static int +getcoord(int atcpu) { int ny, nx, c; if (atcpu) - cgoto(cury,curx); + cgoto(cury, curx); else pgoto(cury, curx); - (void)refresh(); - for (;;) - { - if (atcpu) - { - (void) mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury); + (void) refresh(); + for (;;) { + if (atcpu) { + (void) mvprintw(CYBASE + BDEPTH + 1, CXBASE + 11, "(%d, %c)", + curx, 'A' + cury); cgoto(cury, curx); - } - else - { - (void) mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury); + } else { + (void) mvprintw(PYBASE + BDEPTH + 1, PXBASE + 11, "(%d, %c)", + curx, 'A' + cury); pgoto(cury, curx); } - switch(c = getch()) - { - case 'k': case '8': + switch (c = getch()) { + case 'k': + case '8': #ifdef KEY_MIN case KEY_UP: #endif /* KEY_MIN */ - ny = cury+BDEPTH-1; nx = curx; + ny = cury + BDEPTH - 1; + nx = curx; break; - case 'j': case '2': + case 'j': + case '2': #ifdef KEY_MIN case KEY_DOWN: #endif /* KEY_MIN */ - ny = cury+1; nx = curx; + ny = cury + 1; + nx = curx; break; - case 'h': case '4': + case 'h': + case '4': #ifdef KEY_MIN case KEY_LEFT: #endif /* KEY_MIN */ - ny = cury; nx = curx+BWIDTH-1; + ny = cury; + nx = curx + BWIDTH - 1; break; - case 'l': case '6': + case 'l': + case '6': #ifdef KEY_MIN case KEY_RIGHT: #endif /* KEY_MIN */ - ny = cury; nx = curx+1; + ny = cury; + nx = curx + 1; break; - case 'y': case '7': + case 'y': + case '7': #ifdef KEY_MIN case KEY_A1: #endif /* KEY_MIN */ - ny = cury+BDEPTH-1; nx = curx+BWIDTH-1; + ny = cury + BDEPTH - 1; + nx = curx + BWIDTH - 1; break; - case 'b': case '1': + case 'b': + case '1': #ifdef KEY_MIN case KEY_C1: #endif /* KEY_MIN */ - ny = cury+1; nx = curx+BWIDTH-1; + ny = cury + 1; + nx = curx + BWIDTH - 1; break; - case 'u': case '9': + case 'u': + case '9': #ifdef KEY_MIN case KEY_A3: #endif /* KEY_MIN */ - ny = cury+BDEPTH-1; nx = curx+1; + ny = cury + BDEPTH - 1; + nx = curx + 1; break; - case 'n': case '3': + case 'n': + case '3': #ifdef KEY_MIN case KEY_C3: #endif /* KEY_MIN */ - ny = cury+1; nx = curx+1; + ny = cury + 1; + nx = curx + 1; break; case FF: - nx = curx; ny = cury; - (void)clearok(stdscr, TRUE); - (void)refresh(); + nx = curx; + ny = cury; + (void) clearok(stdscr, TRUE); + (void) refresh(); break; #ifdef NCURSES_MOUSE_VERSION case KEY_MOUSE: { - MEVENT myevent; + MEVENT myevent; getmouse(&myevent); if (atcpu - && myevent.y >= CY(0) && myevent.y <= CY(BDEPTH) - && myevent.x >= CX(0) && myevent.x <= CX(BDEPTH)) - { + && myevent.y >= CY(0) && myevent.y <= CY(BDEPTH) + && myevent.x >= CX(0) && myevent.x <= CX(BDEPTH)) { curx = CXINV(myevent.x); cury = CYINV(myevent.y); - return(' '); - } - else - { + return (' '); + } else { beep(); continue; } @@ -632,7 +642,7 @@ static int getcoord(int atcpu) (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " "); else (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " "); - return(c); + return (c); } curx = nx % BWIDTH; @@ -640,48 +650,46 @@ static int getcoord(int atcpu) } } -static bool collidecheck(int b, int y, int x) +static bool +collidecheck(int b, int y, int x) /* is this location on the selected zboard adjacent to a ship? */ { bool collide; /* anything on the square */ if ((collide = IS_SHIP(board[b][x][y])) != FALSE) - return(collide); + return (collide); /* anything on the neighbors */ - if (!closepack) - { + if (!closepack) { int i; - for (i = 0; i < 8; i++) - { + for (i = 0; i < 8; i++) { int xend, yend; yend = y + yincr[i]; xend = x + xincr[i]; if (ONBOARD(xend, yend) - && IS_SHIP(board[b][xend][yend])) { + && IS_SHIP(board[b][xend][yend])) { collide = TRUE; break; } } } - return(collide); + return (collide); } -static bool checkplace(int b, ship_t *ss, int vis) +static bool +checkplace(int b, ship_t * ss, int vis) { int l, xend, yend; /* first, check for board edges */ - xend = ss->x + ss->length * xincr[ss->dir]; - yend = ss->y + ss->length * yincr[ss->dir]; - if (!ONBOARD(xend, yend)) - { + xend = ss->x + (ss->length - 1) * xincr[ss->dir]; + yend = ss->y + (ss->length - 1) * yincr[ss->dir]; + if (!ONBOARD(xend, yend)) { if (vis) - switch(rnd(3)) - { + switch (rnd(3)) { case 0: error("Ship is hanging from the edge of the world"); break; @@ -692,50 +700,48 @@ static bool checkplace(int b, ship_t *ss, int vis) error("Figure I won't find it if you put it there?"); break; } - return(FALSE); + return (FALSE); } - for(l = 0; l < ss->length; ++l) - { - if(collidecheck(b, ss->y+l*yincr[ss->dir], ss->x+l*xincr[ss->dir])) - { + for (l = 0; l < ss->length; ++l) { + if (collidecheck(b, ss->y + l * yincr[ss->dir], ss->x + l * xincr[ss->dir])) { if (vis) - switch(rnd(3)) - { - case 0: - error("There's already a ship there"); - break; - case 1: - error("Collision alert! Aaaaaagh!"); - break; - case 2: - error("Er, Admiral, what about the other ship?"); - break; - } - return(FALSE); - } + switch (rnd(3)) { + case 0: + error("There's already a ship there"); + break; + case 1: + error("Collision alert! Aaaaaagh!"); + break; + case 2: + error("Er, Admiral, what about the other ship?"); + break; + } + return (FALSE); } - return(TRUE); + } + return (TRUE); } -static int awinna(void) +static int +awinna(void) { int i, j; ship_t *ss; - for(i=0; i<2; ++i) - { + for (i = 0; i < 2; ++i) { ss = (i) ? cpuship : plyship; - for(j=0; j < SHIPTYPES; ++j, ++ss) - if(ss->length > ss->hits) + for (j = 0; j < SHIPTYPES; ++j, ++ss) + if (ss->length > ss->hits) break; if (j == SHIPTYPES) - return(OTHER); + return (OTHER); } - return(-1); + return (-1); } -static ship_t *hitship(int x, int y) +static ship_t * +hitship(int x, int y) /* register a hit on the targeted ship */ { ship_t *sb, *ss; @@ -744,85 +750,88 @@ static ship_t *hitship(int x, int y) getyx(stdscr, oldy, oldx); sb = (turn) ? plyship : cpuship; - if((sym = board[OTHER][x][y]) == 0) - return((ship_t *)NULL); - for(ss = sb; ss < sb + SHIPTYPES; ++ss) - if(ss->symbol == sym) - { + if ((sym = board[OTHER][x][y]) == 0) + return ((ship_t *) NULL); + for (ss = sb; ss < sb + SHIPTYPES; ++ss) + if (ss->symbol == sym) { if (++ss->hits < ss->length) /* still afloat? */ - return((ship_t *)NULL); - else /* sunk! */ - { + return ((ship_t *) NULL); + else { /* sunk! */ int i, j; if (!closepack) - for (j = -1; j <= 1; j++) - { + for (j = -1; j <= 1; j++) { int bx = ss->x + j * xincr[(ss->dir + 2) % 8]; int by = ss->y + j * yincr[(ss->dir + 2) % 8]; - for (i = -1; i <= ss->length; ++i) - { + for (i = -1; i <= ss->length; ++i) { int x1, y1; - + x1 = bx + i * xincr[ss->dir]; y1 = by + i * yincr[ss->dir]; - if (ONBOARD(x1, y1)) - { + if (ONBOARD(x1, y1)) { hits[turn][x1][y1] = MARK_MISS; - if (turn % 2 == PLAYER) - { + if (turn % 2 == PLAYER) { cgoto(y1, x1); #ifdef A_COLOR if (has_colors()) attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ - (void)addch(MARK_MISS); + (void) addch(MARK_MISS); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ + } else { + pgoto(y1, x1); + (void) addch(SHOWSPLASH); } } } } - for (i = 0; i < ss->length; ++i) - { + for (i = 0; i < ss->length; ++i) { int x1 = ss->x + i * xincr[ss->dir]; int y1 = ss->y + i * yincr[ss->dir]; hits[turn][x1][y1] = ss->symbol; - if (turn % 2 == PLAYER) - { + if (turn % 2 == PLAYER) { cgoto(y1, x1); - (void) addch((chtype)(ss->symbol)); + (void) addch((chtype) (ss->symbol)); + } else { + pgoto(y1, x1); +#ifdef A_COLOR + if (has_colors()) + attron(COLOR_PAIR(COLOR_RED)); +#endif /* A_COLOR */ + (void) addch(SHOWHIT); +#ifdef A_COLOR + attrset(0); +#endif /* A_COLOR */ } } (void) move(oldy, oldx); - return(ss); + return (ss); } } (void) move(oldy, oldx); - return((ship_t *)NULL); + return ((ship_t *) NULL); } -static int plyturn(void) +static bool +plyturn(void) { ship_t *ss; bool hit; NCURSES_CONST char *m = NULL; prompt(1, "Where do you want to shoot? ", ""); - for (;;) - { + for (;;) { (void) getcoord(COMPUTER); - if (hits[PLAYER][curx][cury]) - { + if (hits[PLAYER][curx][cury]) { prompt(1, "You shelled this spot already! Try again.", ""); beep(); - } - else + } else break; } hit = IS_SHIP(board[COMPUTER][curx][cury]); @@ -836,16 +845,14 @@ static int plyturn(void) attron(COLOR_PAIR(COLOR_GREEN)); } #endif /* A_COLOR */ - (void) addch((chtype)hits[PLAYER][curx][cury]); + (void) addch((chtype) hits[PLAYER][curx][cury]); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ prompt(1, "You %s.", hit ? "scored a hit" : "missed"); - if(hit && (ss = hitship(curx, cury))) - { - switch(rnd(5)) - { + if (hit && (ss = hitship(curx, cury))) { + switch (rnd(5)) { case 0: m = " You sank my %s!"; break; @@ -862,44 +869,43 @@ static int plyturn(void) m = " You'll pick up survivors from my %s, I hope...!"; break; } - (void)printw(m, ss->name); - (void)beep(); - return(awinna() == -1); + (void) printw(m, ss->name); + (void) beep(); + return (awinna() == -1); } return (hit); } -static int sgetc(const char *s) +static int +sgetc(const char *s) { const char *s1; int ch; - (void)refresh(); - for(;;) - { + (void) refresh(); + for (;;) { ch = getch(); if (islower(ch)) ch = toupper(ch); if (ch == CTRLC) uninitgame(0); - for (s1=s; *s1 && ch != *s1; ++s1) + for (s1 = s; *s1 && ch != *s1; ++s1) continue; - if (*s1) - { - (void) addch((chtype)ch); - (void)refresh(); - return(ch); - } + if (*s1) { + (void) addch((chtype) ch); + (void) refresh(); + return (ch); } + } } - -static void randomfire(int *px, int *py) +static void +randomfire(int *px, int *py) /* random-fire routine -- implements simple diagonal-striping strategy */ { static int turncount = 0; static int srchstep = BEGINSTEP; - static int huntoffs; /* Offset on search strategy */ + static int huntoffs; /* Offset on search strategy */ int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs; int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref; int x, y, i; @@ -911,28 +917,23 @@ static void randomfire(int *px, int *py) nposs = npref = 0; for (x = 0; x < BWIDTH; x++) for (y = 0; y < BDEPTH; y++) - if (!hits[COMPUTER][x][y]) - { + if (!hits[COMPUTER][x][y]) { xpossible[nposs] = x; ypossible[nposs] = y; nposs++; - if (((x+huntoffs) % srchstep) != (y % srchstep)) - { + if (((x + huntoffs) % srchstep) != (y % srchstep)) { xpreferred[npref] = x; ypreferred[npref] = y; npref++; } } - if (npref) - { + if (npref) { i = rnd(npref); *px = xpreferred[i]; *py = ypreferred[i]; - } - else if (nposs) - { + } else if (nposs) { i = rnd(nposs); *px = xpossible[i]; @@ -940,12 +941,10 @@ static void randomfire(int *px, int *py) if (srchstep > 1) --srchstep; - } - else - { + } else { error("No moves possible?? Help!"); exit(EXIT_FAILURE); - /*NOTREACHED*/ + /*NOTREACHED */ } } @@ -953,7 +952,8 @@ static void randomfire(int *px, int *py) #define S_HIT 1 #define S_SUNK -1 -static int cpufire(int x, int y) +static int +cpufire(int x, int y) /* fire away at given location */ { bool hit, sunk; @@ -961,10 +961,11 @@ static int cpufire(int x, int y) hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS; (void) mvprintw(PROMPTLINE, 0, - "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss"); + "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : + "miss"); if ((sunk = (hit && (ss = hitship(x, y)))) != 0) (void) printw(" I've sunk your %s", ss->name); - (void)clrtoeol(); + (void) clrtoeol(); pgoto(y, x); #ifdef A_COLOR @@ -975,7 +976,7 @@ static int cpufire(int x, int y) attron(COLOR_PAIR(COLOR_GREEN)); } #endif /* A_COLOR */ - (void)addch((chtype)(hit ? SHOWHIT : SHOWSPLASH)); + (void) addch((chtype) (hit ? SHOWHIT : SHOWSPLASH)); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ @@ -988,7 +989,8 @@ static int cpufire(int x, int y) * unstructuredness below. The five labels are states which need to be held * between computer turns. */ -static bool cputurn(void) +static bool +cputurn(void) { #define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y]) #define RANDOM_FIRE 0 @@ -1003,29 +1005,28 @@ static bool cputurn(void) int navail, x, y, d, n; int hit = S_MISS; - switch(next) - { - case RANDOM_FIRE: /* last shot was random and missed */ - refire: + switch (next) { + case RANDOM_FIRE: /* last shot was random and missed */ + refire: randomfire(&x, &y); if (!(hit = cpufire(x, y))) next = RANDOM_FIRE; - else - { - ts.x = x; ts.y = y; + else { + ts.x = x; + ts.y = y; ts.hits = 1; next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT; } break; - case RANDOM_HIT: /* last shot was random and hit */ - used[E/2] = used[S/2] = used[W/2] = used[N/2] = FALSE; + case RANDOM_HIT: /* last shot was random and hit */ + used[E / 2] = used[S / 2] = used[W / 2] = used[N / 2] = FALSE; /* FALLTHROUGH */ - case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */ - for (d = navail = 0; d < 4; d++) - { - x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2]; + case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */ + for (d = navail = 0; d < 4; d++) { + x = ts.x + xincr[d * 2]; + y = ts.y + yincr[d * 2]; if (!used[d] && POSSIBLE(x, y)) navail++; else @@ -1033,8 +1034,7 @@ static bool cputurn(void) } if (navail == 0) /* no valid places for shots adjacent... */ goto refire; /* ...so we must random-fire */ - else - { + else { for (d = 0, n = rnd(navail) + 1; n; n--) while (used[d]) d++; @@ -1042,68 +1042,70 @@ static bool cputurn(void) assert(d <= 4); used[d] = FALSE; - x = ts.x + xincr[d*2]; - y = ts.y + yincr[d*2]; + x = ts.x + xincr[d * 2]; + y = ts.y + yincr[d * 2]; assert(POSSIBLE(x, y)); if (!(hit = cpufire(x, y))) next = HUNT_DIRECT; - else - { - ts.x = x; ts.y = y; ts.dir = d*2; ts.hits++; + else { + ts.x = x; + ts.y = y; + ts.dir = d * 2; + ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS; } } break; - case FIRST_PASS: /* we have a start and a direction now */ + case FIRST_PASS: /* we have a start and a direction now */ x = ts.x + xincr[ts.dir]; y = ts.y + yincr[ts.dir]; - if (POSSIBLE(x, y) && (hit = cpufire(x, y))) - { - ts.x = x; ts.y = y; ts.hits++; + if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { + ts.x = x; + ts.y = y; + ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS; - } - else + } else next = REVERSE_JUMP; break; - case REVERSE_JUMP: /* nail down the ship's other end */ + case REVERSE_JUMP: /* nail down the ship's other end */ d = ts.dir + 4; x = ts.x + ts.hits * xincr[d]; y = ts.y + ts.hits * yincr[d]; - if (POSSIBLE(x, y) && (hit = cpufire(x, y))) - { - ts.x = x; ts.y = y; ts.dir = d; ts.hits++; + if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { + ts.x = x; + ts.y = y; + ts.dir = d; + ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS; - } - else + } else next = RANDOM_FIRE; break; - case SECOND_PASS: /* kill squares not caught on first pass */ + case SECOND_PASS: /* kill squares not caught on first pass */ x = ts.x + xincr[ts.dir]; y = ts.y + yincr[ts.dir]; - if (POSSIBLE(x, y) && (hit = cpufire(x, y))) - { - ts.x = x; ts.y = y; ts.hits++; - next = (hit == S_SUNK) ? RANDOM_FIRE: SECOND_PASS; + if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { + ts.x = x; + ts.y = y; + ts.hits++; + next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS; break; - } - else + } else next = RANDOM_FIRE; break; } /* check for continuation and/or winner */ - if (salvo) - { - (void)refresh(); - (void)sleep(1); + if (salvo) { + (void) refresh(); + (void) sleep(1); } if (awinna() != -1) - return(FALSE); + return (FALSE); #ifdef DEBUG (void) mvprintw(PROMPTLINE + 2, 0, @@ -1113,46 +1115,43 @@ static bool cputurn(void) return ((hit) ? TRUE : FALSE); } -static -int playagain(void) +static int +playagain(void) { int j; ship_t *ss; for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++) - for(j = 0; j < ss->length; j++) - { + for (j = 0; j < ss->length; j++) { cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]); - (void)addch((chtype)ss->symbol); + (void) addch((chtype) ss->symbol); } - if(awinna()) + if (awinna()) ++cpuwon; else ++plywon; j = 18 + strlen(name); - if(plywon >= 10) + if (plywon >= 10) ++j; - if(cpuwon >= 10) + if (cpuwon >= 10) ++j; - (void) mvprintw(1,(COLWIDTH-j)/2, - "%s: %d Computer: %d",name,plywon,cpuwon); + (void) mvprintw(1, (COLWIDTH - j) / 2, + "%s: %d Computer: %d", name, plywon, cpuwon); - prompt(2, (awinna()) ? "Want to be humiliated again, %s [yn]? " - : "Going to give me a chance for revenge, %s [yn]? ",name); - return(sgetc("YN") == 'Y'); + prompt(2, (awinna())? "Want to be humiliated again, %s [yn]? " + : "Going to give me a chance for revenge, %s [yn]? ", name); + return (sgetc("YN") == 'Y'); } -static void do_options(int c, char *op[]) +static void +do_options(int c, char *op[]) { register int i; - if (c > 1) - { - for (i=1; i<c; i++) - { - switch(op[i][0]) - { + if (c > 1) { + for (i = 1; i < c; i++) { + switch (op[i][0]) { default: case '?': (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n"); @@ -1163,23 +1162,20 @@ static void do_options(int c, char *op[]) exit(EXIT_FAILURE); break; case '-': - switch(op[i][1]) - { + switch (op[i][1]) { case 'b': blitz = 1; - if (salvo == 1) - { + if (salvo == 1) { (void) fprintf(stderr, - "Bad Arg: -b and -s are mutually exclusive\n"); + "Bad Arg: -b and -s are mutually exclusive\n"); exit(EXIT_FAILURE); } break; case 's': salvo = 1; - if (blitz == 1) - { + if (blitz == 1) { (void) fprintf(stderr, - "Bad Arg: -s and -b are mutually exclusive\n"); + "Bad Arg: -s and -b are mutually exclusive\n"); exit(EXIT_FAILURE); } break; @@ -1188,7 +1184,8 @@ static void do_options(int c, char *op[]) break; default: (void) fprintf(stderr, - "Bad arg: type \"%s ?\" for usage message\n", op[0]); + "Bad arg: type \"%s ?\" for usage message\n", + op[0]); exit(EXIT_FAILURE); } } @@ -1196,73 +1193,64 @@ static void do_options(int c, char *op[]) } } -static int scount(int who) +static int +scount(int who) { register int i, shots; register ship_t *sp; if (who) - sp = cpuship; /* count cpu shots */ + sp = cpuship; /* count cpu shots */ else - sp = plyship; /* count player shots */ + sp = plyship; /* count player shots */ - for (i=0, shots = 0; i < SHIPTYPES; i++, sp++) - { + for (i = 0, shots = 0; i < SHIPTYPES; i++, sp++) { if (sp->hits >= sp->length) continue; /* dead ship */ else shots++; } - return(shots); + return (shots); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { do_options(argc, argv); intro(); do { initgame(); - while(awinna() == -1) - { - if (!blitz) - { - if (!salvo) - { - if(turn) + while (awinna() == -1) { + if (!blitz) { + if (!salvo) { + if (turn) (void) cputurn(); else (void) plyturn(); - } - else - { + } else { register int i; i = scount(turn); - while (i--) - { - if (turn) - { + while (i--) { + if (turn) { if (cputurn() && awinna() != -1) i = 0; - } - else - { + } else { if (plyturn() && awinna() != -1) i = 0; } } - } - } - else - while(turn ? cputurn() : plyturn()) + } + } else + while (turn ? cputurn() : plyturn()) continue; turn = OTHER; } } while (playagain()); uninitgame(0); - /*NOTREACHED*/ + /*NOTREACHED */ } /* bs.c ends here */ diff --git a/contrib/ncurses/test/cardfile.c b/contrib/ncurses/test/cardfile.c index 75d2077..a705d9d 100644 --- a/contrib/ncurses/test/cardfile.c +++ b/contrib/ncurses/test/cardfile.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey <dickey@clark.net> 1999 * - * $Id: cardfile.c,v 1.5 2000/09/09 19:08:32 tom Exp $ + * $Id: cardfile.c,v 1.6 2000/11/04 23:14:28 tom Exp $ * * File format: text beginning in column 1 is a title; other text forms the content. */ @@ -75,7 +75,7 @@ strdup(char *s) static const char * skip(const char *buffer) { - while (isspace(*buffer)) + while (isspace(CharOf(*buffer))) buffer++; return buffer; } @@ -84,7 +84,7 @@ static void trim(char *buffer) { unsigned n = strlen(buffer); - while (n-- && isspace(buffer[n])) + while (n-- && isspace(CharOf(buffer[n]))) buffer[n] = 0; } @@ -166,7 +166,7 @@ read_data(char *fname) if ((fp = fopen(fname, "r")) != 0) { while (fgets(buffer, sizeof(buffer), fp)) { trim(buffer); - if (isspace(*buffer)) { + if (isspace(CharOf(*buffer))) { if (card == 0) card = add_title(""); add_content(card, buffer); diff --git a/contrib/ncurses/test/configure b/contrib/ncurses/test/configure index e27f5ef..de1cf77 100755 --- a/contrib/ncurses/test/configure +++ b/contrib/ncurses/test/configure @@ -1,7 +1,7 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13.19990117 +# Generated automatically using autoconf version 2.13.20000819 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. # # This configure script is free software; the Free Software Foundation @@ -335,7 +335,7 @@ EOF verbose=yes ;; -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13.19990117" + echo "configure generated by autoconf version 2.13.20000819" exit 0 ;; -with-* | --with-*) @@ -760,6 +760,7 @@ LD="ld" LDFLAGS_SHARED="" LD_MODEL="" LD_SHARED_OPTS="" +LIBTOOL="" LIB_NAME=curses LIB_PREFIX="-l" LINK_TESTS="" @@ -787,12 +788,12 @@ fi if test "${with_ncurses+set}" = set; then withval="$with_ncurses" echo $ac_n "checking for initscr""... $ac_c" 1>&6 -echo "configure:791: checking for initscr" >&5 +echo "configure:792: checking for initscr" >&5 if eval "test \"`echo '$''{'ac_cv_func_initscr'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 796 "configure" +#line 797 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char initscr(); below. */ @@ -815,7 +816,7 @@ initscr(); ; return 0; } EOF -if { (eval echo configure:819: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:820: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_initscr=yes" else @@ -834,7 +835,7 @@ else echo "$ac_t""no" 1>&6 echo $ac_n "checking for Gpm_Open in -lgpm""... $ac_c" 1>&6 -echo "configure:838: checking for Gpm_Open in -lgpm" >&5 +echo "configure:839: checking for Gpm_Open in -lgpm" >&5 ac_lib_var=`echo gpm'_'Gpm_Open | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -842,7 +843,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lgpm $LIBS" cat > conftest.$ac_ext <<EOF -#line 846 "configure" +#line 847 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -853,7 +854,7 @@ int main() { Gpm_Open() ; return 0; } EOF -if { (eval echo configure:857: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:858: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -908,12 +909,12 @@ fi echo $ac_n "checking for initscr""... $ac_c" 1>&6 -echo "configure:912: checking for initscr" >&5 +echo "configure:913: checking for initscr" >&5 if eval "test \"`echo '$''{'ac_cv_func_initscr'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 917 "configure" +#line 918 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char initscr(); below. */ @@ -936,7 +937,7 @@ initscr(); ; return 0; } EOF -if { (eval echo configure:940: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:941: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_initscr=yes" else @@ -955,7 +956,7 @@ else echo "$ac_t""no" 1>&6 echo $ac_n "checking for initscr in -l$LIB_NAME""... $ac_c" 1>&6 -echo "configure:959: checking for initscr in -l$LIB_NAME" >&5 +echo "configure:960: checking for initscr in -l$LIB_NAME" >&5 ac_lib_var=`echo $LIB_NAME'_'initscr | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -963,7 +964,7 @@ else ac_save_LIBS="$LIBS" LIBS="-l$LIB_NAME $LIBS" cat > conftest.$ac_ext <<EOF -#line 967 "configure" +#line 968 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -974,7 +975,7 @@ int main() { initscr() ; return 0; } EOF -if { (eval echo configure:978: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:979: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1004,7 +1005,7 @@ fi fi echo $ac_n "checking for form_driver in -lform""... $ac_c" 1>&6 -echo "configure:1008: checking for form_driver in -lform" >&5 +echo "configure:1009: checking for form_driver in -lform" >&5 ac_lib_var=`echo form'_'form_driver | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1012,7 +1013,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lform $LIBS" cat > conftest.$ac_ext <<EOF -#line 1016 "configure" +#line 1017 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1023,7 +1024,7 @@ int main() { form_driver() ; return 0; } EOF -if { (eval echo configure:1027: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1028: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1051,7 +1052,7 @@ else fi echo $ac_n "checking for menu_driver in -lmenu""... $ac_c" 1>&6 -echo "configure:1055: checking for menu_driver in -lmenu" >&5 +echo "configure:1056: checking for menu_driver in -lmenu" >&5 ac_lib_var=`echo menu'_'menu_driver | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1059,7 +1060,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lmenu $LIBS" cat > conftest.$ac_ext <<EOF -#line 1063 "configure" +#line 1064 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1070,7 +1071,7 @@ int main() { menu_driver() ; return 0; } EOF -if { (eval echo configure:1074: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1075: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1098,7 +1099,7 @@ else fi echo $ac_n "checking for new_panel in -lpanel""... $ac_c" 1>&6 -echo "configure:1102: checking for new_panel in -lpanel" >&5 +echo "configure:1103: checking for new_panel in -lpanel" >&5 ac_lib_var=`echo panel'_'new_panel | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1106,7 +1107,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lpanel $LIBS" cat > conftest.$ac_ext <<EOF -#line 1110 "configure" +#line 1111 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1117,7 +1118,7 @@ int main() { new_panel() ; return 0; } EOF -if { (eval echo configure:1121: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1122: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1146,12 +1147,12 @@ fi echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6 -echo "configure:1150: checking return type of signal handlers" >&5 +echo "configure:1151: checking return type of signal handlers" >&5 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1155 "configure" +#line 1156 "configure" #include "confdefs.h" #include <sys/types.h> #include <signal.h> @@ -1168,7 +1169,7 @@ int main() { int i; ; return 0; } EOF -if { (eval echo configure:1172: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1173: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_type_signal=void else @@ -1188,7 +1189,7 @@ EOF echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1192: checking how to run the C preprocessor" >&5 +echo "configure:1193: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1203,13 +1204,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1207 "configure" +#line 1208 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1213: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1214: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1220,13 +1221,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1224 "configure" +#line 1225 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1230: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1231: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1237,13 +1238,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext <<EOF -#line 1241 "configure" +#line 1242 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1247: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1248: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1268,12 +1269,12 @@ fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1272: checking for ANSI C header files" >&5 +echo "configure:1273: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1277 "configure" +#line 1278 "configure" #include "confdefs.h" #include <stdlib.h> #include <stdarg.h> @@ -1281,7 +1282,7 @@ else #include <float.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1285: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1286: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1298,7 +1299,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1302 "configure" +#line 1303 "configure" #include "confdefs.h" #include <string.h> EOF @@ -1316,7 +1317,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1320 "configure" +#line 1321 "configure" #include "confdefs.h" #include <stdlib.h> EOF @@ -1337,7 +1338,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext <<EOF -#line 1341 "configure" +#line 1342 "configure" #include "confdefs.h" #include <ctype.h> #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1348,7 +1349,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1352: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1353: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -1372,12 +1373,12 @@ EOF fi echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:1376: checking whether time.h and sys/time.h may both be included" >&5 +echo "configure:1377: checking whether time.h and sys/time.h may both be included" >&5 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1381 "configure" +#line 1382 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/time.h> @@ -1386,7 +1387,7 @@ int main() { struct tm *tp; ; return 0; } EOF -if { (eval echo configure:1390: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1391: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time=yes else @@ -1421,17 +1422,17 @@ unistd.h \ do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1425: checking for $ac_hdr" >&5 +echo "configure:1426: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1430 "configure" +#line 1431 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1435: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1436: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1469,12 +1470,12 @@ wresize \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1473: checking for $ac_func" >&5 +echo "configure:1474: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1478 "configure" +#line 1479 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1497,7 +1498,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1501: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1502: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1523,7 +1524,7 @@ done echo $ac_n "checking for function curses_version""... $ac_c" 1>&6 -echo "configure:1527: checking for function curses_version" >&5 +echo "configure:1528: checking for function curses_version" >&5 if eval "test \"`echo '$''{'cf_cv_func_curses_version'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1532,7 +1533,7 @@ if test "$cross_compiling" = yes; then cf_cv_func_curses_version=unknown else cat > conftest.$ac_ext <<EOF -#line 1536 "configure" +#line 1537 "configure" #include "confdefs.h" #include <curses.h> @@ -1544,7 +1545,7 @@ int main() } EOF -if { (eval echo configure:1548: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1549: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then cf_cv_func_curses_version=yes @@ -1568,13 +1569,13 @@ EOF echo $ac_n "checking if sys/time.h conflicts with sys/select.h""... $ac_c" 1>&6 -echo "configure:1572: checking if sys/time.h conflicts with sys/select.h" >&5 +echo "configure:1573: checking if sys/time.h conflicts with sys/select.h" >&5 if eval "test \"`echo '$''{'cf_cv_sys_time_select'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1578 "configure" +#line 1579 "configure" #include "confdefs.h" #if HAVE_SYS_TIME_H @@ -1588,7 +1589,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:1592: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1593: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cf_cv_sys_time_select=yes else @@ -1697,7 +1698,7 @@ do echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13.19990117" + echo "$CONFIG_STATUS generated by autoconf version 2.13.20000819" exit 0 ;; -help | --help | --hel | --he | --h) echo "\$ac_cs_usage"; exit 0 ;; @@ -1751,6 +1752,7 @@ s%@LD@%$LD%g s%@LDFLAGS_SHARED@%$LDFLAGS_SHARED%g s%@LD_MODEL@%$LD_MODEL%g s%@LD_SHARED_OPTS@%$LD_SHARED_OPTS%g +s%@LIBTOOL@%$LIBTOOL%g s%@LIB_NAME@%$LIB_NAME%g s%@LIB_PREFIX@%$LIB_PREFIX%g s%@LINK_TESTS@%$LINK_TESTS%g diff --git a/contrib/ncurses/test/configure.in b/contrib/ncurses/test/configure.in index 3399932..d61d477 100644 --- a/contrib/ncurses/test/configure.in +++ b/contrib/ncurses/test/configure.in @@ -28,7 +28,7 @@ dnl*************************************************************************** dnl dnl Author: Thomas E. Dickey 1996,1997,1998,2000 dnl -dnl $Id: configure.in,v 1.30 2000/08/12 22:43:08 tom Exp $ +dnl $Id: configure.in,v 1.31 2000/10/15 18:46:17 tom Exp $ dnl This is a simple configuration-script for the ncurses test programs that dnl allows the test-directory to be separately configured against a reference dnl system (i.e., sysvr4 curses) @@ -36,8 +36,9 @@ dnl dnl If you're configuring ncurses, you shouldn't need to use this script. dnl It's only for testing purposes. dnl -dnl dickey@herndon4.his.com (Thomas Dickey) -AC_PREREQ(2.12) +dnl See http://dickey.his.com/autoconf/ for additional information. +dnl --------------------------------------------------------------------------- +AC_PREREQ(2.13.20000819) AC_INIT(ncurses.c) AC_CONFIG_HEADER(ncurses_cfg.h:ncurses_tst.hin) @@ -56,6 +57,7 @@ LD="ld" AC_SUBST(LD) LDFLAGS_SHARED="" AC_SUBST(LDFLAGS_SHARED) LD_MODEL="" AC_SUBST(LD_MODEL) LD_SHARED_OPTS="" AC_SUBST(LD_SHARED_OPTS) +LIBTOOL="" AC_SUBST(LIBTOOL) LIB_NAME=curses AC_SUBST(LIB_NAME) LIB_PREFIX="-l" AC_SUBST(LIB_PREFIX) LINK_TESTS="" AC_SUBST(LINK_TESTS) diff --git a/contrib/ncurses/test/filter.c b/contrib/ncurses/test/filter.c index 272f372..6ccaffd 100644 --- a/contrib/ncurses/test/filter.c +++ b/contrib/ncurses/test/filter.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey <dickey@clark.net> 1998 * - * $Id: filter.c,v 1.4 2000/09/02 18:50:38 tom Exp $ + * $Id: filter.c,v 1.5 2001/02/24 22:11:58 tom Exp $ */ #include <test.priv.h> @@ -69,12 +69,11 @@ new_command(char *buffer, int length, attr_t underline) int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { - SCREEN *sp; char buffer[80]; attr_t underline; filter(); - sp = newterm((char *) 0, stdout, stdin); + (void) newterm((char *) 0, stdout, stdin); cbreak(); keypad(stdscr, TRUE); diff --git a/contrib/ncurses/test/gdc.c b/contrib/ncurses/test/gdc.c index df9a0c3..c215874 100644 --- a/contrib/ncurses/test/gdc.c +++ b/contrib/ncurses/test/gdc.c @@ -6,7 +6,7 @@ * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling * - * $Id: gdc.c,v 1.15 2000/09/02 18:40:39 tom Exp $ + * $Id: gdc.c,v 1.16 2001/02/24 23:27:22 tom Exp $ */ #include <test.priv.h> @@ -97,7 +97,7 @@ set(int t, int n) m = 7 << n; for (i = 0; i < 5; i++) { - next[i] |= ((disp[t] >> (4 - i) * 3) & 07) << n; + next[i] |= ((disp[t] >> ((4 - i) * 3)) & 07) << n; mask |= (next[i] ^ older[i]) & m; } if (mask & m) @@ -306,6 +306,7 @@ main(int argc, char *argv[]) fprintf(stderr, "gdc terminated by signal %d\n", sigtermed); return EXIT_FAILURE; } + /* FALLTHRU */ default: continue; } diff --git a/contrib/ncurses/test/hashtest.c b/contrib/ncurses/test/hashtest.c index 52e5c21..682368d 100644 --- a/contrib/ncurses/test/hashtest.c +++ b/contrib/ncurses/test/hashtest.c @@ -3,14 +3,14 @@ * * Generate timing statistics for vertical-motion optimization. * - * $Id: hashtest.c,v 1.15 2000/09/02 19:23:33 tom Exp $ + * $Id: hashtest.c,v 1.17 2001/03/10 19:47:22 tom Exp $ */ #ifdef TRACE #define Trace(p) _tracef p #define USE_TRACE 1 #else -#define Trace(p) /* nothing */ +#define Trace(p) /* nothing */ #define USE_TRACE 0 #endif @@ -30,191 +30,199 @@ static bool extend_corner = FALSE; static int foot_lines = 0; static int head_lines = 0; -static void cleanup(void) +static void +cleanup(void) { - move(LINES-1,0); - clrtoeol(); - refresh(); - endwin(); + move(LINES - 1, 0); + clrtoeol(); + refresh(); + endwin(); } -static RETSIGTYPE finish(int sig GCC_UNUSED) +static RETSIGTYPE +finish(int sig GCC_UNUSED) { - cleanup(); - exit(EXIT_FAILURE); + cleanup(); + exit(EXIT_FAILURE); } -static void genlines(int base) +static void +genlines(int base) { - int i, j; + int i, j; #if USE_TRACE - if (base == 'a') - Trace(("Resetting screen")); - else - Trace(("Painting `%c' screen", base)); + if (base == 'a') + Trace(("Resetting screen")); + else + Trace(("Painting `%c' screen", base)); #endif - /* Do this so writes to lower-right corner don't cause a spurious - * scrolling operation. This _shouldn't_ break the scrolling - * optimization, since that's computed in the refresh() call. - */ - scrollok(stdscr, FALSE); - - move(0,0); - for (i = 0; i < head_lines; i++) - for (j = 0; j < COLS; j++) - addch((j % 8 == 0) ? ('A' + j/8) : '-'); - - move(head_lines, 0); - for (i = head_lines; i < LINES - foot_lines; i++) { - int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR; - int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1; - for (j = 0; j < hi; j++) - addch(c); - } - - for (i = LINES - foot_lines; i < LINES; i++) { - move(i, 0); - for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++) - addch((j % 8 == 0) ? ('A' + j/8) : '-'); - } - - scrollok(stdscr, TRUE); - if (single_step) { - move(LINES-1, 0); - getch(); - } else - refresh(); + /* Do this so writes to lower-right corner don't cause a spurious + * scrolling operation. This _shouldn't_ break the scrolling + * optimization, since that's computed in the refresh() call. + */ + scrollok(stdscr, FALSE); + + move(0, 0); + for (i = 0; i < head_lines; i++) + for (j = 0; j < COLS; j++) + addch((j % 8 == 0) ? ('A' + j / 8) : '-'); + + move(head_lines, 0); + for (i = head_lines; i < LINES - foot_lines; i++) { + int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR; + int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1; + for (j = 0; j < hi; j++) + addch(c); + } + + for (i = LINES - foot_lines; i < LINES; i++) { + move(i, 0); + for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++) + addch((j % 8 == 0) ? ('A' + j / 8) : '-'); + } + + scrollok(stdscr, TRUE); + if (single_step) { + move(LINES - 1, 0); + getch(); + } else + refresh(); } -static void one_cycle(int ch) +static void +one_cycle(int ch) { - if (continuous) { - genlines(ch); - } else if (ch != 'a') { - genlines('a'); - genlines(ch); - } + if (continuous) { + genlines(ch); + } else if (ch != 'a') { + genlines('a'); + genlines(ch); + } } -static void run_test(bool optimized) +static void +run_test(bool optimized GCC_UNUSED) { - char ch; - int lo = continuous ? LO_CHAR : 'a' - LINES; - int hi = continuous ? HI_CHAR : 'a' + LINES; + char ch; + int lo = continuous ? LO_CHAR : 'a' - LINES; + int hi = continuous ? HI_CHAR : 'a' + LINES; - if (lo < LO_CHAR) - lo = LO_CHAR; - if (hi > HI_CHAR) - hi = HI_CHAR; + if (lo < LO_CHAR) + lo = LO_CHAR; + if (hi > HI_CHAR) + hi = HI_CHAR; #if defined(TRACE) || defined(NCURSES_TEST) - if (optimized) { - Trace(("With hash mapping")); - _nc_optimize_enable |= OPTIMIZE_HASHMAP; - } else { - Trace(("Without hash mapping")); - _nc_optimize_enable &= ~OPTIMIZE_HASHMAP; - } + if (optimized) { + Trace(("With hash mapping")); + _nc_optimize_enable |= OPTIMIZE_HASHMAP; + } else { + Trace(("Without hash mapping")); + _nc_optimize_enable &= ~OPTIMIZE_HASHMAP; + } #endif - if (reverse_loops) - for (ch = hi; ch >= lo; ch--) - one_cycle(ch); - else - for (ch = lo; ch <= hi; ch++) - one_cycle(ch); + if (reverse_loops) + for (ch = hi; ch >= lo; ch--) + one_cycle(ch); + else + for (ch = lo; ch <= hi; ch++) + one_cycle(ch); } -static void usage(void) +static void +usage(void) { - static const char *const tbl[] = { - "Usage: hashtest [options]" - ,"" - ,"Options:" - ," -c continuous (don't reset between refresh's)" - ," -f num leave 'num' lines constant for footer" - ," -h num leave 'num' lines constant for header" - ," -l num repeat test 'num' times" - ," -n test the normal optimizer" - ," -o test the hashed optimizer" - ," -r reverse the loops" - ," -s single-step" - ," -x assume lower-right corner extension" - }; - size_t n; - - for (n = 0; n < sizeof(tbl)/sizeof(tbl[0]); n++) - fprintf(stderr, "%s\n", tbl[n]); - exit(EXIT_FAILURE); + static const char *const tbl[] = + { + "Usage: hashtest [options]" + ,"" + ,"Options:" + ," -c continuous (don't reset between refresh's)" + ," -f num leave 'num' lines constant for footer" + ," -h num leave 'num' lines constant for header" + ," -l num repeat test 'num' times" + ," -n test the normal optimizer" + ," -o test the hashed optimizer" + ," -r reverse the loops" + ," -s single-step" + ," -x assume lower-right corner extension" + }; + size_t n; + + for (n = 0; n < SIZEOF(tbl); n++) + fprintf(stderr, "%s\n", tbl[n]); + exit(EXIT_FAILURE); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int c; - int test_loops = 1; - int test_normal = FALSE; - int test_optimize = FALSE; - - while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) { - switch (c) { - case 'c': - continuous = TRUE; - break; - case 'f': - foot_lines = atoi(optarg); - break; - case 'h': - head_lines = atoi(optarg); - break; - case 'l': - test_loops = atoi(optarg); - break; - case 'n': - test_normal = TRUE; - break; - case 'o': - test_optimize = TRUE; - break; - case 'r': - reverse_loops = TRUE; - break; - case 's': - single_step = TRUE; - break; - case 'x': - extend_corner = TRUE; - break; - default: - usage(); - } - } - if (!test_normal && !test_optimize) { - test_normal = TRUE; - test_optimize = TRUE; + int c; + int test_loops = 1; + int test_normal = FALSE; + int test_optimize = FALSE; + + while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) { + switch (c) { + case 'c': + continuous = TRUE; + break; + case 'f': + foot_lines = atoi(optarg); + break; + case 'h': + head_lines = atoi(optarg); + break; + case 'l': + test_loops = atoi(optarg); + break; + case 'n': + test_normal = TRUE; + break; + case 'o': + test_optimize = TRUE; + break; + case 'r': + reverse_loops = TRUE; + break; + case 's': + single_step = TRUE; + break; + case 'x': + extend_corner = TRUE; + break; + default: + usage(); } + } + if (!test_normal && !test_optimize) { + test_normal = TRUE; + test_optimize = TRUE; + } #if USE_TRACE - trace(TRACE_TIMES); + trace(TRACE_TIMES); #endif - (void) signal(SIGINT, finish); /* arrange interrupts to terminate */ + (void) signal(SIGINT, finish); /* arrange interrupts to terminate */ - (void) initscr(); /* initialize the curses library */ - keypad(stdscr, TRUE); /* enable keyboard mapping */ - (void) nonl(); /* tell curses not to do NL->CR/NL on output */ - (void) cbreak(); /* take input chars one at a time, no wait for \n */ - (void) noecho(); /* don't echo input */ - scrollok(stdscr, TRUE); + (void) initscr(); /* initialize the curses library */ + keypad(stdscr, TRUE); /* enable keyboard mapping */ + (void) nonl(); /* tell curses not to do NL->CR/NL on output */ + (void) cbreak(); /* take input chars one at a time, no wait for \n */ + (void) noecho(); /* don't echo input */ + scrollok(stdscr, TRUE); - while (test_loops-- > 0) { - if (test_normal) - run_test(FALSE); - if (test_optimize) - run_test(TRUE); - } + while (test_loops-- > 0) { + if (test_normal) + run_test(FALSE); + if (test_optimize) + run_test(TRUE); + } - cleanup(); /* we're done */ - return(EXIT_SUCCESS); + cleanup(); /* we're done */ + return (EXIT_SUCCESS); } /* hashtest.c ends here */ diff --git a/contrib/ncurses/test/knight.c b/contrib/ncurses/test/knight.c index 0729d49..b922371 100644 --- a/contrib/ncurses/test/knight.c +++ b/contrib/ncurses/test/knight.c @@ -6,7 +6,7 @@ * Eric S. Raymond <esr@snark.thyrsus.com> July 22 1995. Mouse support * added September 20th 1995. * - * $Id: knight.c,v 1.17 2000/09/02 18:48:19 tom Exp $ + * $Id: knight.c,v 1.20 2000/10/29 00:51:51 tom Exp $ */ #include <test.priv.h> @@ -35,8 +35,8 @@ #define PLUS_COLOR 2 #define MINUS_COLOR 3 -#define CX(x) (2 + 4 * (x)) -#define CY(y) (1 + 2 * (y)) +#define CX(x) (2 + 4 * (x)) +#define CY(y) (1 + 2 * (y)) #define cellmove(y, x) wmove(boardwin, CY(y), CX(x)) #define CXINV(x) (((x) - 1) / 4) #define CYINV(y) (((y) - 2) / 2) @@ -45,41 +45,35 @@ typedef struct { short x, y; } cell; -static short board[BDEPTH][BWIDTH]; /* the squares */ -static int rw, col; /* current row and column */ -static int lastrow, lastcol; /* last location visited */ -static cell history[BDEPTH * BWIDTH]; /* choice history */ -static int movecount; /* count of moves so far */ static WINDOW *boardwin; /* the board window */ static WINDOW *helpwin; /* the help window */ static WINDOW *msgwin; /* the message window */ -static chtype trail = '#'; /* trail character */ -static chtype plus = '+'; /* cursor hot-spot character */ +static cell history[BDEPTH * BWIDTH + 1]; /* choice history */ static chtype minus = '-'; /* possible-move character */ static chtype oldch; - -static void init(void); -static void play(void); -static void dosquares(void); -static void drawmove(char, int, int, int, int); -static bool evalmove(int, int); -static bool chkmoves(void); -static bool chksqr(int, int); -static int iabs(int); - -int -main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) -{ - init(); - - play(); - - endwin(); - return EXIT_SUCCESS; -} +static chtype plus = '+'; /* cursor hot-spot character */ +static chtype trail = '#'; /* trail character */ +static int movecount; /* count of moves so far */ +static int trialcount; /* count of trials so far */ +static short board[BDEPTH][BWIDTH]; /* the squares */ +/* *INDENT-OFF* */ +static const struct { + int y; + int x; +} offsets[] = { + { 2, 1 }, + { 1, 2 }, + { -1, 2 }, + { -2, 1 }, + { -2, -1 }, + { -1, -2 }, + { 1, -2 }, + { 2, -1 }, +}; +/* *INDENT-ON* */ static void -init(void) +init_program(void) { srand((unsigned) getpid()); initscr(); @@ -154,25 +148,289 @@ help2(void) (void) waddstr(helpwin, "x,q -- exit y k u 7 8 9\n"); (void) waddstr(helpwin, "r -- redraw screen \\|/ \\|/ \n"); - (void) waddstr(helpwin, "u -- undo move h-+-l 4-+-6\n"); - (void) waddstr(helpwin, " /|\\ /|\\ \n"); + (void) waddstr(helpwin, "bksp -- undo move h-+-l 4-+-6\n"); + (void) waddstr(helpwin, "a -- autojump /|\\ /|\\ \n"); (void) waddstr(helpwin, " b j n 1 2 3\n"); (void) waddstr(helpwin, "\nYou can place your knight on the selected\n"); (void) waddstr(helpwin, "square with spacebar, Enter, or the keypad\n"); - (void) waddstr(helpwin, "center key. You can quit with `x' or `q'.\n"); + (void) waddstr(helpwin, "center key. Use F/B to review the path.\n"); (void) mvwaddstr(helpwin, NOTIFYY - INSTRY, 0, "Press `?' to go to game explanation"); } static void +show_help(bool * keyhelp) +{ + werase(helpwin); + if (*keyhelp) { + help1(); + *keyhelp = FALSE; + } else { + help2(); + *keyhelp = TRUE; + } + wrefresh(helpwin); +} + +static bool +chksqr(int r1, int c1) +{ + if ((r1 < 0) || (r1 > BDEPTH - 1)) + return (FALSE); + if ((c1 < 0) || (c1 > BWIDTH - 1)) + return (FALSE); + return ((!board[r1][c1]) ? TRUE : FALSE); +} + +static bool +chkmoves(int rw, int col) +/* check to see if valid moves are available */ +{ + unsigned n; + + for (n = 0; n < SIZEOF(offsets); n++) + if (chksqr(rw + offsets[n].y, col + offsets[n].x)) + return (TRUE); + return (FALSE); +} + +static void +dosquares(void) +{ + int i, j; + + mvaddstr(0, 20, "KNIGHT'S MOVE -- a logical solitaire"); + + move(BOARDY, BOARDX); + waddch(boardwin, ACS_ULCORNER); + for (j = 0; j < 7; j++) { + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_TTEE); + } + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_URCORNER); + + for (i = 1; i < BDEPTH; i++) { + move(BOARDY + i * 2 - 1, BOARDX); + waddch(boardwin, ACS_VLINE); + for (j = 0; j < BWIDTH; j++) { + waddch(boardwin, ' '); + waddch(boardwin, ' '); + waddch(boardwin, ' '); + waddch(boardwin, ACS_VLINE); + } + move(BOARDY + i * 2, BOARDX); + waddch(boardwin, ACS_LTEE); + for (j = 0; j < BWIDTH - 1; j++) { + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_PLUS); + } + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_RTEE); + } + + move(BOARDY + i * 2 - 1, BOARDX); + waddch(boardwin, ACS_VLINE); + for (j = 0; j < BWIDTH; j++) { + waddch(boardwin, ' '); + waddch(boardwin, ' '); + waddch(boardwin, ' '); + waddch(boardwin, ACS_VLINE); + } + + move(BOARDY + i * 2, BOARDX); + waddch(boardwin, ACS_LLCORNER); + for (j = 0; j < BWIDTH - 1; j++) { + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_BTEE); + } + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_HLINE); + waddch(boardwin, ACS_LRCORNER); +} + +static void +mark_possibles(int prow, int pcol, chtype mark) +{ + unsigned n; + + for (n = 0; n < SIZEOF(offsets); n++) { + if (chksqr(prow + offsets[n].y, pcol + offsets[n].x)) { + cellmove(prow + offsets[n].y, pcol + offsets[n].x); + waddch(boardwin, mark); + } + } +} + +static void +find_next_move(int *y, int *x) +{ + unsigned j, k; + int found = -1; + int first = -1; + int next = 0; + int oldy, oldx; + int newy, newx; + + if (movecount > 1) { + oldy = history[movecount - 1].y; + oldx = history[movecount - 1].x; + for (j = 0; j < SIZEOF(offsets) * 2; j++) { + k = j % SIZEOF(offsets); + newy = oldy + offsets[k].y; + newx = oldx + offsets[k].x; + if (chksqr(newy, newx)) { + if (first < 0) + first = k; + if (newy == *y + && newx == *x) { + found = k; + } else if (found >= 0) { + next = k; + break; + } + } + } + if (found < 0) + next = first; + if (next >= 0) { + *y = oldy + offsets[next].y; + *x = oldx + offsets[next].x; + } + } else { + beep(); + } +} + +static void +unmarkcell(int row, int column) +{ + cellmove(row, column); + waddch(boardwin, '\b'); + waddch(boardwin, ' '); + waddch(boardwin, minus); + waddch(boardwin, ' '); +} + +static void +markcell(chtype tchar, int row, int column) +{ + cellmove(row, column); + waddch(boardwin, '\b'); + waddch(boardwin, tchar); + waddch(boardwin, tchar); + waddch(boardwin, tchar); +} + +static void +drawmove(chtype tchar, int oldy, int oldx, int row, int column) +/* place the stars, update board & currents */ +{ + if (movecount <= 1) { + int i, j; + + for (i = 0; i < BDEPTH; i++) { + for (j = 0; j < BWIDTH; j++) { + if (movecount == 0) { + unmarkcell(i, j); + } else { + cellmove(i, j); + if (winch(boardwin) == minus) + waddch(boardwin, movecount ? ' ' : minus); + } + } + } + } else { + markcell(tchar, oldy, oldx); + mark_possibles(oldy, oldx, ' '); + } + + if (row != -1 && column != -1) { + markcell(trail, row, column); + mark_possibles(row, column, minus); + board[row][column] = TRUE; + } + + wprintw(msgwin, "\nMove %d", movecount); + if (trialcount != movecount) + wprintw(msgwin, " (%d tries)", trialcount); + wclrtoeol(msgwin); +} + +static int +iabs(int num) +{ + if (num < 0) + return (-num); + else + return (num); +} + +static bool +evalmove(int row, int column) +/* evaluate move */ +{ + if (movecount == 1) + return (TRUE); + else if (board[row][column] == TRUE) { + waddstr(msgwin, "\nYou've already been there."); + return (FALSE); + } else { + int rdif = iabs(row - history[movecount - 1].y); + int cdif = iabs(column - history[movecount - 1].x); + + if (!((rdif == 1) && (cdif == 2)) && !((rdif == 2) && (cdif == 1))) { + waddstr(msgwin, "\nThat's not a legal knight's move."); + return (FALSE); + } + } + + return (TRUE); +} + +static int +completed(void) +{ + int i, j, count = 0; + + for (i = 0; i < BDEPTH; i++) + for (j = 0; j < BWIDTH; j++) + if (board[i][j] != 0) + count += 1; + return (count == (BWIDTH * BDEPTH) ? -1 : count); +} + +static void +no_previous_move(void) +{ + waddstr(msgwin, "\nNo previous move."); + beep(); +} + +static void play(void) /* play the game */ { bool keyhelp; /* TRUE if keystroke help is up */ - int c, ny = 0, nx = 0; int i, j, count; + int lastcol = 0; /* last location visited */ + int lastrow = 0; + int ny = 0, nx = 0; + int review = 0; /* review history */ + int rw = 0, col = 0; /* current row and column */ do { /* clear screen and draw board */ @@ -187,17 +445,21 @@ play(void) wnoutrefresh(boardwin); doupdate(); - for (i = 0; i < BDEPTH; i++) + movecount = 0; + for (i = 0; i < BDEPTH; i++) { for (j = 0; j < BWIDTH; j++) { board[i][j] = FALSE; - cellmove(i, j); - waddch(boardwin, minus); + unmarkcell(i, j); } - memset(history, '\0', sizeof(history)); + } + memset(history, 0, sizeof(history)); history[0].y = history[0].x = -1; + history[1].y = history[1].x = -1; lastrow = lastcol = -2; movecount = 1; + trialcount = 1; keyhelp = FALSE; + show_help(&keyhelp); for (;;) { if (rw != lastrow || col != lastcol) { @@ -221,11 +483,7 @@ play(void) wrefresh(msgwin); - c = wgetch(boardwin); - - werase(msgwin); - - switch (c) { + switch (wgetch(boardwin)) { case 'k': case '8': case KEY_UP: @@ -297,48 +555,67 @@ play(void) case KEY_B2: case '\n': case ' ': + review = 0; if (evalmove(rw, col)) { drawmove(trail, - history[movecount - 1].y, history[movecount - - 1].x, + history[movecount - 1].y, + history[movecount - 1].x, rw, col); history[movecount].y = rw; history[movecount].x = col; movecount++; - - if (!chkmoves()) - goto dropout; - } else + trialcount++; + + if (!chkmoves(rw, col)) { + if (completed() < 0) { + waddstr(msgwin, "\nYou won."); + } else { + waddstr(msgwin, + "\nNo further moves are possible."); + } + } + } else { beep(); - break; - - case KEY_REDO: - case '\f': - case 'r': - clearok(curscr, TRUE); - wnoutrefresh(stdscr); - wnoutrefresh(boardwin); - wnoutrefresh(msgwin); - wnoutrefresh(helpwin); - doupdate(); + } break; case KEY_UNDO: case KEY_BACKSPACE: case '\b': - if (movecount == 1) { - ny = lastrow; - nx = lastcol; - waddstr(msgwin, "\nNo previous move."); - beep(); + review = 0; + if (movecount <= 0) { + no_previous_move(); + } else if (movecount <= 1) { + ny = history[movecount].y; + nx = history[movecount].x; + if (nx < 0 || ny < 0) { + ny = lastrow; + nx = lastcol; + } + movecount = 0; + board[ny][nx] = FALSE; + oldch = minus; + drawmove(' ', ny, nx, -1, -1); + movecount = 1; + trialcount = 1; + no_previous_move(); } else { int oldy = history[movecount - 1].y; int oldx = history[movecount - 1].x; + if (!board[rw][col]) { + cellmove(rw, col); + waddch(boardwin, ' '); + } + board[oldy][oldx] = FALSE; --movecount; ny = history[movecount - 1].y; nx = history[movecount - 1].x; + if (nx < 0 || ny < 0) { + ny = oldy; + nx = oldx; + } drawmove(' ', oldy, oldx, ny, nx); /* avoid problems if we just changed the current cell */ @@ -347,20 +624,49 @@ play(void) } break; + case 'a': + nx = col; + ny = rw; + find_next_move(&ny, &nx); + break; + + case 'F': + if (review > 0) { + review--; + ny = history[movecount - review - 1].y; + nx = history[movecount - review - 1].x; + } else { + beep(); + } + break; + + case 'B': + if (review < movecount - 2) { + review++; + ny = history[movecount - review - 1].y; + nx = history[movecount - review - 1].x; + } else { + beep(); + } + break; + + case KEY_REDO: + case '\f': + case 'r': + clearok(curscr, TRUE); + wnoutrefresh(stdscr); + wnoutrefresh(boardwin); + wnoutrefresh(msgwin); + wnoutrefresh(helpwin); + doupdate(); + break; + case 'q': case 'x': goto dropout; case '?': - werase(helpwin); - if (keyhelp) { - help1(); - keyhelp = FALSE; - } else { - help2(); - keyhelp = TRUE; - } - wrefresh(helpwin); + show_help(&keyhelp); break; default: @@ -373,219 +679,24 @@ play(void) } dropout: - count = 0; - for (i = 0; i < BDEPTH; i++) - for (j = 0; j < BWIDTH; j++) - if (board[i][j] != 0) - count += 1; - if (count == (BWIDTH * BDEPTH)) + if ((count = completed()) < 0) wprintw(msgwin, "\nYou won. Care to try again? "); else wprintw(msgwin, "\n%d squares filled. Try again? ", count); + wclrtoeol(msgwin); } while (tolower(wgetch(msgwin)) == 'y'); } -static void -dosquares(void) -{ - int i, j; - - mvaddstr(0, 20, "KNIGHT'S MOVE -- a logical solitaire"); - - move(BOARDY, BOARDX); - waddch(boardwin, ACS_ULCORNER); - for (j = 0; j < 7; j++) { - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_TTEE); - } - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_URCORNER); - - for (i = 1; i < BDEPTH; i++) { - move(BOARDY + i * 2 - 1, BOARDX); - waddch(boardwin, ACS_VLINE); - for (j = 0; j < BWIDTH; j++) { - waddch(boardwin, ' '); - waddch(boardwin, ' '); - waddch(boardwin, ' '); - waddch(boardwin, ACS_VLINE); - } - move(BOARDY + i * 2, BOARDX); - waddch(boardwin, ACS_LTEE); - for (j = 0; j < BWIDTH - 1; j++) { - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_PLUS); - } - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_RTEE); - } - - move(BOARDY + i * 2 - 1, BOARDX); - waddch(boardwin, ACS_VLINE); - for (j = 0; j < BWIDTH; j++) { - waddch(boardwin, ' '); - waddch(boardwin, ' '); - waddch(boardwin, ' '); - waddch(boardwin, ACS_VLINE); - } - - move(BOARDY + i * 2, BOARDX); - waddch(boardwin, ACS_LLCORNER); - for (j = 0; j < BWIDTH - 1; j++) { - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_BTEE); - } - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_HLINE); - waddch(boardwin, ACS_LRCORNER); -} - -static void -mark_possibles(int prow, int pcol, chtype mark) -{ - if (chksqr(prow + 2, pcol + 1)) { - cellmove(prow + 2, pcol + 1); - waddch(boardwin, mark); - }; - if (chksqr(prow + 2, pcol - 1)) { - cellmove(prow + 2, pcol - 1); - waddch(boardwin, mark); - }; - if (chksqr(prow - 2, pcol + 1)) { - cellmove(prow - 2, pcol + 1); - waddch(boardwin, mark); - }; - if (chksqr(prow - 2, pcol - 1)) { - cellmove(prow - 2, pcol - 1); - waddch(boardwin, mark); - }; - if (chksqr(prow + 1, pcol + 2)) { - cellmove(prow + 1, pcol + 2); - waddch(boardwin, mark); - }; - if (chksqr(prow + 1, pcol - 2)) { - cellmove(prow + 1, pcol - 2); - waddch(boardwin, mark); - }; - if (chksqr(prow - 1, pcol + 2)) { - cellmove(prow - 1, pcol + 2); - waddch(boardwin, mark); - }; - if (chksqr(prow - 1, pcol - 2)) { - cellmove(prow - 1, pcol - 2); - waddch(boardwin, mark); - }; -} - -static void -drawmove(char tchar, int oldy, int oldx, int row, int column) -/* place the stars, update board & currents */ -{ - if (movecount <= 1) { - int i, j; - - for (i = 0; i < BDEPTH; i++) - for (j = 0; j < BWIDTH; j++) { - cellmove(i, j); - if (winch(boardwin) == minus) - waddch(boardwin, movecount ? ' ' : minus); - } - } else { - cellmove(oldy, oldx); - waddch(boardwin, '\b'); - waddch(boardwin, tchar); - waddch(boardwin, tchar); - waddch(boardwin, tchar); - mark_possibles(oldy, oldx, ' '); - } - - if (row != -1 && column != -1) { - cellmove(row, column); - waddch(boardwin, '\b'); - waddch(boardwin, trail); - waddch(boardwin, trail); - waddch(boardwin, trail); - mark_possibles(row, column, minus); - board[row][column] = TRUE; - } - - wprintw(msgwin, "\nMove %d", movecount); -} - -static bool -evalmove(int row, int column) -/* evaluate move */ -{ - if (movecount == 1) - return (TRUE); - else if (board[row][column] == TRUE) { - waddstr(msgwin, "\nYou've already been there."); - return (FALSE); - } else { - int rdif = iabs(row - history[movecount - 1].y); - int cdif = iabs(column - history[movecount - 1].x); - - if (!((rdif == 1) && (cdif == 2)) && !((rdif == 2) && (cdif == 1))) { - waddstr(msgwin, "\nThat's not a legal knight's move."); - return (FALSE); - } - } - - return (TRUE); -} - -static bool -chkmoves(void) -/* check to see if valid moves are available */ +int +main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { - if (chksqr(rw + 2, col + 1)) - return (TRUE); - if (chksqr(rw + 2, col - 1)) - return (TRUE); - if (chksqr(rw - 2, col + 1)) - return (TRUE); - if (chksqr(rw - 2, col - 1)) - return (TRUE); - if (chksqr(rw + 1, col + 2)) - return (TRUE); - if (chksqr(rw + 1, col - 2)) - return (TRUE); - if (chksqr(rw - 1, col + 2)) - return (TRUE); - if (chksqr(rw - 1, col - 2)) - return (TRUE); - return (FALSE); -} + init_program(); -static int -iabs(int num) -{ - if (num < 0) - return (-num); - else - return (num); -} + play(); -static bool -chksqr(int r1, int c1) -{ - if ((r1 < 0) || (r1 > BDEPTH - 1)) - return (FALSE); - if ((c1 < 0) || (c1 > BWIDTH - 1)) - return (FALSE); - return ((!board[r1][c1]) ? TRUE : FALSE); + endwin(); + return EXIT_SUCCESS; } /* knight.c ends here */ diff --git a/contrib/ncurses/test/lrtest.c b/contrib/ncurses/test/lrtest.c index fb99641..f2fc9d2 100644 --- a/contrib/ncurses/test/lrtest.c +++ b/contrib/ncurses/test/lrtest.c @@ -1,12 +1,13 @@ /* * Test lower-right-hand corner access * - * by Eric S. Raymond <esr@thyrsus.com> + * originally by Eric S. Raymond <esr@thyrsus.com>, written for animation + * and resizing -TD * * This can't be part of the ncurses test-program, because ncurses rips off the * bottom line to do labels. * - * $Id: lrtest.c,v 0.14 1999/10/23 19:44:35 tom Exp $ + * $Id: lrtest.c,v 0.15 2000/12/31 02:09:42 tom Exp $ */ #include <test.priv.h> @@ -56,8 +57,8 @@ show(MARK * m) int main( - int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) + int argc GCC_UNUSED, + char *argv[]GCC_UNUSED) { static MARK marks[] = { @@ -83,8 +84,8 @@ main( move(LINES / 2 - 1, 4); if (!(has_ic() /* see PutCharLR() */ - || auto_right_margin - || (enter_am_mode && exit_am_mode))) { + || auto_right_margin + || (enter_am_mode && exit_am_mode))) { addstr("Your terminal lacks the capabilities needed to address the\n"); move(LINES / 2, 4); addstr("lower-right-hand corner of the screen.\n"); @@ -103,7 +104,7 @@ main( unsigned n; box(stdscr, 0, 0); - for (n = 0; n < sizeof(marks) / sizeof(marks[0]); n++) { + for (n = 0; n < SIZEOF(marks); n++) { show(&marks[n]); } @@ -116,12 +117,24 @@ main( nodelay(stdscr, TRUE); #ifdef KEY_RESIZE else if (ch == KEY_RESIZE) { + for (n = 0; n < SIZEOF(marks); n++) { + if (marks[n].mode == 0) { /* moving along x-direction */ + if (marks[n].y) + marks[n].y = LINES - 1; + } else { + if (marks[n].x) + marks[n].x = COLS - 1; + } + } + flash(); erase(); + wrefresh(curscr); goto restart; } #endif } napms(50); + refresh(); } curs_set(1); diff --git a/contrib/ncurses/test/ncurses.c b/contrib/ncurses/test/ncurses.c index ad1aa01..8bbf023 100644 --- a/contrib/ncurses/test/ncurses.c +++ b/contrib/ncurses/test/ncurses.c @@ -39,7 +39,7 @@ DESCRIPTION AUTHOR Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993 -$Id: ncurses.c,v 1.138 2000/09/17 01:24:00 tom Exp $ +$Id: ncurses.c,v 1.143 2001/05/12 23:49:04 tom Exp $ ***************************************************************************/ @@ -119,6 +119,9 @@ extern int _nc_tracing; #define ESCAPE CTRL('[') #define BLANK ' ' /* this is the background character */ +static int max_colors; /* the actual number of colors we'll use */ +static int max_pairs; /* ...and the number of color pairs */ + /* The behavior of mvhline, mvvline for negative/zero length is unspecified, * though we can rely on negative x/y values to stop the macro. */ @@ -253,7 +256,7 @@ getch_test(void) int c; int incount = 0, firsttime = 0; bool blocking = TRUE; - int y, x; + int y; refresh(); @@ -267,7 +270,7 @@ getch_test(void) noecho(); nonl(); - if (isdigit(buf[0])) { + if (isdigit(CharOf(buf[0]))) { timeout(atoi(buf) * 100); blocking = FALSE; } @@ -301,7 +304,7 @@ getch_test(void) else (void) printw("%s (ASCII control character)\n", unctrl(c)); } - getyx(stdscr, y, x); + y = getcury(stdscr); if (y >= LINES - 1) move(0, 0); clrtoeol(); @@ -405,7 +408,7 @@ show_attr(int row, int skip, chtype attr, const char *name) }; unsigned n; bool found = FALSE; - for (n = 0; n < sizeof(table) / sizeof(table[0]); n++) { + for (n = 0; n < SIZEOF(table); n++) { if ((table[n] & attr) != 0 && ((1 << n) & ncv) != 0) { found = TRUE; @@ -426,11 +429,9 @@ attr_getc(int *skip, int *fg, int *bg, int *ac) if (isdigit(ch)) { *skip = (ch - '0'); - return TRUE; } else if (ch == CTRL('L')) { touchwin(stdscr); touchwin(curscr); - return TRUE; } else if (has_colors()) { switch (ch) { case 'a': @@ -454,15 +455,14 @@ attr_getc(int *skip, int *fg, int *bg, int *ac) default: return FALSE; } - if (*fg >= COLORS) + if (*fg >= max_colors) *fg = 0; if (*fg < 0) - *fg = COLORS - 1; - if (*bg >= COLORS) + *fg = max_colors - 1; + if (*bg >= max_colors) *bg = 0; if (*bg < 0) - *bg = COLORS - 1; - return TRUE; + *bg = max_colors - 1; } else { switch (ch) { case 'a': @@ -474,9 +474,8 @@ attr_getc(int *skip, int *fg, int *bg, int *ac) default: return FALSE; } - return TRUE; } - return FALSE; + return TRUE; } static void @@ -488,7 +487,7 @@ attr_test(void) int fg = COLOR_BLACK; /* color pair 0 is special */ int bg = COLOR_BLACK; int ac = 0; - bool *pairs = (bool *) calloc(COLOR_PAIRS, sizeof(bool)); + bool *pairs = (bool *) calloc(max_pairs, sizeof(bool)); pairs[0] = TRUE; if (skip < 0) @@ -501,7 +500,7 @@ attr_test(void) int normal = A_NORMAL | BLANK; if (has_colors()) { - int pair = (fg * COLORS) + bg; + int pair = (fg * max_colors) + bg; if (!pairs[pair]) { init_pair(pair, fg, bg); pairs[pair] = TRUE; @@ -574,7 +573,7 @@ static NCURSES_CONST char *color_names[] = static void show_color_name(int y, int x, int color) { - if (COLORS > 8) + if (max_colors > 8) mvprintw(y, x, "%02d ", color); else mvaddstr(y, x, color_names[color]); @@ -591,29 +590,30 @@ color_test(void) refresh(); (void) printw("There are %d color pairs\n", COLOR_PAIRS); - width = (COLORS > 8) ? 4 : 8; - hello = (COLORS > 8) ? "Test" : "Hello"; + width = (max_colors > 8) ? 4 : 8; + hello = (max_colors > 8) ? "Test" : "Hello"; for (base = 0; base < 2; base++) { - top = (COLORS > 8) ? 0 : base * (COLORS + 3); + top = (max_colors > 8) ? 0 : base * (max_colors + 3); clrtobot(); (void) mvprintw(top + 1, 0, "%dx%d matrix of foreground/background colors, bright *%s*\n", - COLORS, COLORS, + max_colors, max_colors, base ? "on" : "off"); - for (i = 0; i < COLORS; i++) + for (i = 0; i < max_colors; i++) show_color_name(top + 2, (i + 1) * width, i); - for (i = 0; i < COLORS; i++) + for (i = 0; i < max_colors; i++) show_color_name(top + 3 + i, 0, i); - for (i = 1; i < COLOR_PAIRS; i++) { - init_pair(i, i % COLORS, i / COLORS); + for (i = 1; i < max_pairs; i++) { + init_pair(i, i % max_colors, i / max_colors); attron((attr_t) COLOR_PAIR(i)); if (base) attron((attr_t) A_BOLD); - mvaddstr(top + 3 + (i / COLORS), (i % COLORS + 1) * width, hello); + mvaddstr(top + 3 + (i / max_colors), (i % max_colors + 1) * + width, hello); attrset(A_NORMAL); } - if ((COLORS > 8) || base) + if ((max_colors > 8) || base) Pause(); } @@ -653,7 +653,6 @@ color_edit(void) { int i, this_c = 0, value = 0, current = 0, field = 0; int last_c; - int max_colors = COLORS > 16 ? 16 : COLORS; refresh(); @@ -1200,7 +1199,7 @@ newwin_legend(FRAME * curp) } }; size_t n; - int y, x; + int x; bool do_keypad = HaveKeypad(curp); bool do_scroll = HaveScroll(curp); char buf[BUFSIZ]; @@ -1221,7 +1220,7 @@ newwin_legend(FRAME * curp) sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : ""); break; } - getyx(stdscr, y, x); + x = getcurx(stdscr); addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : "")); addstr(buf); } @@ -2297,7 +2296,7 @@ padgetch(WINDOW *win) switch (c = wGetchar(win)) { case '!': ShellOut(FALSE); - c = KEY_REFRESH; + /* FALLTHRU */ case CTRL('r'): endwin(); refresh(); @@ -3022,7 +3021,7 @@ form_virtualize(FORM * f, WINDOW *w) mode = REQ_INS_MODE; c = mode; } else { - for (n = 0; n < sizeof(lookup) / sizeof(lookup[0]); n++) { + for (n = 0; n < SIZEOF(lookup); n++) { if (lookup[n].code == c) { c = lookup[n].result; break; @@ -3366,7 +3365,7 @@ usage(void) #endif }; size_t n; - for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); n++) + for (n = 0; n < SIZEOF(tbl); n++) fprintf(stderr, "%s\n", tbl[n]); exit(EXIT_FAILURE); } @@ -3504,12 +3503,20 @@ main(int argc, char *argv[]) /* tests, in general, will want these modes */ if (has_colors()) { start_color(); -#ifdef NCURSES_VERSION +#ifdef NCURSES_VERSION_PATCH + max_colors = COLORS > 16 ? 16 : COLORS; if (default_colors) use_default_colors(); +#if NCURSES_VERSION_PATCH >= 20000708 else if (assumed_colors) assume_default_colors(default_fg, default_bg); #endif +#else /* normal SVr4 curses */ + max_colors = COLORS > 8 ? 8 : COLORS; +#endif + max_pairs = (max_colors * max_colors); + if (max_pairs < COLOR_PAIRS) + max_pairs = COLOR_PAIRS; } set_terminal_modes(); def_prog_mode(); @@ -3574,7 +3581,7 @@ main(int argc, char *argv[]) if (command == 0) command = 'q'; break; - } else if (command == 0 && !isspace(ch)) { + } else if (command == 0 && !isspace(CharOf(ch))) { command = ch; } else if (ch == '\n' || ch == '\r') { if (command != 0) diff --git a/contrib/ncurses/test/newdemo.c b/contrib/ncurses/test/newdemo.c index d47d275..c0042e2 100644 --- a/contrib/ncurses/test/newdemo.c +++ b/contrib/ncurses/test/newdemo.c @@ -2,7 +2,7 @@ * newdemo.c - A demo program using PDCurses. The program illustrate * the use of colours for text output. * - * $Id: newdemo.c,v 1.17 1997/09/20 15:11:26 tom Exp $ + * $Id: newdemo.c,v 1.18 2001/03/10 22:27:17 tom Exp $ */ #include <test.priv.h> @@ -11,11 +11,6 @@ #include <time.h> #include <string.h> -static int SubWinTest(WINDOW *win); -static int WaitForUser(WINDOW *win); -static int BouncingBalls(WINDOW *win); -static RETSIGTYPE trap(int); - #define delay_output(x) napms(x) /* @@ -54,157 +49,59 @@ NCURSES_CONST char *messages[] = }; /* - * Main driver + * Trap interrupt */ -int -main( - int argc GCC_UNUSED, - char *argv[] GCC_UNUSED) +static RETSIGTYPE +trap(int sig GCC_UNUSED) { -WINDOW *win; -int w, x, y, i, j, k; -char buffer[200]; -const char *message; -int width, height; -chtype save[80]; -chtype c; + endwin(); + exit(EXIT_FAILURE); +} - initscr(); - start_color(); - cbreak(); - signal(SIGINT, trap); - width = 48; - height = 14; /* Create a drawing window */ - win = newwin(height, width, (LINES-height)/2, (COLS-width)/2); - if(win == NULL) - { endwin(); - return 1; +/* + * Wait for user + */ +static int +WaitForUser(WINDOW *win) +{ + time_t t; + chtype key; + + nodelay(win, TRUE); + t = time((time_t *) 0); + while (1) { + if ((int) (key = wgetch(win)) != ERR) { + if (key == 'q' || key == 'Q') + return 1; + else + return 0; + } + if (time((time_t *) 0) - t > 5) + return 0; } +} - while(1) - { init_pair(1,COLOR_WHITE,COLOR_BLUE); - wattrset(win, COLOR_PAIR(1)); - werase(win); - - init_pair(2,COLOR_RED,COLOR_RED); - wattrset(win, COLOR_PAIR(2)); - box(win, ACS_VLINE, ACS_HLINE); - wrefresh(win); - /* Do ramdom output of a character */ - wattrset(win, COLOR_PAIR(1)); - c = 'a'; - for(i=0; i < 5000; ++i) - { x = rand() % (width-2) + 1; - y = rand() % (height-2) + 1; - mvwaddch(win, y, x, c); - wrefresh(win); - nodelay(win,TRUE); - if (wgetch(win) != ERR) - break; - if(i == 2000) - { c = 'b'; - init_pair(3,COLOR_CYAN,COLOR_YELLOW); - wattron(win, COLOR_PAIR(3)); - } - } - - SubWinTest(win); - /* Erase and draw green window */ - init_pair(4,COLOR_YELLOW,COLOR_GREEN); - wbkgd(win, COLOR_PAIR(4) | A_BOLD); - wattrset(win, COLOR_PAIR(4) | A_BOLD); - werase(win); - wrefresh(win); - /* Draw RED bounding box */ - wattrset(win, COLOR_PAIR(2)); - box(win, ' ', ' '); - wrefresh(win); - /* Display Australia map */ - wattrset(win, COLOR_PAIR(4) | A_BOLD); - i = 0; - while(*AusMap[i]) - { mvwaddstr(win, i+1, 8, AusMap[i]); - wrefresh(win); - delay_output(50); - ++i; - } - - init_pair(5,COLOR_BLUE,COLOR_WHITE); - wattrset(win, COLOR_PAIR(5) | A_BLINK); - mvwaddstr(win, height-2, 6, " PDCurses 2.1 for DOS, OS/2 and Unix"); - wrefresh(win); - - /* Draw running messages */ - init_pair(6,COLOR_YELLOW,COLOR_WHITE); - wattrset(win, COLOR_PAIR(6)); - message = messages[j = 0]; - i = 1; - w = width-2; - strcpy(buffer, message); - while(j < NMESSAGES) { - while ((int)strlen(buffer) < w) { - strcat(buffer, " ... "); - strcat(buffer, messages[++j % NMESSAGES]); - } - - if (i < w) - mvwaddnstr(win, height/2, w - i, buffer, i); - else - mvwaddnstr(win, height/2, 1, buffer, w); - - wrefresh(win); - nodelay(win,TRUE); - if (wgetch(win) != ERR) - { flushinp(); - break; - } - if (i++ >= w) { - for (k = 0; (buffer[k] = buffer[k+1]) != '\0'; k++) - ; - } - delay_output(100); - } - - j = 0; - /* Draw running As across in RED */ - init_pair(7,COLOR_RED,COLOR_GREEN); - wattron(win, COLOR_PAIR(7)); - for(i=2; i < width - 4; ++i) - { - k = mvwinch(win, 4, i); - if (k == ERR) - break; - save[j++] = c = k; - c &= A_CHARTEXT; - mvwaddch(win, 4, i, c); - } - wrefresh(win); - - /* Put a message up wait for a key */ - i = height-2; - wattrset(win, COLOR_PAIR(5)); - mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit "); - wrefresh(win); - - if(WaitForUser(win) == 1) - break; - - j = 0; /* Restore the old line */ - for(i=2; i < width - 4; ++i) - mvwaddch(win, 4, i, save[j++]); - wrefresh(win); +static void +set_colors(WINDOW *win, int pair, int foreground, int background) +{ + if (has_colors()) { + if (pair > COLOR_PAIRS) + pair = COLOR_PAIRS; + init_pair(pair, foreground, background); + wattrset(win, COLOR_PAIR(pair)); + } +} - BouncingBalls(win); - /* Put a message up wait for a key */ - i = height-2; - wattrset(win, COLOR_PAIR(5)); - mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit "); - wrefresh(win); - if(WaitForUser(win) == 1) - break; +static int +use_colors(WINDOW *win, int pair, int attrs) +{ + if (has_colors()) { + if (pair > COLOR_PAIRS) + pair = COLOR_PAIRS; + attrs |= COLOR_PAIR(pair); } - endwin(); - return 0; + wattrset(win, attrs); + return attrs; } /* @@ -213,34 +110,31 @@ chtype c; static int SubWinTest(WINDOW *win) { -int w, h, sw, sh, bx, by; -WINDOW *swin1, *swin2, *swin3; + int w, h, sw, sh, bx, by; + WINDOW *swin1, *swin2, *swin3; - getmaxyx(win, h, w); + getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; - if((swin1 = subwin(win, sh, sw, by+3, bx+5)) == NULL) - return 1; - if((swin2 = subwin(win, sh, sw, by+4, bx+8)) == NULL) - return 1; - if((swin3 = subwin(win, sh, sw, by+5, bx+11)) == NULL) - return 1; - - init_pair(8,COLOR_RED,COLOR_BLUE); - wattrset(swin1, COLOR_PAIR(8)); + if ((swin1 = subwin(win, sh, sw, by + 3, bx + 5)) == NULL) + return 1; + if ((swin2 = subwin(win, sh, sw, by + 4, bx + 8)) == NULL) + return 1; + if ((swin3 = subwin(win, sh, sw, by + 5, bx + 11)) == NULL) + return 1; + + set_colors(swin1, 8, COLOR_RED, COLOR_BLUE); werase(swin1); mvwaddstr(swin1, 0, 3, "Sub-window 1"); wrefresh(swin1); - init_pair(8,COLOR_CYAN,COLOR_MAGENTA); - wattrset(swin2, COLOR_PAIR(8)); + set_colors(swin2, 9, COLOR_CYAN, COLOR_MAGENTA); werase(swin2); mvwaddstr(swin2, 0, 3, "Sub-window 2"); wrefresh(swin2); - init_pair(8,COLOR_YELLOW,COLOR_GREEN); - wattrset(swin3, COLOR_PAIR(8)); + set_colors(swin3, 10, COLOR_YELLOW, COLOR_GREEN); werase(swin3); mvwaddstr(swin3, 0, 3, "Sub-window 3"); wrefresh(swin3); @@ -249,7 +143,19 @@ WINDOW *swin1, *swin2, *swin3; delwin(swin2); delwin(swin3); WaitForUser(win); - return 0; + return 0; +} + +static int +bounce(int n, int *dir, int len) +{ + if (*dir > 0) + ++n; + else + --n; + if (n <= 1 || n >= len - 2) + *dir = *dir ? 0 : 1; + return n; } /* @@ -258,91 +164,195 @@ WINDOW *swin1, *swin2, *swin3; static int BouncingBalls(WINDOW *win) { -int w, h; -int x1, y1, xd1, yd1; -int x2, y2, xd2, yd2; -int x3, y3, xd3, yd3; + int w, h; + int x1, y1, xd1, yd1; + int x2, y2, xd2, yd2; + int x3, y3, xd3, yd3; getmaxyx(win, h, w); - x1 = 2 + rand() % (w - 4); - y1 = 2 + rand() % (h - 4); - x2 = 2 + rand() % (w - 4); - y2 = 2 + rand() % (h - 4); - x3 = 2 + rand() % (w - 4); - y3 = 2 + rand() % (h - 4); - xd1 = 1; yd1 = 1; - xd2 = 1; yd2 = 0; - xd3 = 0; yd3 = 1; - nodelay(win,TRUE); - while(wgetch(win) == ERR) - { x1 = xd1 > 0 ? ++x1 : --x1; - if(x1 <= 1 || x1 >= w - 2) - xd1 = xd1 ? 0 : 1; - y1 = yd1 > 0 ? ++y1 : --y1; - if(y1 <= 1 || y1 >= h - 2) - yd1 = yd1 ? 0 : 1; - - x2 = xd2 > 0 ? ++x2 : --x2; - if(x2 <= 1 || x2 >= w - 2) - xd2 = xd2 ? 0 : 1; - y2 = yd2 > 0 ? ++y2 : --y2; - if(y2 <= 1 || y2 >= h - 2) - yd2 = yd2 ? 0 : 1; - - x3 = xd3 > 0 ? ++x3 : --x3; - if(x3 <= 1 || x3 >= w - 2) - xd3 = xd3 ? 0 : 1; - y3 = yd3 > 0 ? ++y3 : --y3; - if(y3 <= 1 || y3 >= h - 2) - yd3 = yd3 ? 0 : 1; - - init_pair(8,COLOR_RED,COLOR_BLUE); - wattrset(win, COLOR_PAIR(8)); + + x1 = 2 + rand() % (w - 4); + y1 = 2 + rand() % (h - 4); + x2 = 2 + rand() % (w - 4); + y2 = 2 + rand() % (h - 4); + x3 = 2 + rand() % (w - 4); + y3 = 2 + rand() % (h - 4); + + xd1 = 1; + yd1 = 1; + xd2 = 1; + yd2 = 0; + xd3 = 0; + yd3 = 1; + + nodelay(win, TRUE); + + while (wgetch(win) == ERR) { + x1 = bounce(x1, &xd1, w); + y1 = bounce(y1, &yd1, h); + x2 = bounce(x2, &xd2, w); + y2 = bounce(y2, &yd2, h); + x3 = bounce(x3, &xd3, w); + y3 = bounce(y3, &yd3, h); + + set_colors(win, 11, COLOR_RED, COLOR_BLUE); mvwaddch(win, y1, x1, 'O'); - init_pair(8,COLOR_BLUE,COLOR_RED); - wattrset(win, COLOR_PAIR(8)); - mvwaddch(win, y2, x2, '*'); - init_pair(8,COLOR_YELLOW,COLOR_WHITE); - wattrset(win, COLOR_PAIR(8)); - mvwaddch(win, y3, x3, '@'); - wmove(win, 0, 0); - wrefresh(win); + + set_colors(win, 12, COLOR_BLUE, COLOR_RED); + mvwaddch(win, y2, x2, '*'); + + set_colors(win, 13, COLOR_YELLOW, COLOR_WHITE); + mvwaddch(win, y3, x3, '@'); + + wmove(win, 0, 0); + wrefresh(win); delay_output(100); } return 0; } /* - * Wait for user + * Main driver */ -static int WaitForUser(WINDOW *win) +int +main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { - time_t t; - chtype key; - - nodelay(win,TRUE); - t = time((time_t *)0); - while(1) - { - if ((int)(key = wgetch(win)) != ERR) - { - if (key == 'q' || key == 'Q') - return 1; - else - return 0; - } - if (time((time_t *)0) - t > 5) - return 0; - } -} + WINDOW *win; + int w, x, y, i, j, k; + char buffer[200]; + const char *message; + int width, height; + chtype save[80]; + chtype c; -/* - * Trap interrupt - */ -static RETSIGTYPE trap(int sig GCC_UNUSED) -{ + initscr(); + if (has_colors()) + start_color(); + cbreak(); + curs_set(0); + signal(SIGINT, trap); + width = 48; + height = 14; /* Create a drawing window */ + win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); + if (win == NULL) { + endwin(); + return 1; + } + + while (1) { + set_colors(win, 1, COLOR_WHITE, COLOR_BLUE); + werase(win); + + set_colors(win, 2, COLOR_RED, COLOR_RED); + box(win, ACS_VLINE, ACS_HLINE); + wrefresh(win); + /* Do ramdom output of a character */ + use_colors(win, 1, A_NORMAL); + c = 'a'; + for (i = 0; i < 5000; ++i) { + x = rand() % (width - 2) + 1; + y = rand() % (height - 2) + 1; + mvwaddch(win, y, x, c); + wrefresh(win); + nodelay(win, TRUE); + if (wgetch(win) != ERR) + break; + if (i == 2000) { + c = 'b'; + set_colors(win, 3, COLOR_CYAN, COLOR_YELLOW); + } + } + + SubWinTest(win); + /* Erase and draw green window */ + set_colors(win, 4, COLOR_YELLOW, COLOR_GREEN); + wbkgd(win, use_colors(win, 4, A_BOLD)); + werase(win); + wrefresh(win); + /* Draw RED bounding box */ + use_colors(win, 2, A_NORMAL); + box(win, ' ', ' '); + wrefresh(win); + /* Display Australia map */ + use_colors(win, 4, A_BOLD); + i = 0; + while (*AusMap[i]) { + mvwaddstr(win, i + 1, 8, AusMap[i]); + wrefresh(win); + delay_output(50); + ++i; + } + + set_colors(win, 5, COLOR_BLUE, COLOR_WHITE); + use_colors(win, 5, A_BLINK); + mvwaddstr(win, height - 2, 6, " PDCurses 2.1 for DOS, OS/2 and Unix"); + wrefresh(win); + + /* Draw running messages */ + set_colors(win, 6, COLOR_YELLOW, COLOR_WHITE); + message = messages[j = 0]; + i = 1; + w = width - 2; + strcpy(buffer, message); + while (j < NMESSAGES) { + while ((int) strlen(buffer) < w) { + strcat(buffer, " ... "); + strcat(buffer, messages[++j % NMESSAGES]); + } + + if (i < w) + mvwaddnstr(win, height / 2, w - i, buffer, i); + else + mvwaddnstr(win, height / 2, 1, buffer, w); + + wrefresh(win); + nodelay(win, TRUE); + if (wgetch(win) != ERR) { + flushinp(); + break; + } + if (i++ >= w) { + for (k = 0; (buffer[k] = buffer[k + 1]) != '\0'; k++) ; + } + delay_output(100); + } + + j = 0; + /* Draw running As across in RED */ + set_colors(win, 7, COLOR_RED, COLOR_GREEN); + for (i = 2; i < width - 4; ++i) { + k = mvwinch(win, 4, i); + if (k == ERR) + break; + save[j++] = c = k; + c &= A_CHARTEXT; + mvwaddch(win, 4, i, c); + } + wrefresh(win); + + /* Put a message up wait for a key */ + i = height - 2; + use_colors(win, 5, A_NORMAL); + mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit "); + wrefresh(win); + + if (WaitForUser(win) == 1) + break; + + j = 0; /* Restore the old line */ + for (i = 2; i < width - 4; ++i) + mvwaddch(win, 4, i, save[j++]); + wrefresh(win); + + BouncingBalls(win); + /* Put a message up wait for a key */ + i = height - 2; + use_colors(win, 5, A_NORMAL); + mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit "); + wrefresh(win); + if (WaitForUser(win) == 1) + break; + } endwin(); - exit(EXIT_FAILURE); + return 0; } - -/* End of DEMO.C */ diff --git a/contrib/ncurses/test/railroad.c b/contrib/ncurses/test/railroad.c index a9aa306..6d5cd25 100644 --- a/contrib/ncurses/test/railroad.c +++ b/contrib/ncurses/test/railroad.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey <dickey@clark.net> 2000 * - * $Id: railroad.c,v 1.3 2000/09/24 00:20:33 tom Exp $ + * $Id: railroad.c,v 1.5 2001/03/24 22:01:42 tom Exp $ * * A simple demo of the termcap interface. */ @@ -120,7 +120,7 @@ ShowSign(char *string) while (*string != 0) { ch = *string; if (moveit != 0) { - for (first = length - 1; first > (string - base); first--) { + for (first = length - 2; first >= (string - base); first--) { if (first < length - 1) { tputs(tgoto(moveit, first + 1, height - 1), 1, outc); PutChar(' '); @@ -233,8 +233,9 @@ main(int argc, char *argv[]) if (argc > 1) { railroad(argv + 1); } else { + static char world[] = "Hello World"; static char *hello[] = - {"Hello World", 0}; + {world, 0}; railroad(hello); } return EXIT_SUCCESS; diff --git a/contrib/ncurses/test/tclock.c b/contrib/ncurses/test/tclock.c index 9f84655..319b0d4 100644 --- a/contrib/ncurses/test/tclock.c +++ b/contrib/ncurses/test/tclock.c @@ -104,11 +104,11 @@ dline(int pair, int from_x, int from_y, int x2, int y2, char ch) int main( - int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) + int argc GCC_UNUSED, + char *argv[]GCC_UNUSED) { int i, cx, cy; - double mradius, hradius, mangle, hangle; + double cr, mradius, hradius, mangle, hangle; double sangle, sradius, hours; int hdx, hdy; int mdx, mdy; @@ -142,14 +142,16 @@ main( #endif cx = (COLS - 1) / 2; /* 39 */ cy = LINES / 2; /* 12 */ - ch = (cx > cy) ? cy : cx; /* usually cy */ - mradius = (3 * cy) / 4; /* 9 */ - hradius = cy / 2; /* 6 */ - sradius = (2 * cy) / 3; /* 8 */ + if (cx / ASPECT < cy) + cr = cx / ASPECT; + else + cr = cy; + sradius = (5 * cr) / 6; /* 10 */ + mradius = (3 * cr) / 4; /* 9 */ + hradius = cr / 2; /* 6 */ for (i = 0; i < 12; i++) { sangle = (i + 1) * (2.0 * PI) / 12.0; - sradius = (5 * cy) / 6; /* 10 */ sdx = A2X(sangle, sradius); sdy = A2Y(sangle, sradius); sprintf(szChar, "%d", i + 1); @@ -159,9 +161,9 @@ main( mvaddstr(0, 0, "ASCII Clock by Howard Jones (ha.jones@ic.ac.uk),1994"); - sradius = 8; + sradius = (4 * sradius) / 5; for (;;) { - napms(1000); + napms(100); tim = time(0); t = localtime(&tim); @@ -199,7 +201,7 @@ main( mvaddstr(LINES - 2, 0, ctime(&tim)); refresh(); if ((t->tm_sec % 5) == 0 - && t->tm_sec != lastbeep) { + && t->tm_sec != lastbeep) { lastbeep = t->tm_sec; beep(); } @@ -207,7 +209,9 @@ main( if ((ch = getch()) != ERR) { #ifdef KEY_RESIZE if (ch == KEY_RESIZE) { + flash(); erase(); + wrefresh(curscr); goto restart; } #endif diff --git a/contrib/ncurses/test/test.priv.h b/contrib/ncurses/test/test.priv.h index 58bbd16..f5ecf02 100644 --- a/contrib/ncurses/test/test.priv.h +++ b/contrib/ncurses/test/test.priv.h @@ -29,7 +29,7 @@ /**************************************************************************** * Author: Thomas E. Dickey <dickey@clark.net> 1996 * ****************************************************************************/ -/* $Id: test.priv.h,v 1.19 2000/09/02 19:31:58 tom Exp $ */ +/* $Id: test.priv.h,v 1.20 2000/11/04 22:56:50 tom Exp $ */ #if HAVE_CONFIG_H #include <ncurses_cfg.h> @@ -87,6 +87,8 @@ extern int optind; #define GCC_UNUSED /* nothing */ #endif +#define CharOf(c) ((unsigned char)(c)) + #define SIZEOF(table) (sizeof(table)/sizeof(table[0])) #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H diff --git a/contrib/ncurses/test/testcurs.c b/contrib/ncurses/test/testcurs.c index 5fa054a..efcd39fa 100644 --- a/contrib/ncurses/test/testcurs.c +++ b/contrib/ncurses/test/testcurs.c @@ -7,7 +7,7 @@ * wrs(5/28/93) -- modified to be consistent (perform identically) with either * PDCurses or under Unix System V, R4 * - * $Id: testcurs.c,v 1.22 2000/06/17 23:23:34 tom Exp $ + * $Id: testcurs.c,v 1.24 2001/02/24 22:13:23 tom Exp $ */ #include <test.priv.h> @@ -45,7 +45,7 @@ const COMMAND command[] = {"Input Test", inputTest}, {"Output Test", outputTest} }; -#define MAX_OPTIONS ((sizeof(command)/sizeof(command[0]))) +#define MAX_OPTIONS SIZEOF(command) int width, height; @@ -197,11 +197,11 @@ scrollTest(WINDOW *win) { int i; int half; - int OldX, OldY; + int OldY; NCURSES_CONST char *Message = "The window will now scroll slowly"; wclear(win); - getmaxyx(win, OldY, OldX); + OldY = getmaxy(win); half = OldY / 2; mvwprintw(win, OldY - 2, 1, Message); wrefresh(win); diff --git a/contrib/ncurses/test/testscanw.c b/contrib/ncurses/test/testscanw.c index 8420ea0..c9a1623 100644 --- a/contrib/ncurses/test/testscanw.c +++ b/contrib/ncurses/test/testscanw.c @@ -2,37 +2,38 @@ * Date: 1997/03/17 * From: bayern@morpheus.cis.yale.edu * - * $Id: testscanw.c,v 1.5 1997/09/20 14:16:20 tom Exp $ + * $Id: testscanw.c,v 1.6 2000/11/04 23:32:56 tom Exp $ */ #include <test.priv.h> #include <ctype.h> -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - long badanswer = 1; - long *response = &badanswer; + long badanswer = 1; + long *response = &badanswer; - initscr(); - scrollok(stdscr, TRUE); - idlok(stdscr, TRUE); - echo(); + initscr(); + scrollok(stdscr, TRUE); + idlok(stdscr, TRUE); + echo(); #if 0 - trace(TRACE_UPDATE|TRACE_CALLS); + trace(TRACE_UPDATE | TRACE_CALLS); #endif - while (argc > 1) { - if (isdigit(*argv[1])) - move(atoi(argv[1]), 0); - else if (!strcmp(argv[1], "-k")) - keypad(stdscr, TRUE); - argc--, argv++; - } + while (argc > 1) { + if (isdigit(CharOf(*argv[1]))) + move(atoi(argv[1]), 0); + else if (!strcmp(argv[1], "-k")) + keypad(stdscr, TRUE); + argc--, argv++; + } - while (badanswer) { - printw("Enter a number (0 to quit):\n"); - printw("--> "); - scanw("%20ld", response); /* yes, it's a pointer */ - } - endwin(); - return EXIT_SUCCESS; + while (badanswer) { + printw("Enter a number (0 to quit):\n"); + printw("--> "); + scanw("%20ld", response); /* yes, it's a pointer */ + } + endwin(); + return EXIT_SUCCESS; } diff --git a/contrib/ncurses/test/view.c b/contrib/ncurses/test/view.c index 4c1344c..ee60f27 100644 --- a/contrib/ncurses/test/view.c +++ b/contrib/ncurses/test/view.c @@ -23,7 +23,7 @@ * scroll operation worked, and the refresh() code only had to do a * partial repaint. * - * $Id: view.c,v 1.31 2000/09/02 18:14:52 tom Exp $ + * $Id: view.c,v 1.35 2001/01/14 01:39:24 tom Exp $ */ #include <test.priv.h> @@ -31,6 +31,7 @@ #include <string.h> #include <ctype.h> #include <signal.h> +#include <time.h> #if HAVE_TERMIOS_H # include <termios.h> @@ -122,7 +123,7 @@ ch_dup(char *src) for (j = k = 0; j < len; j++) { if (utf8_mode) { - unsigned c = src[j] & 0xff; + unsigned c = CharOf(src[j]); /* Combine UTF-8 into Unicode */ if (c < 0x80) { /* We received an ASCII character */ @@ -191,9 +192,12 @@ main(int argc, char *argv[]) FILE *fp; char buf[BUFSIZ]; int i; + int my_delay = 0; chtype **olptr; - int done = FALSE; int length = 0; + int value = 0; + bool done = FALSE; + bool got_number = FALSE; #if CAN_RESIZE bool use_resize = TRUE; #endif @@ -259,11 +263,11 @@ main(int argc, char *argv[]) col = (col | 7) + 1; while ((d - temp) != col) *d++ = ' '; - } else if (isprint(*d) || utf8_mode) { + } else if (isprint(CharOf(*d)) || utf8_mode) { col++; d++; } else { - sprintf(d, "\\%03o", *s & 0xff); + sprintf(d, "\\%03o", CharOf(*s)); d += strlen(d); col = (d - temp); } @@ -278,16 +282,16 @@ main(int argc, char *argv[]) (void) nonl(); /* tell curses not to do NL->CR/NL on output */ (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ + nodelay(stdscr, TRUE); idlok(stdscr, TRUE); /* allow use of insert/delete line */ lptr = lines; while (!done) { int n, c; - bool got_number; - show_all(); + if (!got_number) + show_all(); - got_number = FALSE; n = 0; for (;;) { #if CAN_RESIZE @@ -303,13 +307,16 @@ main(int argc, char *argv[]) clrtoeol(); } addch(c); - n = 10 * n + (c - '0'); + value = 10 * value + (c - '0'); got_number = TRUE; } else break; } - if (!got_number && n == 0) + if (got_number && value) { + n = value; + } else { n = 1; + } switch (c) { case KEY_DOWN: @@ -368,12 +375,29 @@ main(int argc, char *argv[]) case KEY_RESIZE: /* ignore this; ncurses will repaint */ break; #endif -#if CAN_RESIZE + case 's': + if (got_number) { + halfdelay(my_delay = n); + } else { + nodelay(stdscr, FALSE); + my_delay = -1; + } + break; + case ' ': + nodelay(stdscr, TRUE); + my_delay = 0; + break; case ERR: + if (!my_delay) + napms(50); break; -#endif default: beep(); + break; + } + if (c >= KEY_MIN || (c > 0 && !isdigit(c))) { + got_number = FALSE; + value = 0; } } @@ -418,6 +442,7 @@ show_all(void) int i; char temp[BUFSIZ]; chtype *s; + time_t this_time; #if CAN_RESIZE sprintf(temp, "(%3dx%3d) col %d ", LINES, COLS, shift); @@ -429,6 +454,13 @@ show_all(void) move(0, 0); printw("%.*s", COLS, temp); clrtoeol(); + this_time = time((time_t *) 0); + strcpy(temp, ctime(&this_time)); + if ((i = strlen(temp)) != 0) { + temp[--i] = 0; + if (move(0, COLS - i - 2) != ERR) + printw(" %s", temp); + } scrollok(stdscr, FALSE); /* prevent screen from moving */ for (i = 1; i < LINES; i++) { diff --git a/contrib/ncurses/test/worm.c b/contrib/ncurses/test/worm.c index 142982a..02d9e1f 100644 --- a/contrib/ncurses/test/worm.c +++ b/contrib/ncurses/test/worm.c @@ -34,7 +34,7 @@ Options: traces will be dumped. The program stops and waits for one character of input at the beginning and end of the interval. - $Id: worm.c,v 1.31 2000/09/02 18:41:01 tom Exp $ + $Id: worm.c,v 1.32 2000/12/31 01:54:07 tom Exp $ */ #include <test.priv.h> @@ -45,7 +45,6 @@ static chtype flavor[] = { 'O', '*', '#', '$', '%', '0', '@', }; -#define MAXWORMS (sizeof(flavor)/sizeof(chtype)) static const short xinc[] = { 1, 1, 1, 0, -1, -1, -1, 0 @@ -378,7 +377,7 @@ main(int argc, char *argv[]) for (n = 0, w = &worm[0]; n < number; n++, w++) { if ((x = w->xpos[h = w->head]) < 0) { move(y = w->ypos[h] = bottom, x = w->xpos[h] = 0); - addch(flavor[n % MAXWORMS]); + addch(flavor[n % SIZEOF(flavor)]); ref[y][x]++; } else { y = w->ypos[h]; @@ -419,7 +418,7 @@ main(int argc, char *argv[]) if (y < 0) y = 0; - addch(flavor[n % MAXWORMS]); + addch(flavor[n % SIZEOF(flavor)]); ref[w->ypos[h] = y][w->xpos[h] = x]++; } napms(10); |