From 1cd04388495c0b581cd6d4a9ac8d904d73c75f6f Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 3 Oct 2017 18:08:10 -0400 Subject: [PATCH 1/5] Standard Library file header; termporary notes for me. --- console/tidy.c | 2 +- src/sprtf.c | 17 ++++++----------- src/sprtf.h | 46 ++++++++++++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index c699903..f72300b 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -2017,7 +2017,7 @@ 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); /* add_append_log(1); */ + set_log_file((char *)"temptidy.txt", 0); #endif tdoc = tidyCreate(); diff --git a/src/sprtf.c b/src/sprtf.c index 7fe2d02..cd6dd8d 100644 --- a/src/sprtf.c +++ b/src/sprtf.c @@ -1,21 +1,16 @@ -/* - * SPRTF - Log output utility - part of the HTML Tidy project +/* sprtf.c + * SPRTF - Log output utility - part of the HTML Tidy project * - * Author: Geoff R. McLane - * License: MIT (see tidy.h for the copyright notice) - * - * Revision 1.0.2 2017/02/12 17:06:02 geoff - correct license and coding style - * Revision 1.0.1 2012/11/06 13:01:25 geoff - * Revision 1.0.0 2012/10/17 00:00:00 geoff + * Copyright (c) 1998-2017 Geoff R. McLane and HTACG * + * See tidy.h for the copyright notice. */ #ifdef _MSC_VER # pragma warning( disable : 4995 ) #endif -/* Module: sprtf.c */ -/* Debug log file output */ -#include /* fopen()... */ + +#include /* fopen()... */ #include /* strcpy */ #include /* va_start, va_end, ... */ diff --git a/src/sprtf.h b/src/sprtf.h index 780b748..14c3e02 100644 --- a/src/sprtf.h +++ b/src/sprtf.h @@ -1,24 +1,32 @@ -/* - * SPRTF - Log output utility - part of the HTML Tidy project - * - * Author: Geoff R. McLane - * License: MIT (see tidy.h for the copyright notice) - * - * Revision 1.0.2 2017/02/12 17:06:02 geoff - correct license and coding style - * Revision 1.0.1 2012/11/06 13:01:25 geoff - * Revision 1.0.0 2012/10/17 00:00:00 geoff - * - */ - -/* Module: sprtf.h */ -/* Debug log file output */ #ifndef _SPRTF_HXX_ -# define _SPRTF_HXX_ +#define _SPRTF_HXX_ + +/**************************************************************************//** + * @file + * Log output utility - part of the HTML Tidy project + * + * @author Geoff R. McLane [reports _at_ geoffair _dot_ info] + * + * @copyright + * Copyright (c) 1998-2017 Geoff R. McLane and HTACG. + * @par + * All Rights Reserved. + * @par + * See `tidy.h` for the complete license. + * + * @date 2017/02/12 17:06:02 Revision 1.0.2 geoff - correct license and coding style + * @date 2012/11/06 13:01:25 Revision 1.0.1 geoff + * @date 2012/10/17 00:00:00 Revision 1.0.0 geoff + * @date Additional updates: consult git log + * + ******************************************************************************/ + #include "tidyplatform.h" #ifdef __cplusplus extern "C" { #endif + #ifdef _MSC_VER # define MCDECL _cdecl #else @@ -35,10 +43,10 @@ TIDY_EXPORT int add_append_log( int val ); TIDY_EXPORT int open_log_file( void ); TIDY_EXPORT void close_log_file( void ); -TIDY_EXPORT void set_log_file( char * nf, int open ); -TIDY_EXPORT char * get_log_file( void ); +TIDY_EXPORT void set_log_file( char * nf, int open ); /* used */ +TIDY_EXPORT char * get_log_file( void ); /* used */ -TIDY_EXPORT int MCDECL sprtf( const char *pf, ... ); +TIDY_EXPORT int MCDECL sprtf( const char *pf, ... ); /* used */ #define M_MAX_SPRTF 2048 TIDY_EXPORT int direct_out_it( char *cp ); @@ -49,6 +57,7 @@ TIDY_EXPORT char *GetNxtBuf(); TIDY_EXPORT char *get_date_stg(); TIDY_EXPORT char *get_time_stg(); TIDY_EXPORT char *get_date_time_stg(); + #ifdef _MSC_VER TIDY_EXPORT int gettimeofday(struct timeval *tp, void *tzp); #endif @@ -60,5 +69,6 @@ TIDY_EXPORT int gettimeofday(struct timeval *tp, void *tzp); #ifdef __cplusplus } #endif + #endif /* #ifndef _SPRTF_HXX_*/ /* eof - sprtf.h */ From 4e3c1a1562a7234931134efde5f2ed4bf8d30f1b Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 3 Oct 2017 20:42:29 -0400 Subject: [PATCH 2/5] Move all of the sprtf includes into tidyplatform.h --- console/tidy.c | 5 ----- include/tidyplatform.h | 14 ++++++++++++++ src/alloc.c | 3 --- src/fileio.c | 3 --- src/istack.c | 3 --- src/lexer.c | 7 ------- src/message.c | 3 --- src/messageobj.c | 3 --- src/parser.c | 7 ------- src/pprint.c | 3 --- src/sprtf.h | 4 ---- src/tags.c | 3 --- src/tidylib.c | 3 --- 13 files changed, 14 insertions(+), 47 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index f72300b..4c1a77e 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -26,17 +26,12 @@ # include /* Force console to UTF8. */ #endif #if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" # ifdef _CRTDBG_MAP_ALLOC # include # include # endif #endif -#ifndef SPRTF -# define SPRTF printf -#endif - /** Tidy will send errors to this file, which will be stderr later. */ static FILE* errout = NULL; diff --git a/include/tidyplatform.h b/include/tidyplatform.h index 19c055c..7ffac19 100644 --- a/include/tidyplatform.h +++ b/include/tidyplatform.h @@ -647,6 +647,20 @@ opaque_type( TidyIterator ); } /* extern "C" */ #endif + +/*============================================================================= + * Debugging + *===========================================================================*/ +#if !defined(NDEBUG) +# include "sprtf.h" +#endif + +#ifndef SPRTF +# define SPRTF printf +#endif + + + #endif /* __TIDY_PLATFORM_H__ */ diff --git a/src/alloc.c b/src/alloc.c index dbfd154..17a1227 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -9,9 +9,6 @@ #include "tidy.h" #include "forward.h" -#ifdef DEBUG_MEMORY -# include "sprtf.h" -#endif static TidyMalloc g_malloc = NULL; static TidyRealloc g_realloc = NULL; diff --git a/src/fileio.c b/src/fileio.c index 52fddc6..da5882e 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -13,9 +13,6 @@ #include "forward.h" #include "fileio.h" #include "tidy.h" -#if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" -#endif typedef struct _fp_input_source { diff --git a/src/istack.c b/src/istack.c index bcb09ba..2576407 100644 --- a/src/istack.c +++ b/src/istack.c @@ -10,9 +10,6 @@ #include "attrs.h" #include "streamio.h" #include "tmbstr.h" -#if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" -#endif /* duplicate attributes */ AttVal *TY_(DupAttrs)( TidyDocImpl* doc, AttVal *attrs) diff --git a/src/lexer.c b/src/lexer.c index 8eedf60..876d690 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -39,13 +39,6 @@ #include "clean.h" #include "utf8.h" #include "streamio.h" -#ifdef _MSC_VER -# include "sprtf.h" -#endif - -#ifndef SPRTF -# define SPRTF printf -#endif #if !defined(NDEBUG) && defined(_MSC_VER) /* #define DEBUG_ALLOCATION special EXTRA allocation debug information - VERY NOISY */ diff --git a/src/message.c b/src/message.c index ba85387..fd97164 100644 --- a/src/message.c +++ b/src/message.c @@ -14,9 +14,6 @@ #include "streamio.h" #include "tmbstr.h" #include "utf8.h" -#if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" -#endif #include "version.h" diff --git a/src/messageobj.c b/src/messageobj.c index 957ef8f..ffdb916 100644 --- a/src/messageobj.c +++ b/src/messageobj.c @@ -10,9 +10,6 @@ #include "tidy-int.h" #include "limits.h" #include "tmbstr.h" -#if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" -#endif /********************************************************************* diff --git a/src/parser.c b/src/parser.c index 55430b7..a9db91e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -12,13 +12,6 @@ #include "clean.h" #include "tags.h" #include "tmbstr.h" -#ifdef _MSC_VER -# include "sprtf.h" -#endif - -#ifndef SPRTF -# define SPRTF printf -#endif /* Issue #72 - Need to know to avoid error-reporting - no warning only if --show-body-only yes diff --git a/src/pprint.c b/src/pprint.c index b9c3334..a085463 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -24,9 +24,6 @@ # ifdef DEBUG_PPRINT extern void dbg_show_node( TidyDocImpl* doc, Node *node, int caller, int indent ); # endif -# ifdef DEBUG_INDENT -# include "sprtf.h" -# endif #endif /* diff --git a/src/sprtf.h b/src/sprtf.h index 14c3e02..c589707 100644 --- a/src/sprtf.h +++ b/src/sprtf.h @@ -62,10 +62,6 @@ TIDY_EXPORT char *get_date_time_stg(); TIDY_EXPORT int gettimeofday(struct timeval *tp, void *tzp); #endif -#ifndef SPRTF -# define SPRTF sprtf -#endif - #ifdef __cplusplus } #endif diff --git a/src/tags.c b/src/tags.c index 4cd50a4..81d67a8 100644 --- a/src/tags.c +++ b/src/tags.c @@ -10,9 +10,6 @@ #include "tidy-int.h" #include "message.h" #include "tmbstr.h" -#if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" -#endif /* Attribute checking methods */ static CheckAttribs CheckIMG; static CheckAttribs CheckLINK; diff --git a/src/tidylib.c b/src/tidylib.c index 30c1da6..9befcba 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -34,9 +34,6 @@ #include "mappedio.h" #include "language.h" -#if !defined(NDEBUG) && defined(_MSC_VER) -# include "sprtf.h" -#endif /* Create/Destroy a Tidy "document" object */ static TidyDocImpl* tidyDocCreate( TidyAllocator *allocator ); From a137c068e56a0d2d96315b0707005fab8b39bdb5 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 3 Oct 2017 20:56:50 -0400 Subject: [PATCH 3/5] Added debug to several files. WIP --- console/tidy.c | 4 ++-- include/tidyplatform.h | 4 ++++ src/fileio.c | 4 ++-- src/istack.c | 2 +- src/lexer.c | 20 ++++++++++---------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index 4c1a77e..507baac 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -2426,7 +2426,7 @@ int main( int argc, char** argv ) if ( argc > 1 ) { htmlfil = argv[1]; -#if (!defined(NDEBUG) && defined(_MSC_VER)) +#if (!defined(NDEBUG)) SPRTF("Tidying '%s'\n", htmlfil); #endif /* DEBUG outout */ if ( tidyOptGetBool(tdoc, TidyEmacs) ) @@ -2458,7 +2458,7 @@ int main( int argc, char** argv ) if ( outfil ) { status = tidySaveFile( tdoc, outfil ); } else { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static char tmp_buf[264]; sprintf(tmp_buf,"%s.html",get_log_file()); status = tidySaveFile( tdoc, tmp_buf ); diff --git a/include/tidyplatform.h b/include/tidyplatform.h index 7ffac19..5fa7cb7 100644 --- a/include/tidyplatform.h +++ b/include/tidyplatform.h @@ -481,6 +481,10 @@ extern "C" { # define setmode _setmode # endif +# if defined(_MSC_VER) +# define fileno _fileno +#endif + # define access _access # define strcasecmp _stricmp diff --git a/src/fileio.c b/src/fileio.c index da5882e..66df434 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -82,8 +82,8 @@ void TIDY_CALL TY_(filesink_putByte)( void* sinkData, byte bv ) { FILE* fout = (FILE*) sinkData; fputc( bv, fout ); -#if !defined(NDEBUG) && defined(_MSC_VER) - if (_fileno(fout) != 2) +#if !defined(NDEBUG) + if (fileno(fout) != 2) { if (bv != 0x0d) { diff --git a/src/istack.c b/src/istack.c index 2576407..a82227d 100644 --- a/src/istack.c +++ b/src/istack.c @@ -269,7 +269,7 @@ Node *TY_(InsertedToken)( TidyDocImpl* doc ) istack = lexer->insert; /* #if 0 && defined(_DEBUG) */ -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) if ( lexer->istacksize == 0 ) { SPRTF( "WARNING: ZERO sized istack!\n" ); diff --git a/src/lexer.c b/src/lexer.c index 876d690..38be8e9 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -40,7 +40,7 @@ #include "utf8.h" #include "streamio.h" -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) /* #define DEBUG_ALLOCATION special EXTRA allocation debug information - VERY NOISY */ static void check_me(char *name); static Bool show_attrs = yes; @@ -173,9 +173,9 @@ static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node ) } } #define GTDBG(a,b,c) Show_Node(a,b,c) -#else +#else /* NDEBUG is define */ #define GTDBG(a,b,c) -#endif +#endif /* !defined(NDEBUG) */ /* Forward references */ @@ -322,7 +322,7 @@ static uint GetVersFromFPI(ctmbstr fpi) return 0; } -#if (defined(_MSC_VER) && !defined(NDEBUG)) +#if defined(_MSC_VER) /* Issue #377 - Output diminishing version bits */ typedef struct tagV2S { uint bit; @@ -413,14 +413,14 @@ void TY_(ConstrainVersion)(TidyDocImpl* doc, uint vers) SPRTF("After : %s\n", vcur); } } -#else /* !#if (defined(_MSC_VER) && !defined(NDEBUG)) */ +#else /* !#if defined(_MSC_VER) */ /* everything is allowed in proprietary version of HTML */ /* this is handled here rather than in the tag/attr dicts */ void TY_(ConstrainVersion)(TidyDocImpl* doc, uint vers) { doc->lexer->versions &= (vers | VERS_PROPRIETARY); } -#endif /* #if (defined(_MSC_VER) && !defined(NDEBUG)) y/n */ +#endif /* #if defined(_MSC_VER) y/n */ Bool TY_(IsWhite)(uint c) { @@ -1413,7 +1413,7 @@ Node *TY_(NewNode)(TidyAllocator* allocator, Lexer *lexer) node->column = lexer->columns; } node->type = TextNode; -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_ALLOCATION) +#if !defined(NDEBUG) && defined(DEBUG_ALLOCATION) SPRTF("Allocated node %p\n", node ); #endif return node; @@ -1507,7 +1507,7 @@ void TY_(RemoveAttribute)( TidyDocImpl* doc, Node *node, AttVal *attr ) */ void TY_(FreeNode)( TidyDocImpl* doc, Node *node ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_ALLOCATION) +#if !defined(NDEBUG) && defined(DEBUG_ALLOCATION) /* avoid showing free of root node! */ if (node) { if (RootNode != node->type) { @@ -2484,7 +2484,7 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode ) return GetTokenFromStream( doc, mode ); } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static void check_me(char *name) { SPRTF("Have node %s\n", name); @@ -3418,7 +3418,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode ) return node; /* the COMMENT token */ } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Returning NULL...\n"); #endif return NULL; From ee54057d76fe885020189a5c4b5789f2eb0fb859 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 3 Oct 2017 21:09:59 -0400 Subject: [PATCH 4/5] Added debug to several files. WIP --- src/parser.c | 116 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/parser.c b/src/parser.c index a9db91e..491a9f5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -454,7 +454,7 @@ static void TrimInitialSpace( TidyDocImpl* doc, Node *element, Node *text ) node->end = element->start; lexer->lexbuf[node->start] = ' '; TY_(InsertNodeBeforeElement)(element ,node); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("TrimInitialSpace: Created text node, inserted before <%s>\n", (element->element ? element->element : "unknown")); #endif @@ -794,7 +794,7 @@ static void AddClassNoIndent( TidyDocImpl* doc, Node *node ) */ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static int in_parse_block = 0; static int parse_block_cnt = 0; #endif @@ -802,7 +802,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) Node *node; Bool checkstack = yes; uint istackbase = 0; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block++; parse_block_cnt++; SPRTF("Entering ParseBlock %d... %d %s\n",in_parse_block,parse_block_cnt, @@ -810,7 +810,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) #endif if ( element->tag->model & CM_EMPTY ) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlockL 1 %d...\n",in_parse_block); #endif @@ -875,7 +875,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) element->closed = yes; TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 2 %d...\n",in_parse_block); #endif @@ -929,7 +929,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) { TY_(UngetToken)( doc ); TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 2 %d...\n",in_parse_block); #endif @@ -1093,7 +1093,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) { TY_(UngetToken)( doc ); TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 3 %d...\n",in_parse_block); #endif @@ -1113,7 +1113,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) lexer->istackbase = istackbase; TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 4 %d...\n",in_parse_block); #endif @@ -1172,7 +1172,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) element->parent->tag->parser == TY_(ParseList) ) { TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 5 %d...\n",in_parse_block); #endif @@ -1187,7 +1187,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) if ( nodeIsDL(element->parent) ) { TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 6 %d...\n",in_parse_block); #endif @@ -1202,7 +1202,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) /* In exiled mode, return so table processing can continue. */ if (lexer->exiled) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 7 %d...\n",in_parse_block); #endif @@ -1217,7 +1217,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) TY_(PopInline)( doc, NULL ); lexer->istackbase = istackbase; TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 8 %d...\n",in_parse_block); #endif @@ -1227,7 +1227,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) else { TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 9 %d...\n",in_parse_block); #endif @@ -1271,7 +1271,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 9b %d...\n",in_parse_block); #endif @@ -1339,7 +1339,7 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) } TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_block--; SPRTF("Exit ParseBlock 10 %d...\n",in_parse_block); #endif @@ -1539,18 +1539,18 @@ void TY_(ParseNamespace)(TidyDocImpl* doc, Node *basenode, GetTokenMode mode) void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static int in_parse_inline = 0; #endif Lexer* lexer = doc->lexer; Node *node, *parent; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline++; SPRTF("Entering ParseInline %d...\n",in_parse_inline); #endif if (element->tag->model & CM_EMPTY) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 1 %d...\n",in_parse_inline); #endif @@ -1632,7 +1632,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) element->closed = yes; TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 2 %d...\n",in_parse_inline); #endif @@ -1723,7 +1723,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 3 %d...\n",in_parse_inline); #endif @@ -1813,7 +1813,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) TY_(InlineDup1)( doc, NULL, element ); /* dupe the , after */ if (!(mode & Preformatted)) TrimSpaces( doc, element ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 4 %d...\n",in_parse_inline); #endif @@ -1837,7 +1837,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 5 %d...\n",in_parse_inline); #endif @@ -1854,7 +1854,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) { TY_(UngetToken)( doc ); TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 6 %d...\n",in_parse_inline); #endif @@ -1880,7 +1880,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 7 %d...\n",in_parse_inline); #endif @@ -1917,7 +1917,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 8 %d...\n",in_parse_inline); #endif @@ -2043,7 +2043,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 9 %d...\n",in_parse_inline); #endif @@ -2095,7 +2095,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) { TY_(DiscardElement)( doc, element ); TY_(UngetToken)( doc ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 10 %d...\n",in_parse_inline); #endif @@ -2108,7 +2108,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(mode & Preformatted)) TrimSpaces(doc, element); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 11 %d...\n",in_parse_inline); #endif @@ -2139,7 +2139,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode ) if (!(element->tag->model & CM_OPT)) TY_(Report)(doc, element, node, MISSING_ENDTAG_FOR); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_inline--; SPRTF("Exit ParseInline 12 %d...\n",in_parse_inline); #endif @@ -2327,7 +2327,7 @@ static Bool FindLastLI( Node *list, Node **lastli ) void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static int in_parse_list = 0; #endif Lexer* lexer = doc->lexer; @@ -2335,13 +2335,13 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) Bool wasblock; Bool nodeisOL = nodeIsOL(list); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list++; SPRTF("Entering ParseList %d...\n",in_parse_list); #endif if (list->tag->model & CM_EMPTY) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list--; SPRTF("Exit ParseList 1 %d... CM_EMPTY\n",in_parse_list); #endif @@ -2356,7 +2356,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) { TY_(FreeNode)( doc, node); list->closed = yes; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list--; SPRTF("Exit ParseList 2 %d... Endtag\n",in_parse_list); #endif @@ -2423,7 +2423,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) { TY_(Report)(doc, list, node, MISSING_ENDTAG_BEFORE); TY_(UngetToken)( doc ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list--; SPRTF("Exit ParseList 3 %d... No End Tag\n",in_parse_list); #endif @@ -2456,7 +2456,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) if (TY_(nodeHasCM)(node,CM_BLOCK) && lexer->excludeBlocks) { TY_(Report)(doc, list, node, MISSING_ENDTAG_BEFORE); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list--; SPRTF("Exit ParseList 4 %d... No End Tag\n",in_parse_list); #endif @@ -2468,7 +2468,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) && (TY_(nodeHasCM)(node, CM_TABLE|CM_ROWGRP|CM_ROW) || nodeIsTABLE(node)) ) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list--; SPRTF("Exit ParseList 5 %d... exiled\n",in_parse_list); #endif @@ -2507,7 +2507,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode)) } TY_(Report)(doc, list, node, MISSING_ENDTAG_FOR); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_list--; SPRTF("Exit ParseList 6 %d... missing end tag\n",in_parse_list); #endif @@ -2931,7 +2931,7 @@ void TY_(ParseColGroup)(TidyDocImpl* doc, Node *colgroup, GetTokenMode ARG_UNUSE void TY_(ParseTableTag)(TidyDocImpl* doc, Node *table, GetTokenMode ARG_UNUSED(mode)) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static int in_parse_table = 0; #endif Lexer* lexer = doc->lexer; @@ -2941,7 +2941,7 @@ void TY_(ParseTableTag)(TidyDocImpl* doc, Node *table, GetTokenMode ARG_UNUSED(m TY_(DeferDup)( doc ); istackbase = lexer->istackbase; lexer->istackbase = lexer->istacksize; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_table++; SPRTF("Entering ParseTableTag %d...\n",in_parse_table); #endif @@ -2966,7 +2966,7 @@ void TY_(ParseTableTag)(TidyDocImpl* doc, Node *table, GetTokenMode ARG_UNUSED(m } lexer->istackbase = istackbase; table->closed = yes; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_table--; SPRTF("Exit ParseTableTag 1 %d... EndTag\n",in_parse_table); #endif @@ -3046,7 +3046,7 @@ void TY_(ParseTableTag)(TidyDocImpl* doc, Node *table, GetTokenMode ARG_UNUSED(m TY_(Report)(doc, table, node, MISSING_ENDTAG_BEFORE ); TY_(UngetToken)( doc ); lexer->istackbase = istackbase; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_table--; SPRTF("Exit ParseTableTag 2 %d... missing EndTag\n",in_parse_table); #endif @@ -3060,7 +3060,7 @@ void TY_(ParseTableTag)(TidyDocImpl* doc, Node *table, GetTokenMode ARG_UNUSED(m TY_(UngetToken)( doc ); TY_(Report)(doc, table, node, TAG_NOT_ALLOWED_IN); lexer->istackbase = istackbase; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_table--; SPRTF("Exit ParseTableTag 3 %d... CM_TABLE\n",in_parse_table); #endif @@ -3081,7 +3081,7 @@ void TY_(ParseTableTag)(TidyDocImpl* doc, Node *table, GetTokenMode ARG_UNUSED(m TY_(Report)(doc, table, node, MISSING_ENDTAG_FOR); lexer->istackbase = istackbase; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_table--; SPRTF("Exit ParseTableTag 4 %d... missing end\n",in_parse_table); #endif @@ -3317,14 +3317,14 @@ void TY_(ParseOptGroup)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(m void TY_(ParseSelect)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(mode)) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static int in_parse_select = 0; #endif Lexer* lexer = doc->lexer; Node *node; lexer->insert = NULL; /* defer implicit inline start tags */ -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_select++; SPRTF("Entering ParseSelect %d...\n",in_parse_select); #endif @@ -3336,7 +3336,7 @@ void TY_(ParseSelect)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(mod TY_(FreeNode)( doc, node); field->closed = yes; TrimSpaces(doc, field); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_select--; SPRTF("Exit ParseSelect 1 %d...\n",in_parse_select); #endif @@ -3365,7 +3365,7 @@ void TY_(ParseSelect)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(mod } TY_(Report)(doc, field, node, MISSING_ENDTAG_FOR); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_select--; SPRTF("Exit ParseSelect 2 %d...\n",in_parse_select); #endif @@ -3374,14 +3374,14 @@ void TY_(ParseSelect)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(mod /* HTML5 */ void TY_(ParseDatalist)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(mode)) { -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) static int in_parse_datalist = 0; #endif Lexer* lexer = doc->lexer; Node *node; lexer->insert = NULL; /* defer implicit inline start tags */ -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_datalist++; SPRTF("Entering ParseDatalist %d...\n",in_parse_datalist); #endif @@ -3393,7 +3393,7 @@ void TY_(ParseDatalist)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(m TY_(FreeNode)( doc, node); field->closed = yes; TrimSpaces(doc, field); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_datalist--; SPRTF("Exit ParseDatalist 1 %d...\n",in_parse_datalist); #endif @@ -3422,7 +3422,7 @@ void TY_(ParseDatalist)(TidyDocImpl* doc, Node *field, GetTokenMode ARG_UNUSED(m } TY_(Report)(doc, field, node, MISSING_ENDTAG_FOR); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) in_parse_datalist--; SPRTF("Exit ParseDatalist 2 %d...\n",in_parse_datalist); #endif @@ -3628,7 +3628,7 @@ void TY_(ParseHead)(TidyDocImpl* doc, Node *head, GetTokenMode ARG_UNUSED(mode)) int HasTitle = 0; int HasBase = 0; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Enter ParseHead...\n"); #endif while ((node = TY_(GetToken)(doc, IgnoreWhitespace)) != NULL) @@ -3734,7 +3734,7 @@ void TY_(ParseHead)(TidyDocImpl* doc, Node *head, GetTokenMode ARG_UNUSED(mode)) TY_(Report)(doc, head, node, DISCARDING_UNEXPECTED); TY_(FreeNode)( doc, node); } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Exit ParseHead 1...\n"); #endif } @@ -3790,7 +3790,7 @@ void TY_(ParseBody)(TidyDocImpl* doc, Node *body, GetTokenMode mode) checkstack = yes; TY_(BumpObject)( doc, body->parent ); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Enter ParseBody...\n"); #endif @@ -4057,7 +4057,7 @@ void TY_(ParseBody)(TidyDocImpl* doc, Node *body, GetTokenMode mode) TY_(Report)(doc, body, node, DISCARDING_UNEXPECTED); TY_(FreeNode)( doc, node); } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Exit ParseBody 1...\n"); #endif } @@ -4246,7 +4246,7 @@ void TY_(ParseHTML)(TidyDocImpl* doc, Node *html, GetTokenMode mode) Node *frameset = NULL; Node *noframes = NULL; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Entering ParseHTML...\n"); #endif TY_(SetOptionBool)( doc, TidyXmlTags, no ); @@ -4304,7 +4304,7 @@ void TY_(ParseHTML)(TidyDocImpl* doc, Node *html, GetTokenMode mode) TY_(InsertNodeAtEnd)(html, node); TY_(ParseBody)(doc, node, mode); } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Exit ParseHTML 1...\n"); #endif return; @@ -4475,7 +4475,7 @@ void TY_(ParseHTML)(TidyDocImpl* doc, Node *html, GetTokenMode mode) TY_(InsertNodeAtEnd)(html, node); ParseTag(doc, node, mode); -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("Exit ParseHTML 2...\n"); #endif } From dedcb7bb4d7f6417a8d7f68f5fa6f32c6cef5a83 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 3 Oct 2017 22:31:55 -0400 Subject: [PATCH 5/5] SPRTF is now compatible with macOS and Linux, and most likely all supported platforms. --- CMakeLists.txt | 36 ++++++++++++++++-------------------- console/tidy.c | 10 +++++----- include/tidy.h | 14 ++++++-------- include/tidyplatform.h | 7 +++++++ src/alloc.c | 8 ++++---- src/language.h | 8 ++++---- src/message.h | 2 +- src/pprint.c | 20 +++++++++----------- src/sprtf.h | 14 +++++++------- src/tags.c | 7 ++----- src/tidylib.c | 12 +++++------- 11 files changed, 66 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2508b1a..778253c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,21 +142,22 @@ endif () # NOTE: Currently only available in the Debug configuration build in # Windows, but could be maybe extended to Unix, others... #------------------------------------------------------------------------ +option( ENABLE_ALLOC_DEBUG "Set ON to output node allocation diagnostics." OFF ) +option( ENABLE_MEMORY_DEBUG "Set ON to output some memory diagnostics." OFF ) + +if (ENABLE_ALLOC_DEBUG) + add_definitions ( -DDEBUG_ALLOCATION ) # see lexer.c for details + message(STATUS "*** Note, lexer.c node allocation diagnostics are ON") +endif () + + if (ENABLE_MEMORY_DEBUG) + add_definitions ( -DDEBUG_MEMORY ) # see alloc.c for details + message(STATUS "*** Note, alloc.c memory diagnostics are ON") + endif () + if (WIN32) - option( ENABLE_MEMORY_DEBUG "Set ON to output some memory diagnostics." OFF ) - option( ENABLE_ALLOC_DEBUG "Set ON to output node allocation diagnostics." OFF ) option( ENABLE_CRTDBG_MEMORY "Set ON to enable the Windows CRT debug library." OFF ) - if (ENABLE_MEMORY_DEBUG) - add_definitions ( -DDEBUG_MEMORY ) # see alloc.c for details - message(STATUS "*** Note, alloc.c memory diagnostics are ON") - endif () - - if (ENABLE_ALLOC_DEBUG) - add_definitions ( -DDEBUG_ALLOCATION ) # see lexer.c for details - message(STATUS "*** Note, lexer.c node allocation diagnostics are ON") - endif () - if (ENABLE_CRTDBG_MEMORY) add_definitions ( -D_CRTDBG_MAP_ALLOC ) # see tidy.c for details message(STATUS "*** Note, tidy.c Windows CRT memory debug is ON") @@ -334,7 +335,7 @@ set ( CFILES ${SRCDIR}/buffio.c ${SRCDIR}/fileio.c ${SRCDIR}/streamio.c ${SRCDIR}/tagask.c ${SRCDIR}/tmbstr.c ${SRCDIR}/utf8.c ${SRCDIR}/tidylib.c ${SRCDIR}/mappedio.c ${SRCDIR}/gdoc.c - ${SRCDIR}/language.c ${SRCDIR}/messageobj.c ) + ${SRCDIR}/language.c ${SRCDIR}/messageobj.c ${SRCDIR}/sprtf.c ) set ( HFILES ${INCDIR}/tidyplatform.h ${INCDIR}/tidy.h ${INCDIR}/tidyenum.h @@ -352,13 +353,8 @@ set ( LIBHFILES ${SRCDIR}/pprint.h ${SRCDIR}/streamio.h ${SRCDIR}/tags.h ${SRCDIR}/tmbstr.h ${SRCDIR}/utf8.h ${SRCDIR}/tidy-int.h ${SRCDIR}/version.h ${SRCDIR}/gdoc.h ${SRCDIR}/language.h - ${SRCDIR}/language_en.h ) - -if (MSVC) - list(APPEND CFILES ${SRCDIR}/sprtf.c) - list(APPEND LIBHFILES ${SRCDIR}/sprtf.h) -endif () - + ${SRCDIR}/language_en.h ${SRCDIR}/sprtf.h ) + #------------------------------------------------------------------------ # Target Locations diff --git a/console/tidy.c b/console/tidy.c index 507baac..000dee1 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -25,13 +25,13 @@ #if defined(_WIN32) # include /* Force console to UTF8. */ #endif -#if !defined(NDEBUG) && defined(_MSC_VER) -# ifdef _CRTDBG_MAP_ALLOC -# include -# include -# endif +#if !defined(NDEBUG) && defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC) +# include +# include #endif +#include "sprtf.h" + /** Tidy will send errors to this file, which will be stderr later. */ static FILE* errout = NULL; diff --git a/include/tidy.h b/include/tidy.h index 3b5762a..365c70d 100644 --- a/include/tidy.h +++ b/include/tidy.h @@ -1418,10 +1418,8 @@ TIDY_EXPORT double TIDY_CALL tidyGetArgValueDouble(TidyMessage tmessage, /**< ** Your callback function will be provided with the following parameters. ** @param tdoc Indicates the source tidy document. ** @param line Indicates the line in the source document at this point in the process. - ** @param column Indicates the column in the source document at this point in the process. + ** @param col Indicates the column in the source document at this point in the process. ** @param destLine Indicates the line number in the output document at this point in the process. - ** @return Your callback function will return `yes` if Tidy should include the - ** report in its own output sink, or `no` if Tidy should suppress it. */ typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine ); @@ -1898,7 +1896,7 @@ TIDY_EXPORT uint TIDY_CALL tidyErrorCodeFromKey(ctmbstr code); ** @result Returns a TidyIterator, which is a token used to represent the ** current position in a list within LibTidy. */ -TIDY_EXPORT TidyIterator TIDY_CALL getErrorCodeList(); +TIDY_EXPORT TidyIterator TIDY_CALL getErrorCodeList(void); /** Given a valid TidyIterator initiated with getErrorCodeList(), returns ** an instance of the opaque type TidyMessageArgument, which serves as a token @@ -1946,7 +1944,7 @@ TIDY_EXPORT Bool TIDY_CALL tidySetLanguage( ctmbstr languageCode ); /** Gets the current language used by Tidy. ** @result Returns a string indicating the currently set language. */ -TIDY_EXPORT ctmbstr TIDY_CALL tidyGetLanguage(); +TIDY_EXPORT ctmbstr TIDY_CALL tidyGetLanguage(void); /** @} ** @name Locale Mappings @@ -1978,7 +1976,7 @@ opaque_type(tidyLocaleMapItem); ** @result Returns a TidyIterator, which is a token used to represent the ** current position in a list within LibTidy. */ -TIDY_EXPORT TidyIterator TIDY_CALL getWindowsLanguageList(); +TIDY_EXPORT TidyIterator TIDY_CALL getWindowsLanguageList(void); /** Given a valid TidyIterator initiated with getWindowsLanguageList(), returns ** a pointer to a tidyLocaleMapItem, which can be further interrogated with @@ -2046,7 +2044,7 @@ TIDY_EXPORT ctmbstr TIDY_CALL tidyDefaultString( uint messageType ); ** @result Returns a TidyIterator, which is a token used to represent the ** current position in a list within LibTidy. */ -TIDY_EXPORT TidyIterator TIDY_CALL getStringKeyList(); +TIDY_EXPORT TidyIterator TIDY_CALL getStringKeyList(void); /** Given a valid TidyIterator initiated with getStringKeyList(), returns ** an unsigned integer representing the next key value. @@ -2076,7 +2074,7 @@ TIDY_EXPORT uint TIDY_CALL getNextStringKey( TidyIterator* iter ); ** @result Returns a TidyIterator, which is a token used to represent the ** current position in a list within LibTidy. */ -TIDY_EXPORT TidyIterator TIDY_CALL getInstalledLanguageList(); +TIDY_EXPORT TidyIterator TIDY_CALL getInstalledLanguageList(void); /** Given a valid TidyIterator initiated with getInstalledLanguageList(), ** returns a string representing a language name that is installed in Tidy. diff --git a/include/tidyplatform.h b/include/tidyplatform.h index 5fa7cb7..f4842ef 100644 --- a/include/tidyplatform.h +++ b/include/tidyplatform.h @@ -654,7 +654,14 @@ opaque_type( TidyIterator ); /*============================================================================= * Debugging + * When building and not defining the NDEBUG 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 *===========================================================================*/ + #if !defined(NDEBUG) # include "sprtf.h" #endif diff --git a/src/alloc.c b/src/alloc.c index 17a1227..59aef73 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -15,7 +15,7 @@ static TidyRealloc g_realloc = NULL; static TidyFree g_free = NULL; static TidyPanic g_panic = NULL; -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) +#if !defined(NDEBUG) && defined(DEBUG_MEMORY) static int alloccnt = 0; static int realloccnt = 0; static int freecnt = 0; @@ -63,7 +63,7 @@ static void* TIDY_CALL defaultAlloc( TidyAllocator* allocator, size_t size ) void *p = ( g_malloc ? g_malloc(size) : malloc(size) ); if ( !p ) defaultPanic( allocator,"Out of memory!"); -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) +#if !defined(NDEBUG) && defined(DEBUG_MEMORY) alloccnt++; SPRTF("%d: alloc MEM %p, size %d\n", alloccnt, p, (int)size ); if (size == 0) { @@ -82,7 +82,7 @@ static void* TIDY_CALL defaultRealloc( TidyAllocator* allocator, void* mem, size p = ( g_realloc ? g_realloc(mem, newsize) : realloc(mem, newsize) ); if (!p) defaultPanic( allocator, "Out of memory!"); -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) +#if !defined(NDEBUG) && defined(DEBUG_MEMORY) realloccnt++; SPRTF("%d: realloc MEM %p, size %d\n", realloccnt, p, (int)newsize ); #endif @@ -93,7 +93,7 @@ static void TIDY_CALL defaultFree( TidyAllocator* ARG_UNUSED(allocator), void* m { if ( mem ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) +#if !defined(NDEBUG) && defined(DEBUG_MEMORY) freecnt++; SPRTF("%d: free MEM %p\n", freecnt, mem ); #endif diff --git a/src/language.h b/src/language.h index 5419df6..12991eb 100644 --- a/src/language.h +++ b/src/language.h @@ -113,7 +113,7 @@ Bool TY_(tidySetLanguage)( ctmbstr languageCode ); /** * Gets the current language used by Tidy. */ -ctmbstr TY_(tidyGetLanguage)(); +ctmbstr TY_(tidyGetLanguage)(void); /** * Provides a string given `messageType` in the current @@ -145,7 +145,7 @@ ctmbstr TY_(tidyDefaultString)( uint messageType ); * these are provided for documentation generation purposes * and probably aren't useful for LibTidy implementors. */ -TidyIterator TY_(getStringKeyList)(); +TidyIterator TY_(getStringKeyList)(void); /* * Provides the next key value in Tidy's list of localized @@ -160,7 +160,7 @@ uint TY_(getNextStringKey)( TidyIterator* iter ); * in Tidy's structure of Windows<->POSIX local mapping. * Items can be retrieved with getNextWindowsLanguage(); */ -TidyIterator TY_(getWindowsLanguageList)(); +TidyIterator TY_(getWindowsLanguageList)(void); /** * Returns the next record of type `localeMapItem` in @@ -183,7 +183,7 @@ const ctmbstr TY_(TidyLangPosixName)( const tidyLocaleMapItemImpl *item ); * in Tidy's list of installed language codes. * Items can be retrieved with getNextInstalledLanguage(); */ -TidyIterator TY_(getInstalledLanguageList)(); +TidyIterator TY_(getInstalledLanguageList)(void); /** * Returns the next installed language. diff --git a/src/message.h b/src/message.h index f12ee95..4871e10 100644 --- a/src/message.h +++ b/src/message.h @@ -213,7 +213,7 @@ uint TY_(tidyErrorCodeFromKey)(ctmbstr code); * `TidyReportFilter3`. * Items can be retrieved with getNextErrorCode(); */ -TidyIterator TY_(getErrorCodeList)(); +TidyIterator TY_(getErrorCodeList)(void); /** * Returns the next error code having initialized the iterator diff --git a/src/pprint.c b/src/pprint.c index a085463..d371507 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -18,12 +18,10 @@ #include "utf8.h" /* *** FOR DEBUG ONLY *** */ -#if !defined(NDEBUG) && defined(_MSC_VER) /* #define DEBUG_PPRINT */ /* #define DEBUG_INDENT */ -# ifdef DEBUG_PPRINT +#if !defined(NDEBUG) && defined(DEBUG_PPRINT) extern void dbg_show_node( TidyDocImpl* doc, Node *node, int caller, int indent ); -# endif #endif /* @@ -616,7 +614,7 @@ static Bool CheckWrapIndent( TidyDocImpl* doc, uint indent ) WrapLine( doc ); if ( pprint->indent[ 0 ].spaces < 0 ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; @@ -680,7 +678,7 @@ void TY_(PFlushLine)( TidyDocImpl* doc, uint indent ) if (pprint->indent[ 0 ].spaces != (int)indent ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; @@ -702,7 +700,7 @@ static void PCondFlushLine( TidyDocImpl* doc, uint indent ) /* Issue #390 - Whether chars to flush or not, set new indent */ if ( pprint->indent[ 0 ].spaces != (int)indent ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; @@ -730,7 +728,7 @@ void TY_(PFlushLineSmart)( TidyDocImpl* doc, uint indent ) if ( pprint->indent[ 0 ].spaces != (int)indent ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; @@ -759,7 +757,7 @@ static void PCondFlushLineSmart( TidyDocImpl* doc, uint indent ) \*/ if (pprint->indent[ 0 ].spaces != (int)indent) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; @@ -1947,7 +1945,7 @@ void PPrintScriptStyle( TidyDocImpl* doc, uint mode, uint indent, Node *node ) if ( node->content && pprint->indent[ 0 ].spaces != (int)indent ) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; @@ -2055,7 +2053,7 @@ void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node ) doc->progressCallback( tidyImplToDoc(doc), node->line, node->column, doc->pprint.line + 1 ); } -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_PPRINT) +#if !defined(NDEBUG) && defined(DEBUG_PPRINT) dbg_show_node( doc, node, 4, GetSpaces( &doc->pprint ) ); #endif @@ -2315,7 +2313,7 @@ void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node ) TidyPrintImpl* pprint = &doc->pprint; if (pprint->indent[ 0 ].spaces != (int)indent) { -#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_INDENT) +#if !defined(NDEBUG) && defined(DEBUG_INDENT) SPRTF("%s Indent from %d to %d\n", __FUNCTION__, pprint->indent[ 0 ].spaces, indent ); #endif pprint->indent[ 0 ].spaces = indent; diff --git a/src/sprtf.h b/src/sprtf.h index c589707..322009c 100644 --- a/src/sprtf.h +++ b/src/sprtf.h @@ -43,20 +43,20 @@ TIDY_EXPORT int add_append_log( int val ); TIDY_EXPORT int open_log_file( void ); TIDY_EXPORT void close_log_file( void ); -TIDY_EXPORT void set_log_file( char * nf, int open ); /* used */ -TIDY_EXPORT char * get_log_file( void ); /* used */ +TIDY_EXPORT void set_log_file( char * nf, int open ); +TIDY_EXPORT char * get_log_file( void ); -TIDY_EXPORT int MCDECL sprtf( const char *pf, ... ); /* used */ +TIDY_EXPORT int MCDECL sprtf( const char *pf, ... ); #define M_MAX_SPRTF 2048 TIDY_EXPORT int direct_out_it( char *cp ); -TIDY_EXPORT char *GetNxtBuf(); +TIDY_EXPORT char *GetNxtBuf(void); #define EndBuf(a) ( a + strlen(a) ) -TIDY_EXPORT char *get_date_stg(); -TIDY_EXPORT char *get_time_stg(); -TIDY_EXPORT char *get_date_time_stg(); +TIDY_EXPORT char *get_date_stg(void); +TIDY_EXPORT char *get_time_stg(void); +TIDY_EXPORT char *get_date_time_stg(void); #ifdef _MSC_VER TIDY_EXPORT int gettimeofday(struct timeval *tp, void *tzp); diff --git a/src/tags.c b/src/tags.c index 81d67a8..f965177 100644 --- a/src/tags.c +++ b/src/tags.c @@ -473,10 +473,7 @@ static void declare( TidyDocImpl* doc, TidyTagImpl* tags, } } -#if !defined(NDEBUG) && defined(_MSC_VER) -/* ==================================================================== - MSVC DEBUG ONLY - */ +#if !defined(NDEBUG) void ListElementsPerVersion( uint vers, Bool has ) { uint val, cnt, total, wrap = 10; @@ -522,7 +519,7 @@ void show_have_html5(void) ListElementsPerVersion( VERS_HTML5, yes ); } -#endif +#endif /* !defined(NDEBUG) */ /* public interface for finding tag by name */ Bool TY_(FindTag)( TidyDocImpl* doc, Node *node ) diff --git a/src/tidylib.c b/src/tidylib.c index 9befcba..d433edc 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -1405,7 +1405,7 @@ void tidyDocReportDoctype( TidyDocImpl* doc ) /***************************************************************************** * HTML5 STUFF *****************************************************************************/ -#if !defined(NDEBUG) && defined(_MSC_VER) +#if 0 && !defined(NDEBUG) extern void show_not_html5(void); /* ----------------------------- List tags that do not have version HTML5 (HT50|XH50) @@ -1504,9 +1504,7 @@ void TY_(CheckHTML5)( TidyDocImpl* doc, Node* node ) Bool warn = yes; /* should this be a warning, error, or report??? */ AttVal* attr = NULL; int i = 0; -#if !defined(NDEBUG) && defined(_MSC_VER) - // list_not_html5(); -#endif + while (node) { if ( nodeHasAlignAttr( node ) ) { @@ -1782,7 +1780,7 @@ void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node ) } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) /* *** FOR DEBUG ONLY *** */ const char *dbg_get_lexer_type( void *vp ) { @@ -1919,7 +1917,7 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc ) Bool mergeEmphasis = cfgBool( doc, TidyMergeEmphasis ); Node* node; -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("All nodes BEFORE clean and repair\n"); dbg_show_all_nodes( doc, &doc->root, 0 ); #endif @@ -2037,7 +2035,7 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc ) } } -#if !defined(NDEBUG) && defined(_MSC_VER) +#if !defined(NDEBUG) SPRTF("All nodes AFTER clean and repair\n"); dbg_show_all_nodes( doc, &doc->root, 0 ); #endif