X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fxmas.c;h=79a56a58483265ee1f809b069261fc9581b2da95;hp=2ea08aef0307581faa49a2831b89064752561f00;hb=8fc9fa113b27e0749e0840fef04c9d4acad4aae7;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/test/xmas.c b/test/xmas.c index 2ea08aef..79a56a58 100644 --- a/test/xmas.c +++ b/test/xmas.c @@ -92,7 +92,7 @@ /******************************************************************************/ /* - * $Id: xmas.c,v 1.20 2005/04/16 16:34:38 tom Exp $ + * $Id: xmas.c,v 1.25 2009/08/29 18:47:26 tom Exp $ */ #include @@ -131,6 +131,7 @@ static WINDOW *lookdeer3; static WINDOW *lookdeer4; static WINDOW *w_holiday; static WINDOW *w_del_msg; +static bool *my_pairs; static int boxit(void); static int seas(void); @@ -153,13 +154,12 @@ static void set_color(WINDOW *win, chtype color) { if (has_colors()) { - static bool *pairs; int n = (color + 1); - if (pairs == 0) - pairs = (bool *) calloc((unsigned) (COLORS + 1), sizeof(bool)); - if (!pairs[n]) { + if (my_pairs == 0) + my_pairs = typeCalloc(bool, COLORS + 1); + if (!my_pairs[n]) { init_pair(n, color, my_bg); - pairs[n] = TRUE; + my_pairs[n] = TRUE; } wattroff(win, A_COLOR); wattron(win, COLOR_PAIR(n)); @@ -170,7 +170,7 @@ static void unset_color(WINDOW *win) { if (has_colors()) - wattrset(win, COLOR_PAIR(0)); + (void) wattrset(win, COLOR_PAIR(0)); } static void @@ -194,12 +194,9 @@ main(int argc GCC_UNUSED, char **argv GCC_UNUSED) noecho(); nonl(); refresh(); - signal(SIGINT, done); - signal(SIGTERM, done); -#if !defined DOS && !defined OS2 - signal(SIGHUP, done); - signal(SIGQUIT, done); -#endif + + CATCHALL(done); + if (has_colors()) { start_color(); #if HAVE_USE_DEFAULT_COLORS @@ -209,44 +206,48 @@ main(int argc GCC_UNUSED, char **argv GCC_UNUSED) } curs_set(0); - treescrn = newwin(16, 27, 3, 53); - treescrn2 = newwin(16, 27, 3, 53); - treescrn3 = newwin(16, 27, 3, 53); - treescrn4 = newwin(16, 27, 3, 53); - treescrn5 = newwin(16, 27, 3, 53); - treescrn6 = newwin(16, 27, 3, 53); - treescrn7 = newwin(16, 27, 3, 53); - treescrn8 = newwin(16, 27, 3, 53); - - dotdeer0 = newwin(3, 71, 0, 8); - - stardeer0 = newwin(4, 56, 0, 8); - - lildeer0 = newwin(7, 53, 0, 8); - lildeer1 = newwin(2, 4, 0, 0); - lildeer2 = newwin(2, 4, 0, 0); - lildeer3 = newwin(2, 4, 0, 0); - - middeer0 = newwin(15, 42, 0, 8); - middeer1 = newwin(3, 7, 0, 0); - middeer2 = newwin(3, 7, 0, 0); - middeer3 = newwin(3, 7, 0, 0); - - bigdeer0 = newwin(10, 23, 0, 0); - bigdeer1 = newwin(10, 23, 0, 0); - bigdeer2 = newwin(10, 23, 0, 0); - bigdeer3 = newwin(10, 23, 0, 0); - bigdeer4 = newwin(10, 23, 0, 0); - - lookdeer0 = newwin(10, 25, 0, 0); - lookdeer1 = newwin(10, 25, 0, 0); - lookdeer2 = newwin(10, 25, 0, 0); - lookdeer3 = newwin(10, 25, 0, 0); - lookdeer4 = newwin(10, 25, 0, 0); - - w_holiday = newwin(1, 26, 3, 27); - - w_del_msg = newwin(1, 19, 23, 60); + if ((treescrn = newwin(16, 27, 3, 53)) == 0 || + (treescrn2 = newwin(16, 27, 3, 53)) == 0 || + (treescrn3 = newwin(16, 27, 3, 53)) == 0 || + (treescrn4 = newwin(16, 27, 3, 53)) == 0 || + (treescrn5 = newwin(16, 27, 3, 53)) == 0 || + (treescrn6 = newwin(16, 27, 3, 53)) == 0 || + (treescrn7 = newwin(16, 27, 3, 53)) == 0 || + (treescrn8 = newwin(16, 27, 3, 53)) == 0 || + + (dotdeer0 = newwin(3, 71, 0, 8)) == 0 || + + (stardeer0 = newwin(4, 56, 0, 8)) == 0 || + + (lildeer0 = newwin(7, 53, 0, 8)) == 0 || + (lildeer1 = newwin(2, 4, 0, 0)) == 0 || + (lildeer2 = newwin(2, 4, 0, 0)) == 0 || + (lildeer3 = newwin(2, 4, 0, 0)) == 0 || + + (middeer0 = newwin(15, 42, 0, 8)) == 0 || + (middeer1 = newwin(3, 7, 0, 0)) == 0 || + (middeer2 = newwin(3, 7, 0, 0)) == 0 || + (middeer3 = newwin(3, 7, 0, 0)) == 0 || + + (bigdeer0 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer1 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer2 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer3 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer4 = newwin(10, 23, 0, 0)) == 0 || + + (lookdeer0 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer1 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer2 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer3 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer4 = newwin(10, 25, 0, 0)) == 0 || + + (w_holiday = newwin(1, 26, 3, 27)) == 0 || + + (w_del_msg = newwin(1, 19, 23, 60)) == 0) { + endwin(); + fprintf(stderr, "Cannot create windows - screen too small\n"); + ExitProgram(EXIT_FAILURE); + } mvwaddstr(w_del_msg, 0, 0, "Hit any key to quit"); @@ -532,9 +533,9 @@ main(int argc GCC_UNUSED, char **argv GCC_UNUSED) mvwaddch(treescrn4, 12, 23, ' '); /*star */ - wstandout(treescrn4); + (void) wstandout(treescrn4); mvwaddch(treescrn4, 0, 12, '*'); - wstandend(treescrn4); + (void) wstandend(treescrn4); /*strng1 */ mvwaddch(treescrn4, 3, 13, ' '); @@ -596,9 +597,9 @@ main(int argc GCC_UNUSED, char **argv GCC_UNUSED) mvwaddch(treescrn6, 11, 23, ' '); /*star */ - wstandout(treescrn6); + (void) wstandout(treescrn6); mvwaddch(treescrn6, 0, 12, '*'); - wstandend(treescrn6); + (void) wstandend(treescrn6); /*strng1 */ @@ -815,11 +816,11 @@ balls(void) static int star(void) { - wattrset(treescrn2, A_BOLD | A_BLINK); + (void) wattrset(treescrn2, A_BOLD | A_BLINK); set_color(treescrn2, COLOR_YELLOW); mvwaddch(treescrn2, 0, 12, (chtype) '*'); - wstandend(treescrn2); + (void) wstandend(treescrn2); unset_color(treescrn2); wrefresh(treescrn2); @@ -830,7 +831,7 @@ star(void) static int strng1(void) { - wattrset(treescrn2, A_BOLD | A_BLINK); + (void) wattrset(treescrn2, A_BOLD | A_BLINK); set_color(treescrn2, COLOR_WHITE); mvwaddch(treescrn2, 3, 13, (chtype) '\''); @@ -848,7 +849,7 @@ strng1(void) static int strng2(void) { - wattrset(treescrn2, A_BOLD | A_BLINK); + (void) wattrset(treescrn2, A_BOLD | A_BLINK); set_color(treescrn2, COLOR_WHITE); mvwaddch(treescrn2, 5, 14, (chtype) '\''); @@ -869,7 +870,7 @@ strng2(void) static int strng3(void) { - wattrset(treescrn2, A_BOLD | A_BLINK); + (void) wattrset(treescrn2, A_BOLD | A_BLINK); set_color(treescrn2, COLOR_WHITE); mvwaddch(treescrn2, 7, 16, (chtype) '\''); @@ -892,7 +893,7 @@ strng3(void) static int strng4(void) { - wattrset(treescrn2, A_BOLD | A_BLINK); + (void) wattrset(treescrn2, A_BOLD | A_BLINK); set_color(treescrn2, COLOR_WHITE); mvwaddch(treescrn2, 9, 17, (chtype) '\''); @@ -920,7 +921,7 @@ strng4(void) static int strng5(void) { - wattrset(treescrn2, A_BOLD | A_BLINK); + (void) wattrset(treescrn2, A_BOLD | A_BLINK); set_color(treescrn2, COLOR_WHITE); mvwaddch(treescrn2, 11, 19, (chtype) '\''); @@ -1145,15 +1146,17 @@ reindeer(void) static RETSIGTYPE done(int sig GCC_UNUSED) { - signal(SIGINT, done); - signal(SIGTERM, done); -#if !defined DOS && !defined OS2 - signal(SIGHUP, done); - signal(SIGQUIT, done); -#endif + CATCHALL(done); + move(LINES - 1, 0); refresh(); endwin(); curs_set(1); + +#if NO_LEAKS + if (my_pairs != 0) + free(my_pairs); +#endif + ExitProgram(EXIT_SUCCESS); }