wvline(WINDOW *win, chtype ch, int n) { int code = ERR; NCURSES_SIZE_T row, col; NCURSES_SIZE_T end; T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); if (win) { NCURSES_CH_T wch; row = win->_cury; col = win->_curx; end = row + n - 1; if (end > win->_maxy) end = win->_maxy; if (ch == 0) SetChar(wch, ChCharOf(ACS_VLINE), ChAttrOf(ACS_VLINE)); else SetChar(wch, ChCharOf(ch), ChAttrOf(ch)); wch = _nc_render(win, wch); while (end >= row) { struct ldat *line = &(win->_line[end]); line->text[col] = wch; CHANGED_CELL(line, col); end--; } _nc_synchook(win); code = OK; } returnCode(code); }
whline(WINDOW *win, chtype ch, int n) { int code = ERR; NCURSES_SIZE_T start; NCURSES_SIZE_T end; T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); if (win) { struct ldat *line = &(win->_line[win->_cury]); NCURSES_CH_T wch; start = win->_curx; end = start + n - 1; if (end > win->_maxx) end = win->_maxx; CHANGED_RANGE(line, start, end); if (ch == 0) SetChar(wch, ChCharOf(ACS_HLINE), ChAttrOf(ACS_HLINE)); else SetChar(wch, ChCharOf(ch), ChAttrOf(ch)); wch = _nc_render(win, wch); while (end >= start) { line->text[end] = wch; end--; } _nc_synchook(win); code = OK; } returnCode(code); }
static char * _nc_vischar(char *tp, unsigned c) { if (c == '"' || c == '\\') { *tp++ = '\\'; *tp++ = (char) c; } else if (is7bits(c) && (isgraph(c) || c == ' ')) { *tp++ = (char) c; } else if (c == '\n') { *tp++ = '\\'; *tp++ = 'n'; } else if (c == '\r') { *tp++ = '\\'; *tp++ = 'r'; } else if (c == '\b') { *tp++ = '\\'; *tp++ = 'b'; } else if (c == '\033') { *tp++ = '\\'; *tp++ = 'e'; } else if (UChar(c) == 0x7f) { *tp++ = '\\'; *tp++ = '^'; *tp++ = '?'; } else if (is7bits(c) && iscntrl(UChar(c))) { *tp++ = '\\'; *tp++ = '^'; *tp++ = (char) ('@' + c); } else { sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c)); tp += strlen(tp); } *tp = 0; return tp; }
_tracechtype2(int bufnum, chtype ch) { char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ); if (result != 0) { const char *found; attr_t attr = ChAttrOf(ch); _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum)); if ((found = _nc_altcharset_name(attr, ch)) != 0) { (void) _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; } else (void) _nc_trace_bufcat(bufnum, _nc_tracechar(CURRENT_SCREEN, (int) ChCharOf(ch))); if (attr != A_NORMAL) { (void) _nc_trace_bufcat(bufnum, " | "); (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } result = _nc_trace_bufcat(bufnum, r_brace); } return result; }
waddchnstr(WINDOW *win, const chtype *astr, int n) { NCURSES_SIZE_T y, x; int code = OK; int i; struct ldat *line; T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); if (!win) returnCode(ERR); y = win->_cury; x = win->_curx; if (n < 0) { const chtype *str; n = 0; for (str = (const chtype *) astr; *str != 0; str++) n++; } if (n > win->_maxx - x + 1) n = win->_maxx - x + 1; if (n == 0) returnCode(code); line = &(win->_line[y]); for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) { SetChar2(line->text[i + x], astr[i]); } CHANGED_RANGE(line, x, x + n - 1); _nc_synchook(win); returnCode(code); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static char * Only_Padding( | WINDOW *w, | int len, | int pad) | | Description : Test if 'length' cells starting at the current position | contain a padding character. | | Return Values : true if only padding cells are found +--------------------------------------------------------------------------*/ NCURSES_INLINE static bool Only_Padding(WINDOW *w, int len, int pad) { bool result = TRUE; int y, x, j; FIELD_CELL cell; getyx(w, y, x); for (j = 0; j < len; ++j) { if (wmove(w, y, x + j) != ERR) { #if USE_WIDEC_SUPPORT if (win_wch(w, &cell) != ERR) { if ((chtype)CharOf(cell) != ChCharOf(pad) || cell.chars[1] != 0) { result = FALSE; break; } } #else cell = winch(w); if (ChCharOf(cell) != ChCharOf(pad)) { result = FALSE; break; } #endif } else { /* if an error, return true: no non-padding text found */ break; } } /* no need to reset the cursor position; caller does this */ return result; }
static char * decode_chtype(char *source, chtype fillin, chtype *target) { attr_t attr = ChAttrOf(fillin); int color = PAIR_NUMBER((int) attr); int value; T(("decode_chtype '%s'", source)); source = decode_attr(source, &attr, &color); source = decode_char(source, &value); *target = (ChCharOf(value) | attr | (chtype) COLOR_PAIR(color)); /* FIXME - ignore combining characters */ return source; }
_tracechtype2(int bufnum, chtype ch) { const char *found; strcpy(_nc_trace_buf(bufnum, BUFSIZ), l_brace); if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { (void) _nc_trace_bufcat(bufnum, found); } else (void) _nc_trace_bufcat(bufnum, _tracechar((int)ChCharOf(ch))); if (ChAttrOf(ch) != A_NORMAL) { (void) _nc_trace_bufcat(bufnum, " | "); (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, ChAttrOf(ch))); } return (_nc_trace_bufcat(bufnum, r_brace)); }
static char * _nc_vischar(char *tp, unsigned c LIMIT_ARG) { if (c == '"' || c == '\\') { *tp++ = '\\'; *tp++ = (char) c; } else if (is7bits((int) c) && (isgraph((int) c) || c == ' ')) { *tp++ = (char) c; } else if (c == '\n') { *tp++ = '\\'; *tp++ = 'n'; } else if (c == '\r') { *tp++ = '\\'; *tp++ = 'r'; } else if (c == '\b') { *tp++ = '\\'; *tp++ = 'b'; } else if (c == '\t') { *tp++ = '\\'; *tp++ = 't'; } else if (c == '\033') { *tp++ = '\\'; *tp++ = 'e'; } else if (UChar(c) == 0x7f) { *tp++ = '\\'; *tp++ = '^'; *tp++ = '?'; } else if (is7bits(c) && iscntrl(UChar(c))) { *tp++ = '\\'; *tp++ = '^'; *tp++ = (char) ('@' + c); } else { _nc_SPRINTF(tp, _nc_SLIMIT(limit) "\\%03lo", (unsigned long) ChCharOf(c)); tp += strlen(tp); } *tp = 0; return tp; }
waddchnstr(WINDOW *win, const chtype *astr, int n) { NCURSES_SIZE_T y = win->_cury; NCURSES_SIZE_T x = win->_curx; int code = OK; struct ldat *line; T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); if (!win) returnCode(ERR); if (n < 0) { const chtype *str; n = 0; for (str = (const chtype *) astr; *str != 0; str++) n++; } if (n > win->_maxx - x + 1) n = win->_maxx - x + 1; if (n == 0) returnCode(code); line = &(win->_line[y]); #if USE_WIDEC_SUPPORT { int i; for (i = 0; i < n; ++i) SetChar(line->text[i + x], ChCharOf(astr[i]), ChAttrOf(astr[i])); } #else memcpy(line->text + x, astr, n * sizeof(*astr)); #endif CHANGED_RANGE(line, x, x + n - 1); _nc_synchook(win); returnCode(code); }
_tracechtype2(int bufnum, chtype ch) { const char *found; char *result = _nc_trace_buf(bufnum, BUFSIZ); if (result != 0) { strcpy(result, l_brace); if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { (void) _nc_trace_bufcat(bufnum, found); } else (void) _nc_trace_bufcat(bufnum, _nc_tracechar(CURRENT_SCREEN, (int) ChCharOf(ch))); if (ChAttrOf(ch) != A_NORMAL) { (void) _nc_trace_bufcat(bufnum, " | "); (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, ChAttrOf(ch))); } result = _nc_trace_bufcat(bufnum, r_brace); } return result; }
const char * _nc_altcharset_name(attr_t attr, chtype ch) { const char *result = 0; if ((attr & A_ALTCHARSET) && (acs_chars != 0)) { char *cp; char *found = 0; static const struct { unsigned int val; const char *name; } names[] = { /* *INDENT-OFF* */ { 'l', "ACS_ULCORNER" }, /* upper left corner */ { 'm', "ACS_LLCORNER" }, /* lower left corner */ { 'k', "ACS_URCORNER" }, /* upper right corner */ { 'j', "ACS_LRCORNER" }, /* lower right corner */ { 't', "ACS_LTEE" }, /* tee pointing right */ { 'u', "ACS_RTEE" }, /* tee pointing left */ { 'v', "ACS_BTEE" }, /* tee pointing up */ { 'w', "ACS_TTEE" }, /* tee pointing down */ { 'q', "ACS_HLINE" }, /* horizontal line */ { 'x', "ACS_VLINE" }, /* vertical line */ { 'n', "ACS_PLUS" }, /* large plus or crossover */ { 'o', "ACS_S1" }, /* scan line 1 */ { 's', "ACS_S9" }, /* scan line 9 */ { '`', "ACS_DIAMOND" }, /* diamond */ { 'a', "ACS_CKBOARD" }, /* checker board (stipple) */ { 'f', "ACS_DEGREE" }, /* degree symbol */ { 'g', "ACS_PLMINUS" }, /* plus/minus */ { '~', "ACS_BULLET" }, /* bullet */ { ',', "ACS_LARROW" }, /* arrow pointing left */ { '+', "ACS_RARROW" }, /* arrow pointing right */ { '.', "ACS_DARROW" }, /* arrow pointing down */ { '-', "ACS_UARROW" }, /* arrow pointing up */ { 'h', "ACS_BOARD" }, /* board of squares */ { 'i', "ACS_LANTERN" }, /* lantern symbol */ { '0', "ACS_BLOCK" }, /* solid square block */ { 'p', "ACS_S3" }, /* scan line 3 */ { 'r', "ACS_S7" }, /* scan line 7 */ { 'y', "ACS_LEQUAL" }, /* less/equal */ { 'z', "ACS_GEQUAL" }, /* greater/equal */ { '{', "ACS_PI" }, /* Pi */ { '|', "ACS_NEQUAL" }, /* not equal */ { '}', "ACS_STERLING" }, /* UK pound sign */ { '\0', (char *) 0 } /* *INDENT-OFF* */ }, *sp; for (cp = acs_chars; cp[0] && cp[1]; cp += 2) { if (ChCharOf(cp[1]) == ChCharOf(ch)) { found = cp; /* don't exit from loop - there may be redefinitions */ } } if (found != 0) { ch = ChCharOf(*found); for (sp = names; sp->val; sp++) if (sp->val == ch) { result = sp->name; break; } } } return result; }
_nc_init_acs(void) { chtype *fake_map = acs_map; chtype *real_map = SP != 0 ? SP->_acs_map : fake_map; int j; T(("initializing ACS map")); /* * If we're using this from curses (rather than terminfo), we are storing * the mapping information in the SCREEN struct so we can decide how to * render it. */ if (real_map != fake_map) { for (j = 1; j < ACS_LEN; ++j) { real_map[j] = 0; fake_map[j] = A_ALTCHARSET | j; SP->_screen_acs_map[j] = FALSE; } } else { for (j = 1; j < ACS_LEN; ++j) { real_map[j] = 0; } } /* * Initializations for a UNIX-like multi-terminal environment. Use * ASCII chars and count on the terminfo description to do better. */ real_map['l'] = '+'; /* should be upper left corner */ real_map['m'] = '+'; /* should be lower left corner */ real_map['k'] = '+'; /* should be upper right corner */ real_map['j'] = '+'; /* should be lower right corner */ real_map['u'] = '+'; /* should be tee pointing left */ real_map['t'] = '+'; /* should be tee pointing right */ real_map['v'] = '+'; /* should be tee pointing up */ real_map['w'] = '+'; /* should be tee pointing down */ real_map['q'] = '-'; /* should be horizontal line */ real_map['x'] = '|'; /* should be vertical line */ real_map['n'] = '+'; /* should be large plus or crossover */ real_map['o'] = '~'; /* should be scan line 1 */ real_map['s'] = '_'; /* should be scan line 9 */ real_map['`'] = '+'; /* should be diamond */ real_map['a'] = ':'; /* should be checker board (stipple) */ real_map['f'] = '\''; /* should be degree symbol */ real_map['g'] = '#'; /* should be plus/minus */ real_map['~'] = 'o'; /* should be bullet */ real_map[','] = '<'; /* should be arrow pointing left */ real_map['+'] = '>'; /* should be arrow pointing right */ real_map['.'] = 'v'; /* should be arrow pointing down */ real_map['-'] = '^'; /* should be arrow pointing up */ real_map['h'] = '#'; /* should be board of squares */ real_map['i'] = '#'; /* should be lantern symbol */ real_map['0'] = '#'; /* should be solid square block */ /* these defaults were invented for ncurses */ real_map['p'] = '-'; /* should be scan line 3 */ real_map['r'] = '-'; /* should be scan line 7 */ real_map['y'] = '<'; /* should be less-than-or-equal-to */ real_map['z'] = '>'; /* should be greater-than-or-equal-to */ real_map['{'] = '*'; /* should be greek pi */ real_map['|'] = '!'; /* should be not-equal */ real_map['}'] = 'f'; /* should be pound-sterling symbol */ #if !USE_WIDEC_SUPPORT if (_nc_unicode_locale() && _nc_locale_breaks_acs()) { acs_chars = NULL; ena_acs = NULL; enter_alt_charset_mode = NULL; exit_alt_charset_mode = NULL; set_attributes = NULL; } #endif if (ena_acs != NULL) { TPUTS_TRACE("ena_acs"); putp(ena_acs); } #if NCURSES_EXT_FUNCS /* * Linux console "supports" the "PC ROM" character set by the coincidence * that smpch/rmpch and smacs/rmacs have the same values. ncurses has * no codepage support (see SCO Merge for an example). Outside of the * values defined in acsc, there are no definitions for the "PC ROM" * character set (assumed by some applications to be codepage 437), but we * allow those applications to use those codepoints. * * test/blue.c uses this feature. */ #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b)) if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) && PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) { size_t i; for (i = 1; i < ACS_LEN; ++i) { if (real_map[i] == 0) { real_map[i] = i; if (real_map != fake_map) { if (SP != 0) SP->_screen_acs_map[i] = TRUE; } } } } #endif if (acs_chars != NULL) { size_t i = 0; size_t length = strlen(acs_chars); while (i + 1 < length) { if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) { real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET; if (SP != 0) SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE; } i += 2; } } #ifdef TRACE /* Show the equivalent mapping, noting if it does not match the * given attribute, whether by re-ordering or duplication. */ if (_nc_tracing & TRACE_CALLS) { size_t n, m; char show[ACS_LEN * 2 + 1]; for (n = 1, m = 0; n < ACS_LEN; n++) { if (real_map[n] != 0) { show[m++] = (char) n; show[m++] = ChCharOf(real_map[n]); } } show[m] = 0; if (acs_chars == NULL || strcmp(acs_chars, show)) _tracef("%s acs_chars %s", (acs_chars == NULL) ? "NULL" : "READ", _nc_visbuf(acs_chars)); _tracef("%s acs_chars %s", (acs_chars == NULL) ? "NULL" : (strcmp(acs_chars, show) ? "DIFF" : "SAME"), _nc_visbuf(show)); } #endif /* TRACE */ }
const char * _nc_altcharset_name(attr_t attr, chtype ch) { #define DATA(code, name) { code, { #name } } typedef struct { unsigned int val; const char name[13]; } ALT_NAMES; #if NCURSES_SP_FUNCS SCREEN *sp = CURRENT_SCREEN; #endif static const ALT_NAMES names[] = { DATA('l', ACS_ULCORNER), /* upper left corner */ DATA('m', ACS_LLCORNER), /* lower left corner */ DATA('k', ACS_URCORNER), /* upper right corner */ DATA('j', ACS_LRCORNER), /* lower right corner */ DATA('t', ACS_LTEE), /* tee pointing right */ DATA('u', ACS_RTEE), /* tee pointing left */ DATA('v', ACS_BTEE), /* tee pointing up */ DATA('w', ACS_TTEE), /* tee pointing down */ DATA('q', ACS_HLINE), /* horizontal line */ DATA('x', ACS_VLINE), /* vertical line */ DATA('n', ACS_PLUS), /* large plus or crossover */ DATA('o', ACS_S1), /* scan line 1 */ DATA('s', ACS_S9), /* scan line 9 */ DATA('`', ACS_DIAMOND), /* diamond */ DATA('a', ACS_CKBOARD), /* checker board (stipple) */ DATA('f', ACS_DEGREE), /* degree symbol */ DATA('g', ACS_PLMINUS), /* plus/minus */ DATA('~', ACS_BULLET), /* bullet */ DATA(',', ACS_LARROW), /* arrow pointing left */ DATA('+', ACS_RARROW), /* arrow pointing right */ DATA('.', ACS_DARROW), /* arrow pointing down */ DATA('-', ACS_UARROW), /* arrow pointing up */ DATA('h', ACS_BOARD), /* board of squares */ DATA('i', ACS_LANTERN), /* lantern symbol */ DATA('0', ACS_BLOCK), /* solid square block */ DATA('p', ACS_S3), /* scan line 3 */ DATA('r', ACS_S7), /* scan line 7 */ DATA('y', ACS_LEQUAL), /* less/equal */ DATA('z', ACS_GEQUAL), /* greater/equal */ DATA('{', ACS_PI), /* Pi */ DATA('|', ACS_NEQUAL), /* not equal */ DATA('}', ACS_STERLING), /* UK pound sign */ }; #undef DATA const char *result = 0; #if NCURSES_SP_FUNCS (void) sp; #endif if (SP_PARM != 0 && (attr & A_ALTCHARSET) && (acs_chars != 0)) { char *cp; char *found = 0; for (cp = acs_chars; cp[0] && cp[1]; cp += 2) { if (ChCharOf(UChar(cp[1])) == ChCharOf(ch)) { found = cp; /* don't exit from loop - there may be redefinitions */ } } if (found != 0) { size_t n; ch = ChCharOf(UChar(*found)); for (n = 0; n < SIZEOF(names); ++n) { if (names[n].val == ch) { result = names[n].name; break; } } } } return result; }