X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fblue.c;h=922caab94396181e9c957a5b9ebe5421072329f4;hp=41b6f357d82820d3278ecb7ff5fc01596a848f34;hb=HEAD;hpb=e2e9c09c48b19b24979cafb2d4864f538b5ddd1c diff --git a/test/blue.c b/test/blue.c index 41b6f357..90f240b6 100644 --- a/test/blue.c +++ b/test/blue.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2013,2016 Free Software Foundation, Inc. * + * Copyright 2019-2021,2022 Thomas E. Dickey * + * Copyright 1998-2016,2017 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 * @@ -36,7 +37,7 @@ *****************************************************************************/ /* - * $Id: blue.c,v 1.46 2016/09/05 00:24:27 tom Exp $ + * $Id: blue.c,v 1.55 2022/12/10 23:31:31 tom Exp $ */ #include @@ -70,7 +71,7 @@ #define BLACK_ON_WHITE 2 #define BLUE_ON_WHITE 3 -static void die(int onsig) GCC_NORETURN; +static GCC_NORETURN void die(int onsig); static int deck_size = PACK_SIZE; /* initial deck */ static int deck[PACK_SIZE]; @@ -153,14 +154,14 @@ init_vars(void) static void shuffle(int size) { - int i, j, numswaps, swapnum, temp; + int numswaps, swapnum; numswaps = size * 10; /* an arbitrary figure */ for (swapnum = 0; swapnum < numswaps; swapnum++) { - i = rand() % size; - j = rand() % size; - temp = deck[i]; + int i = rand() % size; + int j = rand() % size; + int temp = deck[i]; deck[i] = deck[j]; deck[j] = temp; } @@ -169,11 +170,11 @@ shuffle(int size) static void deal_cards(void) { - int ptr, card = 0, value, csuit, crank, suit, aces[4]; + int card = 0, value, csuit, crank, suit, aces[4]; memset(aces, 0, sizeof(aces)); for (suit = HEARTS; suit <= CLUBS; suit++) { - ptr = freeptr[suit]; + int ptr = freeptr[suit]; grid[ptr++] = NOCARD; /* 1st card space is blank */ while ((ptr % GRID_WIDTH) != 0) { value = deck[card++]; @@ -196,20 +197,24 @@ deal_cards(void) static void printcard(int value) { - (void) addch(' '); + AddCh(' '); if (value == NOCARD) { (void) addstr(" "); } else { int which = (value / SUIT_LENGTH); int isuit = (value % SUIT_LENGTH); - attr_t color = (attr_t) COLOR_PAIR(((which % 2) == 0) + chtype color = (chtype) COLOR_PAIR(((which % 2) == 0) ? RED_ON_WHITE : BLACK_ON_WHITE); - addch(ranks[isuit][0] | (chtype) COLOR_PAIR(BLUE_ON_WHITE)); - addch(ranks[isuit][1] | (chtype) COLOR_PAIR(BLUE_ON_WHITE)); + AddCh(ranks[isuit][0] | (chtype) COLOR_PAIR(BLUE_ON_WHITE)); + AddCh(ranks[isuit][1] | (chtype) COLOR_PAIR(BLUE_ON_WHITE)); - attron(color); +#ifdef NCURSES_VERSION + (attron) ((int) color); /* quieter compiler warnings */ +#else + attron(color); /* PDCurses, etc., either no macro or wrong */ +#endif #if USE_WIDEC_SUPPORT { wchar_t values[2]; @@ -218,11 +223,15 @@ printcard(int value) addwstr(values); } #else - addch((chtype) suits[which]); + AddCh(suits[which]); #endif +#ifdef NCURSES_VERSION + (attroff) ((int) color); +#else attroff(color); +#endif } - (void) addch(' '); + AddCh(' '); } static void @@ -340,7 +349,7 @@ play_game(void) (void) addstr(buf); move(PROMPTROW, (int) strlen(buf)); clrtoeol(); - (void) addch(' '); + AddCh(' '); } while (((c = (char) getch()) < 'a' || c > 'd') && (c != 'r') @@ -380,10 +389,10 @@ play_game(void) static int collect_discards(void) { - int row, col, cardno = 0, finish, gridno; + int row, col, cardno = 0, gridno; for (row = HEARTS; row <= CLUBS; row++) { - finish = 0; + int finish = 0; for (col = 1; col < GRID_WIDTH; col++) { gridno = row * GRID_WIDTH + col; @@ -456,16 +465,49 @@ use_pc_display(void) #define use_pc_display() /* nothing */ #endif /* HAVE_LANGINFO_CODESET */ +static void +usage(int ok) +{ + static const char *msg[] = + { + "Usage: blue [options]" + ,"" + ,USAGE_COMMON + }; + size_t n; + + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); +} +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ + int main(int argc, char *argv[]) { - CATCHALL(die); + int ch; + + while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) { + switch (ch) { + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); + default: + usage(ch == OPTS_USAGE); + /* NOTREACHED */ + } + } + if (optind < argc) + usage(FALSE); setlocale(LC_ALL, ""); use_pc_display(); - initscr(); + InitAndCatch(initscr(), die); start_color(); init_pair(RED_ON_WHITE, COLOR_RED, COLOR_WHITE);