SPRTF is now compatible with macOS and Linux, and most likely all supported

platforms.
This commit is contained in:
Jim Derry 2017-10-03 22:31:55 -04:00
parent ee54057d76
commit dedcb7bb4d
11 changed files with 66 additions and 72 deletions

View File

@ -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

View File

@ -25,13 +25,13 @@
#if defined(_WIN32)
# include <windows.h> /* Force console to UTF8. */
#endif
#if !defined(NDEBUG) && defined(_MSC_VER)
# ifdef _CRTDBG_MAP_ALLOC
# include <stdlib.h>
# include <crtdbg.h>
# endif
#if !defined(NDEBUG) && defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC)
# include <stdlib.h>
# include <crtdbg.h>
#endif
#include "sprtf.h"
/** Tidy will send errors to this file, which will be stderr later. */
static FILE* errout = NULL;

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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 )

View File

@ -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