]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/trace/visbuf.c
ncurses 5.4
[ncurses.git] / ncurses / trace / visbuf.c
index 4fbecc50e4f6132ba50adbe2dd4900dd71f1ce1e..ed8f872ebb436a7dbdd3f3850dffbbeef5ae8100 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2001-2003,2004 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            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey 1996-2001                                      *
+ *  Author: Thomas E. Dickey 1996-2004                                      *
  *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  ****************************************************************************/
@@ -41,7 +41,7 @@
 #include <tic.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: visbuf.c,v 1.6 2002/10/06 00:03:43 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.9 2004/02/03 01:16:37 tom Exp $")
 
 static char *
 _nc_vischar(char *tp, unsigned c)
@@ -71,6 +71,7 @@ _nc_vischar(char *tp, unsigned c)
        sprintf(tp, "\\%03lo", ChCharOf(c));
        tp += strlen(tp);
     }
+    *tp = 0;
     return tp;
 }
 
@@ -187,9 +188,7 @@ _nc_viswbufn(const wchar_t * buf, int len)
 NCURSES_EXPORT(const char *)
 _nc_viscbuf2(int bufnum, const cchar_t * buf, int len)
 {
-    size_t have = BUFSIZ;
-    char *result = _nc_trace_buf(bufnum, have);
-    char *tp = result;
+    char *result = _nc_trace_buf(bufnum, BUFSIZ);
     int n;
     bool same = TRUE;
     attr_t attr = A_NORMAL;
@@ -211,17 +210,18 @@ _nc_viscbuf2(int bufnum, const cchar_t * buf, int len)
      * detailed trace function that displays each character separately.
      */
     if (same) {
-       *tp++ = D_QUOTE;
+       static const char d_quote[] =
+       {D_QUOTE, 0};
+
+       result = _nc_trace_bufcat(bufnum, d_quote);
        while (len-- > 0) {
            if ((found = _nc_altcharset_name(attr, CharOfD(buf))) != 0) {
-               (void) strcpy(tp, found);
-               tp += strlen(tp);
+               result = _nc_trace_bufcat(bufnum, found);
                attr &= ~A_ALTCHARSET;
            } else if (!isnac(CHDEREF(buf))) {
                PUTC_DATA;
 
-               memset(&PUT_st, '\0', sizeof(PUT_st));
-               PUTC_i = 0;
+               PUTC_INIT;
                do {
                    PUTC_ch = PUTC_i < CCHARW_MAX ? buf->chars[PUTC_i] : L'\0';
                    PUTC_n = wcrtomb(PUTC_buf, buf->chars[PUTC_i], &PUT_st);
@@ -230,33 +230,31 @@ _nc_viscbuf2(int bufnum, const cchar_t * buf, int len)
                    if (PUTC_n <= 0)
                        break;
                    for (n = 0; n < PUTC_n; n++) {
-                       tp = _nc_vischar(tp, UChar(PUTC_buf[n]));
+                       char temp[80];
+                       _nc_vischar(temp, UChar(PUTC_buf[n]));
+                       result = _nc_trace_bufcat(bufnum, temp);
                    }
                    ++PUTC_i;
                } while (PUTC_ch != L'\0');
            }
            buf++;
        }
-       *tp++ = D_QUOTE;
-       *tp++ = '\0';
-       if (attr != A_NORMAL)
-           (void) sprintf(tp, " | %s",
-                          _traceattr2(bufnum + 20, attr));
+       result = _nc_trace_bufcat(bufnum, d_quote);
+       if (attr != A_NORMAL) {
+           result = _nc_trace_bufcat(bufnum, " | ");
+           result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+       }
     } else {
-       *tp++ = L_BRACE;
+       static const char l_brace[] =
+       {L_BRACE, 0};
+       static const char r_brace[] =
+       {R_BRACE, 0};
+       strcpy(result, l_brace);
        while (len-- > 0) {
-           char *temp = _tracecchar_t2(bufnum + 20, buf++);
-           size_t used = (tp - result);
-           size_t want = strlen(temp) + 5 + used;
-           if (want > have) {
-               result = _nc_trace_buf(bufnum, have = want);
-               tp = result + used;
-           }
-           (void) strcpy(tp, temp);
-           tp += strlen(tp);
+           result = _nc_trace_bufcat(bufnum,
+                                     _tracecchar_t2(bufnum + 20, buf++));
        }
-       *tp++ = R_BRACE;
-       *tp++ = '\0';
+       result = _nc_trace_bufcat(bufnum, r_brace);
     }
     return result;
 }