36
36
* visbuf.c - Tracing/Debugging support routines
39
#define NEED_NCURSES_CH_T
39
40
#include <curses.priv.h>
44
MODULE_ID("$Id: visbuf.c,v 1.14 2005/08/20 20:01:20 tom Exp $")
45
MODULE_ID("$Id: visbuf.c,v 1.21 2006/12/02 21:20:28 tom Exp $")
47
static const char d_quote[] = {D_QUOTE, 0};
48
static const char l_brace[] = {L_BRACE, 0};
49
static const char r_brace[] = {R_BRACE, 0};
47
52
_nc_vischar(char *tp, unsigned c)
221
226
return _nc_viswbuf2(0, mybuf);
228
#endif /* USE_WIDEC_SUPPORT */
230
/* use these functions for displaying parts of a line within a window */
224
231
NCURSES_EXPORT(const char *)
225
_nc_viscbuf2(int bufnum, const cchar_t *buf, int len)
232
_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
227
234
char *result = _nc_trace_buf(bufnum, BUFSIZ);
230
attr_t attr = A_NORMAL;
231
236
const char *found;
238
#if USE_WIDEC_SUPPORT
234
240
len = _nc_wchstrlen(buf);
236
for (n = 1; n < len; n++) {
237
if (!SameAttrOf(buf[n], buf[0])) {
241
#endif /* USE_WIDEC_SUPPORT */
244
* If the rendition is the same for the whole string, display it as a
245
* quoted string, followed by the rendition. Otherwise, use the more
246
* detailed trace function that displays each character separately.
244
* Display one or more strings followed by attributes.
249
static const char d_quote[] =
247
while (first < len) {
248
attr_t attr = AttrOf(buf[first]);
252
for (j = first + 1; j < len; ++j) {
253
if (!SameAttrOf(buf[j], buf[first])) {
259
result = _nc_trace_bufcat(bufnum, l_brace);
252
260
result = _nc_trace_bufcat(bufnum, d_quote);
254
if ((found = _nc_altcharset_name(attr, CharOfD(buf))) != 0) {
261
for (j = first; j <= last; ++j) {
262
if ((found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j]))) != 0) {
255
263
result = _nc_trace_bufcat(bufnum, found);
256
264
attr &= ~A_ALTCHARSET;
257
} else if (!isWidecExt(CHDEREF(buf))) {
266
#if USE_WIDEC_SUPPORT
267
if (!isWidecExt(buf[j])) {
262
PUTC_ch = PUTC_i < CCHARW_MAX ? buf->chars[PUTC_i] : L'\0';
263
PUTC_n = wcrtomb(PUTC_buf, buf->chars[PUTC_i], &PUT_st);
271
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
274
PUTC_ch = buf[j].chars[PUTC_i];
264
275
if (PUTC_ch == L'\0')
277
PUTC_n = wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st);
268
for (n = 0; n < PUTC_n; n++) {
280
for (k = 0; k < PUTC_n; k++) {
270
_nc_vischar(temp, UChar(PUTC_buf[n]));
282
_nc_vischar(temp, UChar(PUTC_buf[k]));
271
283
result = _nc_trace_bufcat(bufnum, temp);
274
} while (PUTC_ch != L'\0');
290
_nc_vischar(temp, UChar(buf[j]));
291
result = _nc_trace_bufcat(bufnum, temp);
293
#endif /* USE_WIDEC_SUPPORT */
278
295
result = _nc_trace_bufcat(bufnum, d_quote);
279
296
if (attr != A_NORMAL) {
280
297
result = _nc_trace_bufcat(bufnum, " | ");
281
298
result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
284
static const char l_brace[] =
286
static const char r_brace[] =
288
strcpy(result, l_brace);
290
result = _nc_trace_bufcat(bufnum,
291
_tracecchar_t2(bufnum + 20, buf++));
293
300
result = _nc_trace_bufcat(bufnum, r_brace);
298
306
NCURSES_EXPORT(const char *)
299
_nc_viscbuf(const cchar_t *buf, int len)
307
_nc_viscbuf(const NCURSES_CH_T * buf, int len)
301
309
return _nc_viscbuf2(0, buf, len);
303
311
#endif /* TRACE */
304
#endif /* USE_WIDEC_SUPPORT */