X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fblue.c;h=50d48b1d5b843c377c920c26bb3c8c165b59556b;hp=9cdb91259c997e8eb64ca3b0242d57915d5cadb0;hb=21c8ffa0edf2e389f3f674f0c08009002c6f357d;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/test/blue.c b/test/blue.c index 9cdb9125..50d48b1d 100644 --- a/test/blue.c +++ b/test/blue.c @@ -1,3 +1,30 @@ +/**************************************************************************** + * Copyright (c) 1998-2009,2013 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"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ /***************************************************************************** * * * B l u e M o o n * @@ -13,7 +40,7 @@ * results, use the ncurses(3) library. On non-Intel machines, SVr4 curses is * just as good. * - * $Id: blue.c,v 1.25 2005/05/28 21:38:03 tom Exp $ + * $Id: blue.c,v 1.35 2013/04/27 19:46:53 tom Exp $ */ #include @@ -43,7 +70,7 @@ #define BLACK_ON_WHITE 2 #define BLUE_ON_WHITE 3 -static RETSIGTYPE die(int onsig) GCC_NORETURN; +static void die(int onsig) GCC_NORETURN; static int deck_size = PACK_SIZE; /* initial deck */ static int deck[PACK_SIZE]; @@ -90,7 +117,7 @@ static chtype letters[4] = OR_COLORS('c', BLACK_ON_WHITE), /* clubs */ }; -#if defined(__i386__) +#if defined(__i386__) && defined(A_ALTCHARSET) && HAVE_TIGETSTR static chtype glyphs[] = { PC_COLORS('\003', RED_ON_WHITE), /* hearts */ @@ -98,11 +125,14 @@ static chtype glyphs[] = PC_COLORS('\004', RED_ON_WHITE), /* diamonds */ PC_COLORS('\005', BLACK_ON_WHITE), /* clubs */ }; +#define USE_CP437 1 +#else +#define USE_CP437 0 #endif /* __i386__ */ static chtype *suits = letters; /* this may change to glyphs below */ -static RETSIGTYPE +static void die(int onsig) { (void) signal(onsig, SIG_IGN); @@ -143,6 +173,7 @@ deal_cards(void) { int ptr, card = 0, value, csuit, crank, suit, aces[4]; + memset(aces, 0, sizeof(aces)); for (suit = HEARTS; suit <= CLUBS; suit++) { ptr = freeptr[suit]; grid[ptr++] = NOCARD; /* 1st card space is blank */ @@ -171,8 +202,8 @@ printcard(int value) if (value == NOCARD) (void) addstr(" "); else { - addch(ranks[value % SUIT_LENGTH][0] | COLOR_PAIR(BLUE_ON_WHITE)); - addch(ranks[value % SUIT_LENGTH][1] | COLOR_PAIR(BLUE_ON_WHITE)); + addch(ranks[value % SUIT_LENGTH][0] | (chtype) COLOR_PAIR(BLUE_ON_WHITE)); + addch(ranks[value % SUIT_LENGTH][1] | (chtype) COLOR_PAIR(BLUE_ON_WHITE)); addch(suits[value / SUIT_LENGTH]); } (void) addch(' '); @@ -269,7 +300,7 @@ play_game(void) if (selection[i] != NOCARD) { move(BASEROW + (selection[i] / GRID_WIDTH) * 2 + 3, (selection[i] % GRID_WIDTH) * 5); - (void) printw(" %c ", *lp++ = 'a' + i); + (void) printw(" %c ", (*lp++ = (char) ('a' + i))); } }; *lp = '\0'; @@ -295,7 +326,9 @@ play_game(void) clrtoeol(); (void) addch(' '); } while - (((c = getch()) < 'a' || c > 'd') && (c != 'r') && (c != 'q')); + (((c = (char) getch()) < 'a' || c > 'd') + && (c != 'r') + && (c != 'q')); } for (j = 0; j < 4; j++) @@ -322,9 +355,9 @@ play_game(void) } move(PROMPTROW, 0); - standout(); + (void) standout(); (void) printw("Finished deal %d - type any character to continue...", deal_number); - standend(); + (void) standend(); (void) getch(); } @@ -355,7 +388,7 @@ game_finished(int deal) { clear(); (void) printw("You finished the game in %d deals. This is ", deal); - standout(); + (void) standout(); if (deal < 2) (void) addstr("excellent"); else if (deal < 4) @@ -364,7 +397,7 @@ game_finished(int deal) (void) addstr("average"); else (void) addstr("poor"); - standend(); + (void) standend(); (void) addstr(". "); refresh(); } @@ -372,7 +405,7 @@ game_finished(int deal) int main(int argc, char *argv[]) { - (void) signal(SIGINT, die); + CATCHALL(die); setlocale(LC_ALL, ""); @@ -391,7 +424,7 @@ main(int argc, char *argv[]) letters[1] = OR_COLORS('s', BLACK_ON_WHITE); /* spades */ letters[2] = OR_COLORS('d', RED_ON_WHITE); /* diamonds */ letters[3] = OR_COLORS('c', BLACK_ON_WHITE); /* clubs */ -#if defined(__i386__) && defined(A_ALTCHARSET) +#if USE_CP437 glyphs[0] = PC_COLORS('\003', RED_ON_WHITE); /* hearts */ glyphs[1] = PC_COLORS('\006', BLACK_ON_WHITE); /* spades */ glyphs[2] = PC_COLORS('\004', RED_ON_WHITE); /* diamonds */ @@ -399,10 +432,10 @@ main(int argc, char *argv[]) #endif #endif -#if defined(__i386__) && defined(A_ALTCHARSET) +#if USE_CP437 if (tigetstr("smpch")) suits = glyphs; -#endif /* __i386__ && A_ALTCHARSET */ +#endif /* USE_CP437 */ cbreak();