X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fncurses.c;h=345eadebfdbca6ff922cadcfc61a79d637a976e7;hb=acc28c6418f43cbf15187f2f1fd9a562d5d96535;hp=bf874677b8ff4a9c1214021db282aca212a31c41;hpb=1bab6fd2bd6c65560d26b46b0a245bd7d46f2add;p=ncurses.git diff --git a/test/ncurses.c b/test/ncurses.c index bf874677..345eadeb 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.408 2014/06/28 21:45:40 tom Exp $ +$Id: ncurses.c,v 1.415 2014/08/09 22:28:42 tom Exp $ ***************************************************************************/ @@ -305,7 +305,7 @@ wGetstring(WINDOW *win, char *buffer, int limit) static wchar_t fullwidth_digit(int ch) { - return (ch + 0xff10 - '0'); + return (wchar_t) (ch + 0xff10 - '0'); } static void @@ -323,7 +323,7 @@ make_narrow_text(wchar_t *target, const char *source) { int ch; while ((ch = *source++) != 0) { - *target++ = ch; + *target++ = (wchar_t) ch; } *target = 0; } @@ -1292,6 +1292,10 @@ attr_legend(WINDOW *helpwin) " a/A toggle ACS (alternate character set) mapping"); MvWPrintw(helpwin, row, col, " v/V toggle video attribute to combine with each line"); +#if USE_WIDEC_SUPPORT + MvWPrintw(helpwin, row, col, + " w/W toggle normal/wide (double-width) test-characters"); +#endif } static void @@ -1422,6 +1426,7 @@ show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *n * string operation for the other attributes. */ wmove(win, 0, 0); + werase(win); if (attr & A_ALTCHARSET) { const char *s; chtype ch; @@ -1431,9 +1436,9 @@ show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *n (void) waddch(win, ch | attr); } } else { - (void) wattrset(win, attr); + (void) wattrset(win, AttrArg(attr, 0)); (void) waddstr(win, attr_test_string); - (void) wattroff(win, attr); + (void) wattroff(win, (int) attr); } if (skip) printw("%*s", skip, " "); @@ -1673,20 +1678,59 @@ attr_test(void) } #if USE_WIDEC_SUPPORT +static bool use_fullwidth; static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1]; +#define FULL_LO 0xff00 +#define FULL_HI 0xff5e +#define HALF_LO 0x20 + +#define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI) +#define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO) +#define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO) + +/* + * Returns an ASCII code in [32..126] + */ +static wchar_t +normal_wchar(int ch) +{ + wchar_t result = (wchar_t) ch; + if (isFullWidth(ch)) + result = ToNormalWidth(ch); + return result; +} + +/* + * Returns either an ASCII code in in [32..126] or full-width in + * [0xff00..0xff5e], according to use_fullwidth setting. + */ +static wchar_t +target_wchar(int ch) +{ + wchar_t result = (wchar_t) ch; + if (use_fullwidth) { + if (!isFullWidth(ch)) + result = ToFullWidth(ch); + } else { + if (isFullWidth(ch)) + result = ToNormalWidth(ch); + } + return result; +} + static void wide_adjust_attr_string(int adjust) { - char save = (char) wide_attr_test_string[0]; - int first = ((int) UChar(save)) + adjust; + wchar_t save = wide_attr_test_string[0]; + int first = ((int) normal_wchar(save)) + adjust; int j, k; if (first >= ATTRSTRING_1ST) { for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) { if (k > ATTRSTRING_END) break; - wide_attr_test_string[j] = k; + wide_attr_test_string[j] = target_wchar(k); if (((k + 1 - first) % 5) == 0) { if (++j >= MAX_ATTRSTRING) break; @@ -1707,7 +1751,8 @@ wide_adjust_attr_string(int adjust) static void wide_init_attr_string(void) { - wide_attr_test_string[0] = default_attr_string(); + use_fullwidth = FALSE; + wide_attr_test_string[0] = (wchar_t) default_attr_string(); wide_adjust_attr_string(0); } @@ -1767,6 +1812,7 @@ wide_show_attr(WINDOW *win, * string operation for the other attributes. */ wmove(win, 0, 0); + werase(win); if (attr & WA_ALTCHARSET) { const wchar_t *s; cchar_t ch; @@ -1872,6 +1918,14 @@ wide_attr_getc(int *skip, if (*kc >= limit) *kc = 0; break; + case 'w': + use_fullwidth = FALSE; + wide_adjust_attr_string(0); + break; + case 'W': + use_fullwidth = TRUE; + wide_adjust_attr_string(0); + break; case '<': wide_adjust_attr_string(-1); break; @@ -2181,13 +2235,13 @@ color_test(void) NCURSES_COLOR_T bg = InxToBG(i); init_pair(pair, fg, bg); - attron((attr_t) COLOR_PAIR(pair)); + attron(COLOR_PAIR(pair)); if (opt_acsc) - attron((attr_t) A_ALTCHARSET); + attron(A_ALTCHARSET); if (opt_bold) - attron((attr_t) A_BOLD); + attron(A_BOLD); if (opt_revs) - attron((attr_t) A_REVERSE); + attron(A_REVERSE); if (opt_nums) { sprintf(numbered, "{%02X}", (int) i); @@ -2392,11 +2446,11 @@ wide_color_test(void) init_pair(pair, InxToFG(i), InxToBG(i)); (void) color_set(pair, NULL); if (opt_acsc) - attr_on((attr_t) A_ALTCHARSET, NULL); + attr_on(A_ALTCHARSET, NULL); if (opt_bold) - attr_on((attr_t) A_BOLD, NULL); + attr_on(A_BOLD, NULL); if (opt_revs) - attr_on((attr_t) A_REVERSE, NULL); + attr_on(A_REVERSE, NULL); if (opt_nums) { sprintf(numbered, "{%02X}", i); @@ -2597,7 +2651,7 @@ color_edit(void) (i == current ? '>' : ' '), (i < (int) SIZEOF(the_color_names) ? the_color_names[i] : numeric)); - (void) attrset((attr_t) COLOR_PAIR(i)); + (void) attrset(AttrArg(COLOR_PAIR(i), 0)); addstr(" "); (void) attrset(A_NORMAL); @@ -3555,7 +3609,7 @@ show_paged_widechars(int base, MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last); attroff(A_BOLD); - for (code = first; (int) code <= last; code++) { + 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; @@ -3588,7 +3642,7 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIR MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last); attroff(A_BOLD); - for (code = first; (int) code <= last; code++) { + 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]; @@ -6353,11 +6407,11 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col) break; case 2: init_pair(cpair, COLOR_BLUE, COLOR_WHITE); - (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL)); + (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL)); break; case 3: init_pair(cpair, COLOR_WHITE, COLOR_BLUE); - (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD)); + (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD)); break; } } @@ -6780,7 +6834,9 @@ usage(void) ," -a f,b set default-colors (assumed white-on-black)" ," -d use default-colors if terminal supports them" #endif +#if HAVE_USE_ENV ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS" +#endif #if USE_SOFTKEYS ," -e fmt specify format for soft-keys test (e)" #endif @@ -7000,9 +7056,11 @@ main(int argc, char *argv[]) default_colors = TRUE; break; #endif +#if HAVE_USE_ENV case 'E': use_env(FALSE); break; +#endif case 'e': my_e_param = atoi(optarg); #ifdef NCURSES_VERSION