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; }
const char * _nc_visbuf2(int bufnum, const char *buf) /* visibilize a given string */ { char *vbuf; char *tp; int c; if (buf == 0) return ("(null)"); if (buf == CANCELLED_STRING) return ("(cancelled)"); #ifdef TRACE tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5); #else { static char *mybuf[2]; mybuf[bufnum] = _nc_doalloc(mybuf[bufnum], (strlen(buf) * 4) + 5); tp = vbuf = mybuf[bufnum]; } #endif *tp++ = '"'; while ((c = *buf++) != '\0') { if (c == '"') { *tp++ = '\\'; *tp++ = '"'; } else if (is7bits(c) && (isgraph(c) || c == ' ')) { *tp++ = 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 (is7bits(c) && iscntrl(c)) { *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + c; } else { sprintf(tp, "\\%03o", c & 0xff); tp += strlen(tp); } } *tp++ = '"'; *tp++ = '\0'; return (vbuf); }
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; }
const char *_nc_visbuf2(int bufnum, const char *buf) /* visibilize a given string */ { char *vbuf; char *tp; int c; if (buf == 0) return("(null)"); tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5); *tp++ = '"'; while ((c = *buf++) != '\0') { if (c == '"') { *tp++ = '\\'; *tp++ = '"'; } else if (is7bits(c) && (isgraph(c) || c == ' ')) { *tp++ = 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 (is7bits(c) && iscntrl(c)) { *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + c; } else { sprintf(tp, "\\%03o", c & 0xff); tp += strlen(tp); } } *tp++ = '"'; *tp++ = '\0'; return(vbuf); }
wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) { int code = ERR; NCURSES_SIZE_T oy; NCURSES_SIZE_T ox; const wchar_t *cp; T((T_CALLED("wins_nwstr(%p,%s,%d)"), (void *) win, _nc_viswbufn(wstr, n), n)); if (win != 0 && wstr != 0) { if (n < 1) n = (int) wcslen(wstr); code = OK; if (n > 0) { SCREEN *sp = _nc_screen_of(win); oy = win->_cury; ox = win->_curx; for (cp = wstr; *cp && ((cp - wstr) < n); cp++) { int len = wcwidth(*cp); if ((len >= 0 && len != 1) || !is7bits(*cp)) { cchar_t tmp_cchar; wchar_t tmp_wchar = *cp; memset(&tmp_cchar, 0, sizeof(tmp_cchar)); (void) setcchar(&tmp_cchar, &tmp_wchar, WA_NORMAL, (short) 0, (void *) 0); code = _nc_insert_wch(win, &tmp_cchar); } else { /* tabs, other ASCII stuff */ code = _nc_insert_ch(sp, win, (chtype) (*cp)); } if (code != OK) break; } win->_curx = ox; win->_cury = oy; _nc_synchook(win); } } returnCode(code); }
static char * save_tc_char(char *bufptr, int c1) { char temp[80]; if (is7bits(c1) && isprint(c1)) { if (c1 == ':' || c1 == '\\') bufptr = save_char(bufptr, '\\'); bufptr = save_char(bufptr, c1); } else { if (c1 == (c1 & 0x1f)) /* iscntrl() returns T on 255 */ _nc_STRCPY(temp, unctrl((chtype) c1), sizeof(temp)); else _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "\\%03o", c1); bufptr = save_string(bufptr, temp); } return bufptr; }
wins_nwstr(WINDOW *win, const wchar_t * wstr, int n) { int code = ERR; NCURSES_SIZE_T oy; NCURSES_SIZE_T ox; const wchar_t *cp; T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr,n), n)); if (win != 0 && wstr != 0 && wcwidth(*wstr) > 0) { code = OK; if (n < 1) n = wcslen(wstr); oy = win->_cury; ox = win->_curx; for (cp = wstr; *cp && ((cp - wstr) < n); cp++) { NCURSES_CH_T wch; SetChar2(wch, *cp); if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') { _nc_waddch_nosync(win, wch); } else if (is7bits(*cp) && iscntrl(*cp)) { winsch(win, ' ' + (chtype) (*cp)); winsch(win, (chtype) '^'); win->_curx += 2; } else if (wins_wch(win, &wch) == ERR || win->_curx > win->_maxx) { break; } } win->_curx = ox; win->_cury = oy; _nc_synchook(win); code = OK; } returnCode(code); }
_nc_trans_string(char *ptr, char *last) { int count = 0; int number = 0; int i, c; chtype ch, last_ch = '\0'; bool ignored = FALSE; bool long_warning = FALSE; while ((ch = c = next_char()) != (chtype) separator && c != EOF) { if (ptr == (last - 1)) break; if ((_nc_syntax == SYN_TERMCAP) && c == '\n') break; if (ch == '^' && last_ch != '%') { ch = c = next_char(); if (c == EOF) _nc_err_abort("Premature EOF"); if (!(is7bits(ch) && isprint(ch))) { _nc_warning("Illegal ^ character - %s", unctrl(ch)); } if (ch == '?') { *(ptr++) = '\177'; if (_nc_tracing) _nc_warning("Allow ^? as synonym for \\177"); } else { if ((ch &= 037) == 0) ch = 128; *(ptr++) = (char) (ch); } } else if (ch == '\\') { ch = c = next_char(); if (c == EOF) _nc_err_abort("Premature EOF"); if (ch >= '0' && ch <= '7') { number = ch - '0'; for (i = 0; i < 2; i++) { ch = c = next_char(); if (c == EOF) _nc_err_abort("Premature EOF"); if (c < '0' || c > '7') { if (isdigit(c)) { _nc_warning("Non-octal digit `%c' in \\ sequence", c); /* allow the digit; it'll do less harm */ } else { push_back((char) c); break; } } number = number * 8 + c - '0'; } if (number == 0) number = 0200; *(ptr++) = (char) number; } else { switch (c) { case 'E': case 'e': *(ptr++) = '\033'; break; case 'a': *(ptr++) = '\007'; break; case 'l': case 'n': *(ptr++) = '\n'; break; case 'r': *(ptr++) = '\r'; break; case 'b': *(ptr++) = '\010'; break; case 's': *(ptr++) = ' '; break; case 'f': *(ptr++) = '\014'; break; case 't': *(ptr++) = '\t'; break; case '\\': *(ptr++) = '\\'; break; case '^': *(ptr++) = '^'; break; case ',': *(ptr++) = ','; break; case ':': *(ptr++) = ':'; break; case '\n': continue; default: _nc_warning("Illegal character %s in \\ sequence", unctrl(ch)); *(ptr++) = (char) ch; } /* endswitch (ch) */ } /* endelse (ch < '0' || ch > '7') */ } /* end else if (ch == '\\') */ else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) { /* newlines embedded in a terminfo string are ignored */ ignored = TRUE; } else { *(ptr++) = (char) ch; } if (!ignored) { last_ch = ch; count++; } ignored = FALSE; if (count > MAXCAPLEN && !long_warning) { _nc_warning("Very long string found. Missing separator?"); long_warning = TRUE; } } /* end while */ *ptr = '\0'; return (ch); }