static const char * _nc_visbuf2n(int bufnum, const char *buf, int len) { char *vbuf; char *tp; int c; if (buf == 0) return ("(null)"); if (buf == CANCELLED_STRING) return ("(cancelled)"); if (len < 0) len = strlen(buf); #ifdef TRACE tp = vbuf = _nc_trace_buf(bufnum, (unsigned) (len * 4) + 5); #else { static char *mybuf[2]; mybuf[bufnum] = typeRealloc(char, (unsigned) (len * 4) + 5, mybuf[bufnum]); tp = vbuf = mybuf[bufnum]; } #endif *tp++ = D_QUOTE; while ((--len >= 0) && (c = *buf++) != '\0') { tp = _nc_vischar(tp, UChar(c)); } *tp++ = D_QUOTE; *tp++ = '\0'; return (vbuf); }
static const char * _nc_visbuf2n(int bufnum, const char *buf, int len) { const char *vbuf; char *tp; int c; if (buf == 0) return ("(null)"); if (buf == CANCELLED_STRING) return ("(cancelled)"); if (len < 0) len = (int) strlen(buf); #ifdef TRACE vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len)); #else { static char *mybuf[NUM_VISBUFS]; if (bufnum < 0) { for (c = 0; c < NUM_VISBUFS; ++c) { FreeAndNull(mybuf[c]); } tp = 0; } else { mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]); vbuf = tp = mybuf[bufnum]; } } #endif if (tp != 0) { *tp++ = D_QUOTE; while ((--len >= 0) && (c = *buf++) != '\0') { tp = _nc_vischar(tp, UChar(c)); } *tp++ = D_QUOTE; *tp = '\0'; } else { vbuf = ("(_nc_visbuf2n failed)"); } return (vbuf); }
static const char * _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) { const char *vbuf; char *tp; wchar_t c; if (buf == 0) return ("(null)"); if (len < 0) len = (int) wcslen(buf); #ifdef TRACE vbuf = tp = _nc_trace_buf(bufnum, WideLen(len)); #else { static char *mybuf[NUM_VISBUFS]; mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]); vbuf = tp = mybuf[bufnum]; } #endif if (tp != 0) { *tp++ = D_QUOTE; while ((--len >= 0) && (c = *buf++) != '\0') { char temp[CCHARW_MAX + 80]; int j = wctomb(temp, c), k; if (j <= 0) { sprintf(temp, "\\u%08X", (unsigned) c); j = (int) strlen(temp); } for (k = 0; k < j; ++k) { tp = _nc_vischar(tp, UChar(temp[k])); } } *tp++ = D_QUOTE; *tp = '\0'; } else { vbuf = ("(_nc_viswbuf2n failed)"); } return (vbuf); }
static const char * _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) { char *vbuf; char *tp; wchar_t c; if (buf == 0) return ("(null)"); if (len < 0) len = wcslen(buf); #ifdef TRACE tp = vbuf = _nc_trace_buf(bufnum, (unsigned) (len * 4) + 5); #else { static char *mybuf[2]; mybuf[bufnum] = typeRealloc(char, (unsigned) (len * 4) + 5, mybuf[bufnum]); tp = vbuf = mybuf[bufnum]; } #endif *tp++ = D_QUOTE; while ((--len >= 0) && (c = *buf++) != '\0') { char temp[CCHARW_MAX + 80]; int j = wctomb(temp, c), k; if (j <= 0) { sprintf(temp, "\\u%08X", (wint_t) c); j = strlen(temp); } for (k = 0; k < j; ++k) { tp = _nc_vischar(tp, UChar(temp[k])); } } *tp++ = D_QUOTE; *tp++ = '\0'; return (vbuf); }