From 42e91b48b003dae34edd8f41b82ba0d7ffa67d16 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 12 Dec 2007 01:07:10 +0000 Subject: Added more tracey goodness, this is incomplete, but cool looking. Also removed some debugging from Process, it needs a helper to clear a buffer, or an option to ignore stderr. --- src/process.cpp | 1 - src/trace.h | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/process.cpp b/src/process.cpp index 5dab243..719996b 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -87,7 +87,6 @@ size_t Bu::Process::read( void *pBuf, size_t nBytes ) size_t iRet = ::read( iStdOut, (char *)pBuf+iTotal, nBytes-iTotal ); if( iRet == 0 ) return iTotal; - printf("--read=%d / %d--\n", iRet, iTotal+iRet ); iTotal += iRet; if( iTotal == nBytes ) return iTotal; diff --git a/src/trace.h b/src/trace.h index 345a2de..4f85c9b 100644 --- a/src/trace.h +++ b/src/trace.h @@ -9,9 +9,155 @@ #define BU_TRACE_H #ifdef BU_TRACE -# define TRACE() printf("trace: %s\n", __PRETTY_FUNCTION__ ) +#include "bu/fstring.h" + +namespace Nango +{ + template void __tracer_format( t &v ); + + void __tracer( const char *pf ) + { + printf("trace: %s\n", pf ); + } + +#define looper( vv ) \ + for( ; *n; n++ ) \ + { \ + if( *n == ',' || *n == ')' ) \ + { \ + fwrite( s, (int)n-(int)s, 1, stdout ); \ + fwrite("=", 1, 1, stdout); \ + __tracer_format( vv ); \ + s = n; \ + n++; \ + break; \ + } \ + } + template void __tracer( const char *pf, t1 &v1 ) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template void __tracer( const char *pf, + t1 &v1, t2 &v2 ) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + looper( v2 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template + void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3 ) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + looper( v2 ); + looper( v3 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template + void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4 ) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + looper( v2 ); + looper( v3 ); + looper( v4 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template + void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5 ) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + looper( v2 ); + looper( v3 ); + looper( v4 ); + looper( v5 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template + void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5, + t6 &v6) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + looper( v2 ); + looper( v3 ); + looper( v4 ); + looper( v5 ); + looper( v6 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template + void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5, + t6 &v6, t7 &v7 ) + { + printf("trace: "); + const char *s = pf; + const char *n = pf; + looper( v1 ); + looper( v2 ); + looper( v3 ); + looper( v4 ); + looper( v5 ); + looper( v6 ); + looper( v7 ); + fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( "\n", 1, 1, stdout ); + } + + template<> void __tracer_format( const int &v ) + { + printf("%d", v ); + } + + template<> void __tracer_format( int &v ) + { + printf("%d", v ); + } + + template<> void __tracer_format( void * &v ) + { + printf("0x%08X", (unsigned int)v ); + } + + template<> void __tracer_format( const char * &v ) + { + printf("\"%s\"", v ); + } +} + +# define TRACE(args...) Nango::__tracer( __PRETTY_FUNCTION__, ##args ) #else -# define TRACE() {} +# define TRACE(args...) {} #endif #endif -- cgit v1.2.3