- /*
- * If the rendition is the same for the whole string, display it as a
- * quoted string, followed by the rendition. Otherwise, use the more
- * detailed trace function that displays each character separately.
- */
- if (same) {
- *tp++ = D_QUOTE;
- while (len-- > 0) {
- if ((found = _nc_altcharset_name(attr, CharOfD(buf))) != 0) {
- (void) strcpy(tp, found);
- tp += strlen(tp);
- attr &= ~A_ALTCHARSET;
- } else if (!isnac(CHDEREF(buf))) {
- PUTC_DATA;
-
- memset(&PUT_st, '\0', sizeof(PUT_st));
- PUTC_i = 0;
- do {
- PUTC_ch = PUTC_i < CCHARW_MAX ? buf->chars[PUTC_i] : L'\0';
- PUTC_n = wcrtomb(PUTC_buf, buf->chars[PUTC_i], &PUT_st);
- if (PUTC_ch == L'\0')
- --PUTC_n;
- if (PUTC_n <= 0)
- break;
- for (n = 0; n < PUTC_n; n++) {
- tp = _nc_vischar(tp, UChar(PUTC_buf[n]));
+ return _nc_viswbuf2(0, mybuf);
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+/* use these functions for displaying parts of a line within a window */
+NCURSES_EXPORT(const char *)
+_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
+{
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
+
+ if (result != 0) {
+ int first = 0;
+
+#if USE_WIDEC_SUPPORT
+ if (len < 0)
+ len = _nc_wchstrlen(buf);
+#endif /* USE_WIDEC_SUPPORT */
+
+ /*
+ * Display one or more strings followed by attributes.
+ */
+ while (first < len) {
+ attr_t attr = AttrOf(buf[first]);
+ int last = len - 1;
+ int j;
+
+ for (j = first + 1; j < len; ++j) {
+ if (!SameAttrOf(buf[j], buf[first])) {
+ last = j - 1;
+ break;
+ }
+ }
+
+ (void) _nc_trace_bufcat(bufnum, l_brace);
+ (void) _nc_trace_bufcat(bufnum, d_quote);
+ for (j = first; j <= last; ++j) {
+ const char *found = _nc_altcharset_name(attr, (chtype)
+ CharOf(buf[j]));
+ if (found != 0) {
+ (void) _nc_trace_bufcat(bufnum, found);
+ attr &= ~A_ALTCHARSET;
+ } else
+#if USE_WIDEC_SUPPORT
+ if (!isWidecExt(buf[j])) {
+ PUTC_DATA;
+
+ for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+ int k;
+ char temp[80];
+
+ PUTC_ch = buf[j].chars[PUTC_i];
+ if (PUTC_ch == L'\0') {
+ if (PUTC_i == 0)
+ (void) _nc_trace_bufcat(bufnum, "\\000");
+ break;
+ }
+ PUTC_INIT;
+ PUTC_n = (int) wcrtomb(PUTC_buf,
+ buf[j].chars[PUTC_i], &PUT_st);
+ if (PUTC_n <= 0 || buf[j].chars[PUTC_i] > 255) {
+ sprintf(temp, "{%d:\\u%x}",
+ wcwidth(buf[j].chars[PUTC_i]),
+ buf[j].chars[PUTC_i]);
+ (void) _nc_trace_bufcat(bufnum, temp);
+ break;
+ }
+ for (k = 0; k < PUTC_n; k++) {
+ VisChar(temp, UChar(PUTC_buf[k]), sizeof(temp));
+ (void) _nc_trace_bufcat(bufnum, temp);
+ }