/****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-2008,2009 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 *
#include <tic.h>
#include <ctype.h>
-MODULE_ID("$Id: visbuf.c,v 1.32 2008/08/04 23:07:39 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.35 2009/12/12 21:34:23 tom Exp $")
+
+#define NUM_VISBUFS 4
#define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4)
#define WideLen(len) (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX)
vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len));
#else
{
- static char *mybuf[4];
- mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]);
- vbuf = tp = mybuf[bufnum];
+ 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) {
vbuf = tp = _nc_trace_buf(bufnum, WideLen(len));
#else
{
- static char *mybuf[2];
+ static char *mybuf[NUM_VISBUFS];
mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]);
vbuf = tp = mybuf[bufnum];
}
static unsigned mylen;
unsigned n;
- for (n = 0; buf[n] != 0; ++n) ;
+ for (n = 0; buf[n] != 0; ++n) {
+ ; /* empty */
+ }
if (mylen < ++n) {
mylen = n + 80;
if (mybuf != 0)
else
mybuf = typeMalloc(wchar_t, mylen);
}
- for (n = 0; buf[n] != 0; ++n)
+ for (n = 0; buf[n] != 0; ++n) {
mybuf[n] = (wchar_t) buf[n];
+ }
+ mybuf[n] = L'\0';
return _nc_viswbuf2(0, mybuf);
}
int k;
PUTC_ch = buf[j].chars[PUTC_i];
- if (PUTC_ch == L'\0')
+ if (PUTC_ch == L'\0') {
+ if (PUTC_i == 0)
+ result = _nc_trace_bufcat(bufnum, "\\000");
break;
- PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st);
+ }
+ PUTC_n = (int) wcrtomb(PUTC_buf,
+ buf[j].chars[PUTC_i], &PUT_st);
if (PUTC_n <= 0)
break;
for (k = 0; k < PUTC_n; k++) {