diff --git a/CMakeLists.txt b/CMakeLists.txt index b83fcc5..d8d18dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,6 +336,9 @@ set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://www.html-tidy.org/") #set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc") set(CPACK_DEBIAN_PACKAGE_SECTION "Libraries") +## RPM config +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/share/man" "/usr/share/man/man1") + set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test/;${CMAKE_CURRENT_SOURCE_DIR}/build/;${CMAKE_CURRENT_SOURCE_DIR}/.git/") if (NOT WIN32 AND NOT APPLE) diff --git a/include/tidy.h b/include/tidy.h index f20e12d..0eeabca 100755 --- a/include/tidy.h +++ b/include/tidy.h @@ -744,9 +744,13 @@ TIDY_EXPORT int TIDY_CALL tidySaveStdout( TidyDoc tdoc ); /** Save to given TidyBuffer object */ TIDY_EXPORT int TIDY_CALL tidySaveBuffer( TidyDoc tdoc, TidyBuffer* buf ); -/** Save document to application buffer. If buffer is not big enough, -** ENOMEM will be returned and the necessary buffer size will be placed -** in *buflen. +/** Save document to application buffer. If TidyShowMarkup and +** the document has no errors, or TidyForceOutput, the current +** document, per the current configuration, will be Pretty Printed +** to the application buffer. The document byte length, +** not character length, will be placed in *buflen. The document +** will not be null terminated. If the buffer is not big enough, +** ENOMEM will be returned, else the actual document status. */ TIDY_EXPORT int TIDY_CALL tidySaveString( TidyDoc tdoc, tmbstr buffer, uint* buflen ); diff --git a/src/istack.c b/src/istack.c index afa6c73..dc708e4 100644 --- a/src/istack.c +++ b/src/istack.c @@ -10,6 +10,9 @@ #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) @@ -115,6 +118,7 @@ static void PopIStack( TidyDocImpl* doc ) TY_(FreeAttribute)( doc, av ); } TidyDocFree(doc, istack->element); + istack->element = NULL; /* remove the freed element */ } static void PopIStackUntil( TidyDocImpl* doc, TidyTagId tid ) @@ -267,9 +271,12 @@ Node *TY_(InsertedToken)( TidyDocImpl* doc ) node->end = lexer->txtend; /* was : lexer->txtstart; */ istack = lexer->insert; -#if 0 && defined(_DEBUG) +/* #if 0 && defined(_DEBUG) */ +#if !defined(NDEBUG) && defined(_MSC_VER) if ( lexer->istacksize == 0 ) - fprintf( stderr, "0-size istack!\n" ); + { + SPRTF( "WARNING: ZERO sized istack!\n" ); + } #endif node->element = TY_(tmbstrdup)(doc->allocator, istack->element); diff --git a/src/lexer.c b/src/lexer.c index 24b2343..23baf34 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -52,7 +52,7 @@ static void check_me(char *name); static Bool show_attrs = yes; #define MX_TXT 8 -static char buffer[MX_TXT+8]; /* NOTE extra for '...'\0 tail */ +static char buffer[(MX_TXT*4)+8]; /* NOTE extra for '...'\0 tail */ static tmbstr get_text_string(Lexer* lexer, Node *node) { uint len = node->end - node->start; @@ -61,31 +61,74 @@ static tmbstr get_text_string(Lexer* lexer, Node *node) unsigned char c; uint i = 0; Bool insp = no; - buffer[0] = (char)0; - while (cp < end ) { - c = *cp; - if (c == '\n') { - buffer[i++] = '\\'; - buffer[i++] = 'n'; - insp = yes; - } else if (c == ' ') { - if (!insp) + if (len <= ((MX_TXT * 2) + 3)) { + buffer[0] = 0; + while (cp < end) { + c = *cp; + cp++; + if (c == '\n') { + buffer[i++] = '\\'; + buffer[i++] = 'n'; + } else if ( c == ' ' ) { + if (!insp) + buffer[i++] = c; + insp = yes; + } else { buffer[i++] = c; - insp = yes; - } else { - buffer[i++] = c; - insp = no; + insp = no; + } } - cp++; - if (i >= MX_TXT) - break; - } - if (i < len) { - buffer[i++] = '.'; - if (i < len) { - buffer[i++] = '.'; - if (i < len) { - buffer[i++] = '.'; + } else { + char *end1 = cp + MX_TXT; + char *bgn = cp + (len - MX_TXT); + buffer[0] = 0; + if (bgn < end1) + bgn = end1; + while (cp < end1) { + c = *cp; + cp++; + if (c == '\n') { + buffer[i++] = '\\'; + buffer[i++] = 'n'; + } else if ( c == ' ' ) { + if (!insp) + buffer[i++] = c; + insp = yes; + } else { + buffer[i++] = c; + insp = no; + } + if (i >= MX_TXT) + break; + } + c = '.'; + if ((i < len)&&(cp < bgn)) { + buffer[i++] = c; + cp++; + if ((i < len)&&(cp < bgn)) { + buffer[i++] = c; + cp++; + if ((i < len)&&(cp < bgn)) { + buffer[i++] = c; + cp++; + } + } + } + cp = bgn; + insp = no; + while (cp < end) { + c = *cp; + cp++; + if (c == '\n') { + buffer[i++] = '\\'; + buffer[i++] = 'n'; + } else if ( c == ' ' ) { + if (!insp) + buffer[i++] = c; + insp = yes; + } else { + buffer[i++] = c; + insp = no; } } } @@ -101,7 +144,7 @@ static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node ) tmbstr src = lex ? "lexer" : "stream"; SPRTF("R=%d C=%d: ", line, col ); // DEBUG: Be able to set a TRAP on a SPECIFIC row,col - if ((line == 8) && (col == 36)) { + if ((line == 67) && (col == 95)) { check_me("Show_Node"); // just a debug trap } if (lexer && lexer->token && @@ -2265,8 +2308,11 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode ) assert( !(lexer->pushed || lexer->itoken) ); /* at start of block elements, unclosed inline - elements are inserted into the token stream */ - if (lexer->insert || lexer->inode) { + elements are inserted into the token stream + Issue #341 - Can NOT insert a token if NO istacksize + */ + if ((lexer->insert || lexer->inode) && lexer->istacksize) + { /*\ Issue #92: could fix by the following, but instead chose not to stack these 2 * if ( !(lexer->insert && (nodeIsINS(lexer->insert) || nodeIsDEL(lexer->insert))) ) { \*/