X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdemo_new_pair.c;h=a4cbb5370dcbec8ba03fc7db13ba56dced2873c8;hp=1070c06ae2290ad91e5806b8eb0d2ad243cf5cb4;hb=119b5a6788c26bf7dcc99fcfd54e072946352a93;hpb=5e1e572b71ae31a6071daa24e2460a68a6f1003c;ds=sidebyside diff --git a/test/demo_new_pair.c b/test/demo_new_pair.c index 1070c06a..a4cbb537 100644 --- a/test/demo_new_pair.c +++ b/test/demo_new_pair.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2017 Free Software Foundation, Inc. * + * Copyright (c) 2017,2018 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 * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_new_pair.c,v 1.13 2017/04/15 17:36:00 tom Exp $ + * $Id: demo_new_pair.c,v 1.19 2018/05/12 14:30:04 tom Exp $ * * Demonstrate the alloc_pair() function. */ @@ -63,19 +63,19 @@ next_attr(int now) attr_t bits[MAX_BITS]; init = TRUE; - bits[limit++] = A_NORMAL; + bits[limit++] = WA_NORMAL; if (valid_cap("smso")) - bits[limit++] = A_STANDOUT; + bits[limit++] = WA_STANDOUT; if (valid_cap("smul")) - bits[limit++] = A_UNDERLINE; + bits[limit++] = WA_UNDERLINE; if (valid_cap("rev")) - bits[limit++] = A_REVERSE; + bits[limit++] = WA_REVERSE; if (valid_cap("blink")) - bits[limit++] = A_BLINK; + bits[limit++] = WA_BLINK; if (valid_cap("dim")) - bits[limit++] = A_DIM; + bits[limit++] = WA_DIM; if (valid_cap("bold")) - bits[limit++] = A_BOLD; + bits[limit++] = WA_BOLD; for (j = 0; j < limit; ++j) { for (k = 0; k < limit; ++k) { table[j * limit + k] = bits[j] | bits[k]; @@ -223,14 +223,17 @@ main(int argc, char *argv[]) if (isatty(fileno(stderr))) { output = stderr; - } else if ((ch = open("/dev/tty", O_WRONLY)) != 0) { + } else if ((ch = open("/dev/tty", O_WRONLY)) >= 0) { output = fdopen(ch, "w"); } else { fprintf(stderr, "cannot open terminal for output\n"); ExitProgram(EXIT_FAILURE); } - if (newterm(NULL, output, stdin) == 0) - usage(); + if (newterm(NULL, output, stdin) == 0) { + fprintf(stderr, "Cannot initialize terminal\n"); + fclose(output); + ExitProgram(EXIT_FAILURE); + } (void) cbreak(); /* read chars without wait for \n */ (void) noecho(); /* don't echo input */ update_modes(); @@ -320,7 +323,9 @@ main(int argc, char *argv[]) break; wch[0] = use_wide ? 0xff03 : '#'; wch[1] = 0; - setcchar(&temp, wch, my_attrs, (short) my_pair, NULL); + setcchar(&temp, wch, my_attrs, + (short) my_pair, + (use_init ? NULL : (void *) &my_pair)); /* * At the end of a page, move the cursor to the home position. */ @@ -331,7 +336,7 @@ main(int argc, char *argv[]) total_cells += 1 + (use_wide ? 1 : 0); ++current; } - endwin(); + exit_curses(); fclose(output); printf("%.1f cells/second\n",