From fd7b4f858927b019918b1752b8db7c7df7dd258a Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Fri, 6 Mar 2015 19:28:52 +0100 Subject: [PATCH] just some more DEBUG on text nodes --- src/lexer.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lexer.c b/src/lexer.c index ad6a876..91b1e13 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -49,6 +49,33 @@ #if !defined(NDEBUG) && defined(_MSC_VER) static Bool show_attrs = yes; +#define MX_TXT 5 +static char buffer[MX_TXT+8]; /* NOTE extra for '...'\0 tail */ +static tmbstr get_text_string(Lexer* lexer, Node *node) +{ + uint len = node->end - node->start; + tmbstr cp = lexer->lexbuf + node->start; + tmbstr end = lexer->lexbuf + node->end; + uint i = 0; + buffer[0] = (char)0; + while (cp < end ) { + buffer[i++] = *cp; + cp++; + if (i >= MX_TXT) + break; + } + if (i < len) { + buffer[i++] = '.'; + if (i < len) { + buffer[i++] = '.'; + if (i < len) { + buffer[i++] = '.'; + } + } + } + buffer[i] = 0; + return buffer; +} static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node ) { Lexer* lexer = doc->lexer; @@ -58,7 +85,9 @@ static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node ) SPRTF("R=%d C=%d: ", line, col ); if (lexer && lexer->token && (lexer->token->type == TextNode)) { if (show_attrs) { - SPRTF("Returning %s TextNode ... %s\n", msg, + uint len = node->end - node->start; + tmbstr cp = get_text_string( lexer, node ); + SPRTF("Returning %s TextNode [%s]%u %s\n", msg, cp, len, lex ? "lexer" : "stream"); } else { SPRTF("Returning %s TextNode %p... %s\n", msg, node,