+show_1_acs(int n, int repeat, const char *name, chtype code)
+{
+ const int height = 16;
+ int row = 2 + (n % height);
+ int col = (n / height) * COLS / 2;
+
+ MvPrintw(row, col, "%*s : ", COLS / 4, name);
+ do {
+ addch(code);
+ } while (--repeat > 0);
+ return n + 1;
+}
+
+static void
+show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+/* display the ACS character set */
+{
+ int n;
+
+#define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
+
+ erase();
+ attron(A_BOLD);
+ MvAddStr(0, 20, "Display of the ACS Character Set");
+ attroff(A_BOLD);
+ refresh();
+
+ n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
+ n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
+ n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
+ n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
+ n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
+ n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
+ n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
+ n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
+
+ /*
+ * HPUX's ACS definitions are broken here. Just give up.
+ */
+#if !(defined(__hpux) && !defined(NCURSES_VERSION))
+ n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
+ n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
+ n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
+ n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
+ n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
+ n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
+ n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
+ n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
+ n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
+ n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
+ n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
+ n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
+ n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
+ n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
+ n = show_1_acs(n, repeat, BOTH(ACS_PI));
+ n = show_1_acs(n, repeat, BOTH(ACS_S1));
+ n = show_1_acs(n, repeat, BOTH(ACS_S3));
+ n = show_1_acs(n, repeat, BOTH(ACS_S7));
+ (void) show_1_acs(n, repeat, BOTH(ACS_S9));
+#endif
+}
+
+static void
+acs_display(void)
+{
+ int c = 'a';
+ int pagesize = 32;
+ char *term = getenv("TERM");
+ const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
+ ? "p=PC, "
+ : "");
+ chtype attr = A_NORMAL;
+ int digit = 0;
+ int repeat = 1;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_BLACK;
+ unsigned at_code = 0;
+ NCURSES_PAIRS_T pair = 0;
+ void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
+ ATTR_TBL my_list[SIZEOF(attrs_to_test)];
+ unsigned my_size = init_attr_list(my_list, termattrs());
+
+ do {
+ switch (c) {
+ case CTRL('L'):
+ Repaint();
+ break;
+ case 'a':
+ ToggleAcs(last_show_acs, show_acs_chars);
+ break;
+ case 'p':
+ if (*pch_kludge)
+ ToggleAcs(last_show_acs, show_pc_chars);
+ else
+ beep();
+ break;
+ case 'w':
+ if (pagesize == 32) {
+ pagesize = 256;
+ } else {
+ pagesize = 32;
+ }
+ break;
+ case 'x':
+ ToggleAcs(last_show_acs, show_box_chars);
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ digit = (c - '0');
+ last_show_acs = 0;
+ break;
+ case '-':
+ if (digit > 0) {
+ --digit;
+ last_show_acs = 0;
+ } else {
+ beep();
+ }
+ break;
+ case '+':
+ if (digit < 3) {
+ ++digit;
+ last_show_acs = 0;
+ } else {
+ beep();
+ }
+ break;
+ case '>':
+ if (repeat < (COLS / 4))
+ ++repeat;
+ break;
+ case '<':
+ if (repeat > 1)
+ --repeat;
+ break;
+ default:
+ if (cycle_attr(c, &at_code, &attr, my_list, my_size)
+ || cycle_colors(c, &fg, &bg, &pair)) {
+ break;
+ } else {
+ beep();
+ }
+ break;
+ }
+ if (pagesize != 32) {
+ show_256_chars(repeat, attr, pair);
+ } else if (last_show_acs != 0) {
+ last_show_acs(repeat, attr, pair);
+ } else {
+ show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
+ }
+
+ MvPrintw(LINES - 3, 0,
+ "Note: ANSI terminals may not display C1 characters.");
+ MvPrintw(LINES - 2, 0,
+ "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
+ pch_kludge);
+ if (use_colors) {
+ MvPrintw(LINES - 1, 0,
+ "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
+ my_list[at_code].name,
+ fg, bg);
+ } else {
+ MvPrintw(LINES - 1, 0,
+ "v/V cycles through video attributes (%s).",
+ my_list[at_code].name);
+ }
+ refresh();
+ } while (!isQuit(c = Getchar()));
+
+ Pause();
+ erase();
+ endwin();
+}
+
+#if USE_WIDEC_SUPPORT
+static cchar_t *
+merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ int count;
+
+ *dst = *src;
+ do {
+ TEST_CCHAR(src, count, {
+ attr |= (test_attrs & A_ALTCHARSET);
+ setcchar(dst, test_wch, attr, pair, NULL);
+ }
+ , {
+ ;
+ });
+ } while (0);
+ return dst;
+}
+
+/*
+ * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
+ * display. If there are no repeats, we could normally display 16 lines of 64
+ * characters (1024 total). However, taking repeats and double-width cells
+ * into account, use 256 characters for the page.
+ */
+static void
+show_paged_widechars(int base,
+ int pagesize,
+ int repeat,
+ int space,
+ attr_t attr,
+ NCURSES_PAIRS_T pair)
+{
+ int first = base * pagesize;
+ int last = first + pagesize - 1;
+ int per_line = 16;
+ cchar_t temp;
+ wchar_t code;
+ wchar_t codes[10];
+
+ erase();
+ attron(A_BOLD);
+ MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
+ attroff(A_BOLD);
+
+ for (code = (wchar_t) first; (int) code <= last; code++) {
+ int row = (2 + ((int) code - first) / per_line);
+ int col = 5 * ((int) code % per_line);
+ int count;
+
+ memset(&codes, 0, sizeof(codes));
+ codes[0] = code;
+ setcchar(&temp, codes, attr, pair, 0);
+ move(row, col);
+ if (wcwidth(code) == 0 && code != 0) {
+ addch((chtype) space |
+ (A_REVERSE ^ attr) |
+ (attr_t) COLOR_PAIR(pair));
+ }
+ add_wch(&temp);
+ for (count = 1; count < repeat; ++count) {
+ add_wch(&temp);
+ }
+ }
+}
+
+static void
+show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ cchar_t temp;
+ wchar_t code;
+ int last = first + 31;
+
+ erase();
+ attron(A_BOLD);
+ MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
+ attroff(A_BOLD);
+
+ for (code = (wchar_t) first; (int) code <= last; code++) {
+ int row = 2 + ((code - first) % 16);
+ int col = ((code - first) / 16) * COLS / 2;
+ wchar_t codes[10];
+ char tmp[80];
+ int count = repeat;
+ int y, x;
+
+ sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
+ MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
+
+ memset(&codes, 0, sizeof(codes));
+ codes[0] = code;
+ setcchar(&temp, codes, attr, pair, 0);
+
+ do {
+ /*
+ * Give non-spacing characters something to combine with. If we
+ * don't, they'll bunch up in a heap on the space after the ":".
+ * Mark them with reverse-video to make them simpler to find on
+ * the display.
+ */
+ if (wcwidth(code) == 0) {
+ addch((chtype) space |
+ (A_REVERSE ^ attr) |
+ (attr_t) COLOR_PAIR(pair));
+ }
+ /*
+ * This uses echo_wchar(), for comparison with the normal 'f'
+ * test (and to make a test-case for echo_wchar()). The screen
+ * may flicker because the erase() at the top of the function
+ * is met by the builtin refresh() in echo_wchar().
+ */
+ echo_wchar(&temp);
+ /*
+ * The repeat-count may make text wrap - avoid that.
+ */
+ getyx(stdscr, y, x);
+ (void) y;
+ if (x >= col + (COLS / 2) - 2)
+ break;
+ } while (--count > 0);
+ }
+}
+
+static int
+show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)