/////////////////////////////////////////////////////////////////////////////// // TraceEx.h // // Contains functions and macro's for tracing program execution in debug and // // non-debug versions of a program. // // // // Copyright (c) JAK++ Software Development B.V. 1995-1999 All Rights // // Reserved. // // Copyright (c) Smartsoft, LLC 1999-2001. All Rights Reserved. // // Written by Jan Knepper // // Thank the Lord for giving me everything to make this possible! // // // // Redistribution and use in source and binary forms, with or without // // modification, are permitted provided that the following conditions // // are met: // // 1. Redistributions of source code must retain the above copyright // // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // // notice, this list of conditions and the following disclaimer in the // // documentation and/or other materials provided with the distribution. // // 3. The name of the author may not be used to endorse or promote products // // derived from this software without specific prior written permission. // // // // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND // // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE // // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // // THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////////// #ifndef TRACEEX_H #define TRACEEX_H #ifndef __TCHAR_H # include #endif #ifndef __STDIO_H # include #endif #ifndef TARGET_H # include "Target.h" #endif #ifdef __cplusplus extern "C" { #endif /////////////////////////////////////////////////////////////////////////////// // Tracing works on 3 different levels: // // - Logging __FILE__ and __LINE__ (location) and message to a file without // // process interruption. (Level-0) // // - Logging location and message in to a title in Windows environments and // // at the left top of the screen in Text-Mode environments without process // // interruption. (Level-1) // // - Logging location and message in a MessageBox in Windows environments // // and also in a MessageBox in Text-Mode environment. This interrupts the // // running process until the MessageBox is dismissed. (Level-2) // // // // Default a higher level always automatically invokes all methods of // // reporting of the lower levels. In other words, tracing with a method to // // get information reported in a MessageBox, also will report the // // information in the title or left top of the screen and into a file. // // Each level can be queried, turned on and off with the functions: // // - GetTraceLog // // - SetTraceLog // // - GetTraceTitle // // - SetTraceTitle // // - GetTraceMessage // // - SetTraceMessage // // // // The default format (printf) of how the location (__FILE__ and __LINE__) // // are represented is "%s [%d]", but can be queried and changed with: // // - GetTraceFormat // // - SetTraceFormat // // // // The default separation between location and the message information in // // file and title/left top screen logging is " => ", but can be queried and // // changed with: // // - GetTraceSeparator // // - SetTraceSeparator // // // // The default path name of the log file is "C:\TEMP\TRACE.JAK" this can be // // queried and changed with: // // - GetTraceLogFile // // - SetTraceLogFile // // // // To activate tracing for sources on or a combination of the following // // defines is required: // // -D_TRACE // // -D_TRACE_LOCAL // // The reason for this is that -D_TRACE should be used in a makefile or // // project to turn on tracing for all the sources, while -D_TRACE_LOCAL // // could be defined for or even inside a particular source. // // The latter of course could also be done by defining -D_TRACE for a // // particular source. It is just convenient to have two define's to switch // // tracing on and off. // // Notice that the function names mentioned actually are macro names that // // depending on definition of either -D_TRACE or -D_TRACE_LOCAL will be // // expanded to real functions or not. // // // // The idea behind this design is that there are a couple of easy // // posibilities: // // - Generate .EXE/.DLL with or without tracing code depending on -D_TRACE // // and -D_TRACE_LOCAL. When none of these is defined there are no tracing // // calls made because no tracing code is generated during compilation. // // - Generate .EXE/.DLL with switchable tracing code. Either -D_TRACE, // // -D_TRACE_LOCAL or both should be defined during compilation. However // // the actual tracing can be turned off by using the mentioned functions. // /////////////////////////////////////////////////////////////////////////////// extern int _GetTraceLog (); extern void _SetTraceLog ( int ); extern int _GetTraceTitle (); extern void _SetTraceTitle ( int ); extern int _GetTraceMessage (); extern void _SetTraceMessage ( int ); extern const TCHAR *_GetTraceFormat (); extern void _SetTraceFormat ( const TCHAR * ); extern const TCHAR *_GetTraceSeparator (); extern void _SetTraceSeparator ( const TCHAR * ); extern const TCHAR *_GetTraceLogFile (); extern void _SetTraceLogFile ( const TCHAR * ); #if defined(I_WIN_32) extern int _TraceLog ( HWND, const TCHAR *, int, const TCHAR *, ... ); extern int _TraceTitle ( HWND, const TCHAR *, int, const TCHAR *, ... ); extern int _TraceMessage ( HWND, const TCHAR *, int, const TCHAR *, ... ); #elif defined(I_WIN_16) #elif defined(I_OS2_32) #elif defined(I_DOS_32) #elif defined(I_DOS_16) extern int _TraceLog ( int , const TCHAR *, int, const TCHAR *, ... ); extern int _TraceTitle ( int , const TCHAR *, int, const TCHAR *, ... ); extern int _TraceMessage ( int , const TCHAR *, int, const TCHAR *, ... ); #elif defined(I_NET_32) #elif defined(I_UNIX_32) extern int _TraceLog ( int , const TCHAR *, int, const TCHAR *, ... ); extern int _TraceTitle ( int , const TCHAR *, int, const TCHAR *, ... ); extern int _TraceMessage ( int , const TCHAR *, int, const TCHAR *, ... ); #else #pragma message "Can't trace on this target platform yet!" #error "Can't trace on this target platform yet!" #endif #if defined(_TRACE) || defined(_TRACE_LOCAL) #define GetTraceLog() _GetTraceLog () #define SetTraceLog(x) _SetTraceLog ( x ) #define GetTraceTitle() _GetTraceTitle () #define SetTraceTitle(x) _SetTraceTitle ( x ) #define GetTraceMessage() _GetTraceMessage () #define SetTraceMessage(x) _SetTraceMessage ( x ) #define GetTraceFormat() _GetTraceFormat () #define SetTraceFormat(x) _SetTraceFormat ( x ) #define GetTraceSeparator() _GetTraceSeparator () #define SetTraceSeparator(x) _SetTraceSeparator ( x ) #define GetTraceLogFile() _GetTraceLogFile () #define SetTraceLogFile(x) _SetTraceLogFile ( x ) // Macro's for Trace variable's. #define V_TRACE(x) x // Macro's for Trace Log. #define L_TRACE (w,m) _TraceLog (w,_T(__FILE__),__LINE__,m) #define L_TRACE0(w,m) _TraceLog (w,_T(__FILE__),__LINE__,m) #define L_TRACE1(w,m,a0) _TraceLog (w,_T(__FILE__),__LINE__,m,a0) #define L_TRACE2(w,m,a0,a1) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1) #define L_TRACE3(w,m,a0,a1,a2) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2) #define L_TRACE4(w,m,a0,a1,a2,a3) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3) #define L_TRACE5(w,m,a0,a1,a2,a3,a4) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4) #define L_TRACE6(w,m,a0,a1,a2,a3,a4,a5) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5) #define L_TRACE7(w,m,a0,a1,a2,a3,a4,a5,a6) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6) #define L_TRACE8(w,m,a0,a1,a2,a3,a4,a5,a6,a7) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6,a7) #define L_TRACE9(w,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) _TraceLog (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) // Macro's for Trace Title. #define T_TRACE (w,m) _TraceTitle (w,_T(__FILE__),__LINE__,m) #define T_TRACE0(w,m) _TraceTitle (w,_T(__FILE__),__LINE__,m) #define T_TRACE1(w,m,a0) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0) #define T_TRACE2(w,m,a0,a1) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1) #define T_TRACE3(w,m,a0,a1,a2) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2) #define T_TRACE4(w,m,a0,a1,a2,a3) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3) #define T_TRACE5(w,m,a0,a1,a2,a3,a4) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4) #define T_TRACE6(w,m,a0,a1,a2,a3,a4,a5) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5) #define T_TRACE7(w,m,a0,a1,a2,a3,a4,a5,a6) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6) #define T_TRACE8(w,m,a0,a1,a2,a3,a4,a5,a6,a7) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6,a7) #define T_TRACE9(w,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) _TraceTitle (w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) // Macro's for Trace Message. #define M_TRACE (w,m) _TraceMessage(w,_T(__FILE__),__LINE__,m) #define M_TRACE0(w,m) _TraceMessage(w,_T(__FILE__),__LINE__,m) #define M_TRACE1(w,m,a0) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0) #define M_TRACE2(w,m,a0,a1) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1) #define M_TRACE3(w,m,a0,a1,a2) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2) #define M_TRACE4(w,m,a0,a1,a2,a3) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3) #define M_TRACE5(w,m,a0,a1,a2,a3,a4) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4) #define M_TRACE6(w,m,a0,a1,a2,a3,a4,a5) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5) #define M_TRACE7(w,m,a0,a1,a2,a3,a4,a5,a6) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6) #define M_TRACE8(w,m,a0,a1,a2,a3,a4,a5,a6,a7) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6,a7) #define M_TRACE9(w,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) _TraceMessage(w,_T(__FILE__),__LINE__,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) #else #define GetTraceLog() 0 #define SetTraceLog(x) #define GetTraceTitle() 0 #define SetTraceTitle(x) #define GetTraceMessage() 0 #define SetTraceMessage(x) #define GetTraceFormat() ( void * ) 0 #define SetTraceFormat(x) #define GetTraceSeparator() ( void * ) 0 #define SetTraceSeparator(x) #define GetTraceLogFile() ( void * ) 0 #define SetTraceLogFile(x) // Macro's for Trace variable's. #define V_TRACE(x) // Macro's for Trace Log. #define L_TRACE (w,m) #define L_TRACE0(w,m) #define L_TRACE1(w,m,a0) #define L_TRACE2(w,m,a0,a1) #define L_TRACE3(w,m,a0,a1,a2) #define L_TRACE4(w,m,a0,a1,a2,a3) #define L_TRACE5(w,m,a0,a1,a2,a3,a4) #define L_TRACE6(w,m,a0,a1,a2,a3,a4,a5) #define L_TRACE7(w,m,a0,a1,a2,a3,a4,a5,a6) #define L_TRACE8(w,m,a0,a1,a2,a3,a4,a5,a6,a7) #define L_TRACE9(w,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) // Macro's for Trace Title. #define T_TRACE (w,m) #define T_TRACE0(w,m) #define T_TRACE1(w,m,a0) #define T_TRACE2(w,m,a0,a1) #define T_TRACE3(w,m,a0,a1,a2) #define T_TRACE4(w,m,a0,a1,a2,a3) #define T_TRACE5(w,m,a0,a1,a2,a3,a4) #define T_TRACE6(w,m,a0,a1,a2,a3,a4,a5) #define T_TRACE7(w,m,a0,a1,a2,a3,a4,a5,a6) #define T_TRACE8(w,m,a0,a1,a2,a3,a4,a5,a6,a7) #define T_TRACE9(w,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) // Macro's for Trace Message. #define M_TRACE (w,m) #define M_TRACE0(w,m) #define M_TRACE1(w,m,a0) #define M_TRACE2(w,m,a0,a1) #define M_TRACE3(w,m,a0,a1,a2) #define M_TRACE4(w,m,a0,a1,a2,a3) #define M_TRACE5(w,m,a0,a1,a2,a3,a4) #define M_TRACE6(w,m,a0,a1,a2,a3,a4,a5) #define M_TRACE7(w,m,a0,a1,a2,a3,a4,a5,a6) #define M_TRACE8(w,m,a0,a1,a2,a3,a4,a5,a6,a7) #define M_TRACE9(w,m,a0,a1,a2,a3,a4,a5,a6,a7,a8) #endif #ifdef __cplusplus } #endif #endif