diff --git a/pd/src/s_inter.c b/pd/src/s_inter.c index ede74bef7d3dd265747e59645eb6e8f325abd6f7..75a8ffeb16d1db63e313eec67b7088d62bf4ab1e 100644 --- a/pd/src/s_inter.c +++ b/pd/src/s_inter.c @@ -14,6 +14,8 @@ that didn't really belong anywhere. */ #ifdef HAVE_UNISTD_H #include <unistd.h> +#else // if isatty exists outside unistd, please add another #ifdef +static int isatty(int fd) {return 0;} #endif #ifndef _WIN32 @@ -80,6 +82,8 @@ typedef int socklen_t; #define LOCALHOST "localhost" #endif +static int stderr_isatty; + #include <execinfo.h> typedef struct _fdpoll @@ -452,10 +456,11 @@ static int socketreceiver_doread(t_socketreceiver *x) { intail = (indx+1)&(INBUFSIZE-1); binbuf_text(inbinbuf, messbuf, bp - messbuf); - if (sys_debuglevel & DEBUG_MESSDOWN) - { - int res = write(2, messbuf, bp - messbuf); - res = write(2, "\n", 1); + if (sys_debuglevel & DEBUG_MESSDOWN) { + if (stderr_isatty) + fprintf(stderr,"<- \e[0;1;36m%.*s\e[0m\n", bp - messbuf, messbuf); + else + fprintf(stderr,"<- %.*s\n", bp - messbuf, messbuf); } x->sr_inhead = inhead; x->sr_intail = intail; @@ -710,7 +715,13 @@ void sys_vvgui(const char *fmt, va_list ap) { } if (sys_debuglevel & DEBUG_MESSUP) { //blargh(); - fprintf(stderr, "%s", sys_guibuf + sys_guibufhead); + int begin = lastend=='\n' || lastend=='\r' || lastend==-1; + if (stderr_isatty) + fprintf(stderr, "%s\e[0;1;35m%s\e[0m", + begin ? "-> " : "", sys_guibuf + sys_guibufhead); + else + fprintf(stderr, "%s%s", + begin ? "-> " : "", sys_guibuf + sys_guibufhead); } sys_guibufhead += msglen; sys_bytessincelastping += msglen; @@ -931,6 +942,7 @@ int sys_startgui(const char *guidir) int len = sizeof(server); int ntry = 0, portno = FIRSTPORTNUM; int xsock = -1; + stderr_isatty = isatty(2); #ifdef MSW short version = MAKEWORD(2, 0); WSADATA nobby; diff --git a/pd/src/t_tkcmd.c b/pd/src/t_tkcmd.c index e4f2b890aa00335a4c927ee91c6711c6a99f08c6..3cbac0751d8a5ff229cc668de6dd2d5a2e94960e 100644 --- a/pd/src/t_tkcmd.c +++ b/pd/src/t_tkcmd.c @@ -17,6 +17,8 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> +#else // if isatty exists outside unistd, please add another #ifdef +static int isatty(int fd) {return 0;} #endif #ifndef MSW @@ -64,6 +66,7 @@ void tcl_mess(char *s); static Tcl_Interp *tk_pdinterp; static int pd_portno = 0; +static int stderr_isatty; /***************** the socket setup code ********************/ @@ -558,8 +561,8 @@ void tcl_mess(char *s) int result; #ifdef DEBUG_TCL - char catch_s[strlen(s)+1]; - sprintf(catch_s, "%s", s); + char *catch_s = s; + //char catch_s[strlen(s)+666]; sprintf(catch_s, "set errorInfo \"\"; if {[catch {%s}]} {puts \"\\033\\[0;1;33m$errorInfo\\033\\[0m\"}", s); #else char catch_s[strlen(s)+11]; sprintf(catch_s, "catch { %s }", s); @@ -571,9 +574,13 @@ void tcl_mess(char *s) Tcl_DecrRefCount(messageObjPtr); if (result != TCL_OK) { - if (tk_pdinterp) printf("in sys_gui \e[0;1;36m%s\e[31m%s\e[0m\n", - s, Tcl_GetStringResult(tk_pdinterp)); - else printf("no error\n"); + if (tk_pdinterp) { + const char *t = Tcl_GetStringResult(tk_pdinterp); + if (stderr_isatty) + printf("in sys_gui \e[0;1;33m%s\e[31m%s\e[0m\n", s, t); + else + printf("in sys_gui %s%s\n", s, t); + } else printf("no error\n"); } } @@ -653,6 +660,7 @@ void pdgui_setname(char *s) int Pdtcl_Init(Tcl_Interp *interp) { + stderr_isatty = isatty(2); const char *argv = Tcl_GetVar(interp, "argv", 0); int portno = 0, i; if (argv)