X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fdemo_new_pair.c;h=ac0d9bf3362de6a37a5a6980afc0b66bc0d5de31;hb=95b3f94ec8b2da797e3e9a18fb49320daa5ab221;hp=aef725a0d5e5f1deb8f6660c109650ea32614e9c;hpb=90d42867e1296bc79021006a92032c76e59068b6;p=ncurses.git diff --git a/test/demo_new_pair.c b/test/demo_new_pair.c index aef725a0..ac0d9bf3 100644 --- a/test/demo_new_pair.c +++ b/test/demo_new_pair.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 2017 Free Software Foundation, Inc. * + * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 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 * @@ -26,16 +27,21 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_new_pair.c,v 1.10 2017/03/10 09:47:15 tom Exp $ + * $Id: demo_new_pair.c,v 1.24 2021/02/21 01:24:06 tom Exp $ * * Demonstrate the alloc_pair() function. */ #include #include +#include #if HAVE_ALLOC_PAIR && USE_WIDEC_SUPPORT +#include +#include +#include + #define MAX_BITS 8 /* all but A_ALTCHARSET */ #define MAX_ATTR ((1<= 0) { + output = fdopen(ch, "w"); + } else { + fprintf(stderr, "cannot open terminal for output\n"); + ExitProgram(EXIT_FAILURE); + } + 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(); @@ -259,8 +264,8 @@ main(int argc, char *argv[]) int my_pair; switch (getch()) { - case '?': - show_help(help); + case HELP_KEY_1: + popup_msg(stdscr, help); break; case 'p': /* step-by-page */ @@ -324,7 +329,42 @@ 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)); + + if (check_set) { + int problem = 0; + wchar_t chk_wch[2]; + attr_t chk_attrs = 0; + short chk_pair = 0; + int chk_pair2 = 0; + +#define AllButColor(a) ((a) & (A_ATTRIBUTES & ~A_COLOR)) + + if (getcchar(&temp, NULL, &chk_attrs, &chk_pair, + (use_init ? NULL : (void *) &chk_pair2)) != 2) { + problem = 1; + } else if (getcchar(&temp, chk_wch, &chk_attrs, &chk_pair, + (use_init ? NULL : (void *) &chk_pair2)) != OK) { + problem = 2; + } else if (chk_wch[0] != wch[0]) { + problem = 3; + } else if (AllButColor(my_attrs) != AllButColor(chk_attrs)) { + problem = 4; + } else if (my_pair != chk_pair) { + problem = 4; + } else if (!use_init && (my_pair != chk_pair2)) { + problem = 5; + } + if (problem) { + wch[0] = (wchar_t) (problem + '0'); + 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. */ @@ -335,7 +375,8 @@ main(int argc, char *argv[]) total_cells += 1 + (use_wide ? 1 : 0); ++current; } - endwin(); + stop_curses(); + fclose(output); printf("%.1f cells/second\n", (double) (total_cells) / (double) (now() - start));