diff --git a/console/tidy.c b/console/tidy.c index 6929882..93a6e85 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -22,15 +22,12 @@ #include "tidy.h" #include "tidybuffio.h" #include "locale.h" +#include "sprtf.h" #if defined(_WIN32) # include /* Force console to UTF8. */ #endif -#ifdef ENABLE_DEBUG_LOG -# include "sprtf.h" -#endif - #if defined(ENABLE_DEBUG_LOG) && defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC) # include # include @@ -2016,7 +2013,6 @@ int main( int argc, char** argv ) # if defined(_CRTDBG_MAP_ALLOC) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); # endif - set_log_file((char *)"temptidy.txt", 0); #endif tdoc = tidyCreate(); diff --git a/include/tidyplatform.h b/include/tidyplatform.h index c617e87..28de468 100644 --- a/include/tidyplatform.h +++ b/include/tidyplatform.h @@ -494,6 +494,9 @@ extern "C" { # if defined(_MSC_VER) # define fileno _fileno +#if !defined(NDEBUG) && !defined(ENABLE_DEBUG_LOG) && !defined(DISABLE_DEBUG_LOG) +#define ENABLE_DEBUG_LOG +#endif #endif # define access _access @@ -662,38 +665,8 @@ opaque_type( TidyIterator ); } /* extern "C" */ #endif - -/*============================================================================= - * Debugging - * When building and defining the ENABLE_DEBUG_LOG macro, Tidy will output - * extensive debug information. In addition to this macro, you can supply - * build flags for additional diagnostic information: - * - _CRTDBG_MAP_ALLOC (_MSC_VER only) - * - DEBUG_ALLOCATION - * - DEBUG_MEMORY - * - * You can use DEBUG_LOG( SPRTF() ) to avoid #ifdef ENABLE_DEBUG_LOG for - * one-liners. - *===========================================================================*/ - -#ifdef ENABLE_DEBUG_LOG -# include "sprtf.h" -#endif - -#ifndef SPRTF -# define SPRTF printf -#endif - -#ifdef ENABLE_DEBUG_LOG -# define DEBUG_LOG(ARG) do { ARG; } while(0) -#else -# define DEBUG_LOG(ARG) -#endif - - #endif /* __TIDY_PLATFORM_H__ */ - /* * local variables: * mode: c diff --git a/src/alloc.c b/src/alloc.c index 1666e40..7235a3c 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -9,6 +9,7 @@ #include "tidy.h" #include "forward.h" +#include "sprtf.h" static TidyMalloc g_malloc = NULL; static TidyRealloc g_realloc = NULL; diff --git a/src/fileio.c b/src/fileio.c index 8a5297f..61048c0 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -13,6 +13,7 @@ #include "forward.h" #include "fileio.h" #include "tidy.h" +#include "sprtf.h" typedef struct _fp_input_source { diff --git a/src/lexer.c b/src/lexer.c index 21728e0..05fc509 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -39,6 +39,7 @@ #include "clean.h" #include "utf8.h" #include "streamio.h" +#include "sprtf.h" #if defined(ENABLE_DEBUG_LOG) /* #define DEBUG_ALLOCATION special EXTRA allocation debug information - VERY NOISY */ diff --git a/src/parser.c b/src/parser.c index 333996c..8569ed5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -12,6 +12,7 @@ #include "clean.h" #include "tags.h" #include "tmbstr.h" +#include "sprtf.h" /* Issue #72 - Need to know to avoid error-reporting - no warning only if --show-body-only yes diff --git a/src/sprtf.c b/src/sprtf.c index cd6dd8d..3468ac1 100644 --- a/src/sprtf.c +++ b/src/sprtf.c @@ -28,6 +28,8 @@ #include /* for exit() in unix */ #include "sprtf.h" +#ifdef ENABLE_DEBUG_LOG + #ifdef _MSC_VER # ifndef _CRT_SECURE_NO_DEPRECATE # define _CRT_SECURE_NO_DEPRECATE @@ -56,11 +58,8 @@ char *GetNxtBuf() } #define MXIO 512 -#ifdef _MSC_VER /* use local log */ -static char def_log[] = "tempex.txt"; -#else -static char def_log[] = "ex.log"; -#endif + +static char def_log[] = "temptidy.txt"; /* use local log */ static char logfile[264] = "\0"; static FILE * outfile = NULL; static int addsystime = 0; @@ -419,4 +418,5 @@ int MCDECL wsprtf( PTSTR pf, ... ) #endif /* #ifdef UNICODE */ +#endif /* #ifdef ENABLE_DEBUG_LOG */ /* eof - sprtf.c */ diff --git a/src/sprtf.h b/src/sprtf.h index 322009c..47033f0 100644 --- a/src/sprtf.h +++ b/src/sprtf.h @@ -26,6 +26,31 @@ #ifdef __cplusplus extern "C" { #endif +#ifdef ENABLE_DEBUG_LOG + /*============================================================================= + * EXTRA Debugging, and information aid. + * + * When building and defining the ENABLE_DEBUG_LOG macro, Tidy will output + * extensive debug information. In addition to this macro, you can supply + * cmake build flags for additional diagnostic information: + * - -DENABLE_ALLOC_DEBUG:BOOL=ON - DEBUG_ALLOCATION + * - -DENABLE_MEMORY_DEBUG:BOOL=ON - DEBUG_MEMORY + * - -DENABLE_CRTDBG_MEMORY:BOOL=ON - _CRTDBG_MAP_ALLOC (WIN32 only) + * + * _MSC_VER Only - ENABLE_DEBUG_LOG is automatically enabled in the Debug + * build, unless DISABLE_DEBUG_LOG is defined. See 'tidyplatform.h' + * + * You can use DEBUG_LOG( SPRTF() ) to avoid #ifdef ENABLE_DEBUG_LOG for + * one-liners. + * + * This EXTRA Debug information is also written to a 'temptidy.txt' log + * file, for review, and analysis. + * + *===========================================================================*/ + +#ifndef SPRTF +# define SPRTF sprtf +#endif #ifdef _MSC_VER # define MCDECL _cdecl @@ -62,9 +87,14 @@ TIDY_EXPORT char *get_date_time_stg(void); TIDY_EXPORT int gettimeofday(struct timeval *tp, void *tzp); #endif +# define DEBUG_LOG(ARG) do { ARG; } while(0) + +#else +# define DEBUG_LOG(ARG) +#endif + #ifdef __cplusplus } #endif - #endif /* #ifndef _SPRTF_HXX_*/ /* eof - sprtf.h */ diff --git a/src/tags.c b/src/tags.c index 67eeaa0..fbcf547 100644 --- a/src/tags.c +++ b/src/tags.c @@ -10,6 +10,8 @@ #include "tidy-int.h" #include "message.h" #include "tmbstr.h" +#include "sprtf.h" + /* Attribute checking methods */ static CheckAttribs CheckIMG; static CheckAttribs CheckLINK; diff --git a/src/tidylib.c b/src/tidylib.c index ade57ae..3145cdc 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -33,7 +33,7 @@ #include "utf8.h" #include "mappedio.h" #include "language.h" - +#include "sprtf.h" /* Create/Destroy a Tidy "document" object */ static TidyDocImpl* tidyDocCreate( TidyAllocator *allocator );