X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fbs.c;h=aeb92f30a6caf6320462ae66941921c8a66dbde0;hp=f8784853c7620cf233452089adf655d779685b30;hb=29a36e53e1f77a0c3672f2e267d573823d6a9a60;hpb=64f44b13d30e0a7bc2921a9d43755423f81564fd diff --git a/test/bs.c b/test/bs.c index f8784853..aeb92f30 100644 --- a/test/bs.c +++ b/test/bs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc. * + * Copyright (c) 1998-2014,2016 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 * @@ -34,7 +34,7 @@ * v2.0 featuring strict ANSI/POSIX conformance, November 1993. * v2.1 with ncurses mouse support, September 1995 * - * $Id: bs.c,v 1.56 2012/12/08 23:35:58 tom Exp $ + * $Id: bs.c,v 1.64 2016/08/21 00:03:32 tom Exp $ */ #include @@ -110,7 +110,7 @@ static char sub[] = "Submarine"; static char destroy[] = "Destroyer"; static char ptboat[] = "PT Boat"; -static char name[40]; +static char *your_name; static char dftname[] = "stranger"; /* direction constants */ @@ -174,9 +174,9 @@ static int salvo, blitz, closepack; #define PR (void)addstr -static RETSIGTYPE uninitgame(int sig) GCC_NORETURN; +static void uninitgame(int sig) GCC_NORETURN; -static RETSIGTYPE +static void uninitgame(int sig GCC_UNUSED) /* end the game, either normally or due to signal */ { @@ -214,17 +214,18 @@ announceopts(void) static void intro(void) { - char *tmpname; + const char *tmpname; srand((unsigned) (time(0L) + getpid())); /* Kick the random number generator */ CATCHALL(uninitgame); - if ((tmpname = getlogin()) != 0) { - (void) strcpy(name, tmpname); - name[0] = (char) toupper(UChar(name[0])); - } else - (void) strcpy(name, dftname); + if ((tmpname = getlogin()) != 0 && + (your_name = strdup(tmpname)) != 0) { + your_name[0] = (char) toupper(UChar(your_name[0])); + } else { + your_name = dftname; + } (void) initscr(); keypad(stdscr, TRUE); @@ -368,7 +369,7 @@ initgame(void) MvAddCh(PYBASE + i, PXBASE - 3, (chtype) (i + 'A')); #ifdef A_COLOR if (has_colors()) - attron((attr_t) COLOR_PAIR(COLOR_BLUE)); + attron(COLOR_PAIR(COLOR_BLUE)); #endif /* A_COLOR */ (void) addch(' '); for (j = 0; j < BWIDTH; j++) @@ -386,7 +387,7 @@ initgame(void) MvAddCh(CYBASE + i, CXBASE - 3, (chtype) (i + 'A')); #ifdef A_COLOR if (has_colors()) - attron((attr_t) COLOR_PAIR(COLOR_BLUE)); + attron(COLOR_PAIR(COLOR_BLUE)); #endif /* A_COLOR */ (void) addch(' '); for (j = 0; j < BWIDTH; j++) @@ -443,7 +444,7 @@ initgame(void) do { c = (char) getcoord(PLAYER); } while - (!strchr(docked, c)); + (!(strchr) (docked, c)); if (c == 'R') (void) ungetch('R'); @@ -770,7 +771,7 @@ hitship(int x, int y) cgoto(y1, x1); #ifdef A_COLOR if (has_colors()) - attron((attr_t) COLOR_PAIR(COLOR_GREEN)); + attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ (void) addch(MARK_MISS); #ifdef A_COLOR @@ -796,7 +797,7 @@ hitship(int x, int y) pgoto(y1, x1); #ifdef A_COLOR if (has_colors()) - attron((attr_t) COLOR_PAIR(COLOR_RED)); + attron(COLOR_PAIR(COLOR_RED)); #endif /* A_COLOR */ (void) addch(SHOWHIT); #ifdef A_COLOR @@ -835,9 +836,9 @@ plyturn(void) #ifdef A_COLOR if (has_colors()) { if (hit) - attron((attr_t) COLOR_PAIR(COLOR_RED)); + attron(COLOR_PAIR(COLOR_RED)); else - attron((attr_t) COLOR_PAIR(COLOR_GREEN)); + attron(COLOR_PAIR(COLOR_GREEN)); } #endif /* A_COLOR */ (void) addch((chtype) hits[PLAYER][curx][cury]); @@ -955,8 +956,8 @@ cpufire(int x, int y) bool hit, sunk; ship_t *ss = NULL; - hit = board[PLAYER][x][y] ? MARK_HIT : MARK_MISS; - hits[COMPUTER][x][y] = (char) hit; + hit = (bool) board[PLAYER][x][y]; + hits[COMPUTER][x][y] = (hit ? MARK_HIT : MARK_MISS); MvPrintw(PROMPTLINE, 0, "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss"); @@ -968,9 +969,9 @@ cpufire(int x, int y) #ifdef A_COLOR if (has_colors()) { if (hit) - attron((attr_t) COLOR_PAIR(COLOR_RED)); + attron(COLOR_PAIR(COLOR_RED)); else - attron((attr_t) COLOR_PAIR(COLOR_GREEN)); + attron(COLOR_PAIR(COLOR_GREEN)); } #endif /* A_COLOR */ (void) addch((chtype) (hit ? SHOWHIT : SHOWSPLASH)); @@ -1133,16 +1134,16 @@ playagain(void) ++cpuwon; else ++plywon; - j = 18 + (int) strlen(name); + j = 18 + (int) strlen(your_name); if (plywon >= 10) ++j; if (cpuwon >= 10) ++j; MvPrintw(1, (COLWIDTH - j) / 2, - "%s: %d Computer: %d", name, plywon, cpuwon); + "%s: %d Computer: %d", your_name, plywon, cpuwon); prompt(2, (awinna())? "Want to be humiliated again, %s [yn]? " - : "Going to give me a chance for revenge, %s [yn]? ", name); + : "Going to give me a chance for revenge, %s [yn]? ", your_name); return (sgetc("YN") == 'Y'); }