X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftrace%2Fvisbuf.c;h=5f95a6bc50c054117a5e1f5cbdd3c8859d347bd0;hp=fec06439c35a06700b7af87da6719bff2fed80f2;hb=e5d1530ca229aef94a3c84ad33f8ae89f35c4045;hpb=a8845f1feadb0b4d906e9040e465b93fd3f72660 diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c index fec06439..5f95a6bc 100644 --- a/ncurses/trace/visbuf.c +++ b/ncurses/trace/visbuf.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 2001-2012,2014 Free Software Foundation, Inc. * + * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2001-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +43,7 @@ #include #include -MODULE_ID("$Id: visbuf.c,v 1.44 2014/09/25 08:51:13 tom Exp $") +MODULE_ID("$Id: visbuf.c,v 1.52 2020/02/02 23:34:34 tom Exp $") #define NUM_VISBUFS 4 @@ -80,6 +81,9 @@ _nc_vischar(char *tp, unsigned c LIMIT_ARG) } else if (c == '\b') { *tp++ = '\\'; *tp++ = 'b'; + } else if (c == '\t') { + *tp++ = '\\'; + *tp++ = 't'; } else if (c == '\033') { *tp++ = '\\'; *tp++ = 'e'; @@ -105,7 +109,6 @@ _nc_visbuf2n(int bufnum, const char *buf, int len) { const char *vbuf = 0; char *tp; - int c; int count; if (buf == 0) @@ -122,6 +125,8 @@ _nc_visbuf2n(int bufnum, const char *buf, int len) #else { static char *mybuf[NUM_VISBUFS]; + int c; + if (bufnum < 0) { for (c = 0; c < NUM_VISBUFS; ++c) { FreeAndNull(mybuf[c]); @@ -134,6 +139,8 @@ _nc_visbuf2n(int bufnum, const char *buf, int len) } #endif if (tp != 0) { + int c; + *tp++ = D_QUOTE; while ((--count >= 0) && (c = *buf++) != '\0') { tp = VisChar(tp, UChar(c), NormalLen(len)); @@ -185,7 +192,6 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) { const char *vbuf; char *tp; - wchar_t c; int count; if (buf == 0) @@ -205,6 +211,8 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) } #endif if (tp != 0) { + wchar_t c; + *tp++ = D_QUOTE; while ((--count >= 0) && (c = *buf++) != '\0') { char temp[CCHARW_MAX + 80]; @@ -278,10 +286,10 @@ NCURSES_EXPORT(const char *) _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) { char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ); - int first; - const char *found; if (result != 0) { + int first = 0; + #if USE_WIDEC_SUPPORT if (len < 0) len = _nc_wchstrlen(buf); @@ -290,7 +298,6 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) /* * Display one or more strings followed by attributes. */ - first = 0; while (first < len) { attr_t attr = AttrOf(buf[first]); int last = len - 1; @@ -306,7 +313,8 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) (void) _nc_trace_bufcat(bufnum, l_brace); (void) _nc_trace_bufcat(bufnum, d_quote); for (j = first; j <= last; ++j) { - found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j])); + const char *found = _nc_altcharset_name(attr, (chtype) + CharOf(buf[j])); if (found != 0) { (void) _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; @@ -315,9 +323,9 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) if (!isWidecExt(buf[j])) { PUTC_DATA; - PUTC_INIT; 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') { @@ -325,12 +333,18 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) (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) + if (PUTC_n <= 0 || buf[j].chars[PUTC_i] > 255) { + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "{%d:\\u%lx}", + _nc_wacs_width(buf[j].chars[PUTC_i]), + (unsigned long) buf[j].chars[PUTC_i]); + (void) _nc_trace_bufcat(bufnum, temp); break; + } for (k = 0; k < PUTC_n; k++) { - char temp[80]; VisChar(temp, UChar(PUTC_buf[k]), sizeof(temp)); (void) _nc_trace_bufcat(bufnum, temp); }