Purged TIDY_STORE_ORIGINAL_TEXT.

This commit is contained in:
Jim Derry 2017-10-03 14:18:49 -04:00
parent 9679d88fae
commit 9706b9e5c4
5 changed files with 2 additions and 161 deletions

View file

@ -1539,10 +1539,6 @@ void TY_(FreeNode)( TidyDocImpl* doc, Node *node )
TY_(FreeAttrs)( doc, node );
TY_(FreeNode)( doc, node->content );
TidyDocFree( doc, node->element );
#ifdef TIDY_STORE_ORIGINAL_TEXT
if (node->otext)
TidyDocFree(doc, node->otext);
#endif
if (RootNode != node->type)
TidyDocFree( doc, node );
else
@ -1552,53 +1548,6 @@ void TY_(FreeNode)( TidyDocImpl* doc, Node *node )
}
}
#ifdef TIDY_STORE_ORIGINAL_TEXT
void StoreOriginalTextInToken(TidyDocImpl* doc, Node* node, uint count)
{
if (!doc->storeText)
return;
if (count >= doc->docIn->otextlen)
return;
if (!doc->docIn->otextsize)
return;
if (count == 0)
{
node->otext = doc->docIn->otextbuf;
doc->docIn->otextbuf = NULL;
doc->docIn->otextlen = 0;
doc->docIn->otextsize = 0;
}
else
{
uint len = doc->docIn->otextlen;
tmbstr buf1 = (tmbstr)TidyDocAlloc(doc, len - count + 1);
tmbstr buf2 = (tmbstr)TidyDocAlloc(doc, count + 1);
uint i, j;
/* strncpy? */
for (i = 0; i < len - count; ++i)
buf1[i] = doc->docIn->otextbuf[i];
buf1[i] = 0;
for (j = 0; j + i < len; ++j)
buf2[j] = doc->docIn->otextbuf[j + i];
buf2[j] = 0;
TidyDocFree(doc, doc->docIn->otextbuf);
node->otext = buf1;
doc->docIn->otextbuf = buf2;
doc->docIn->otextlen = count;
doc->docIn->otextsize = count + 1;
}
}
#endif
Node* TY_(TextToken)( Lexer *lexer )
{
Node *node = TY_(NewNode)( lexer->allocator, lexer );
@ -1651,9 +1600,6 @@ static Node* NewToken(TidyDocImpl* doc, NodeType type)
node->type = type;
node->start = lexer->txtstart;
node->end = lexer->txtend;
#ifdef TIDY_STORE_ORIGINAL_TEXT
StoreOriginalTextInToken(doc, node, 0);
#endif
return node;
}
@ -2454,17 +2400,8 @@ void TY_(UngetToken)( TidyDocImpl* doc )
doc->lexer->pushed = yes;
}
#ifdef TIDY_STORE_ORIGINAL_TEXT
#define CondReturnTextNode(doc, skip) \
if (lexer->txtend > lexer->txtstart) \
{ \
lexer->token = TY_(TextToken)(lexer); \
StoreOriginalTextInToken(doc, lexer->token, skip); \
return lexer->token; \
}
#else
#if !defined(NDEBUG) && defined(_MSC_VER)
#define CondReturnTextNode(doc, skip) \
# define CondReturnTextNode(doc, skip) \
if (lexer->txtend > lexer->txtstart) { \
Node *_node = TY_(TextToken)(lexer); \
lexer->token = _node; \
@ -2473,14 +2410,13 @@ void TY_(UngetToken)( TidyDocImpl* doc )
}
#else
#define CondReturnTextNode(doc, skip) \
# define CondReturnTextNode(doc, skip) \
if (lexer->txtend > lexer->txtstart) \
{ \
lexer->token = TY_(TextToken)(lexer); \
return lexer->token; \
}
#endif
#endif
/*
modes for GetToken()
@ -2695,9 +2631,6 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
lexer->txtend = lexer->lexsize;
}
lexer->token = TY_(TextToken)(lexer);
#ifdef TIDY_STORE_ORIGINAL_TEXT
StoreOriginalTextInToken(doc, lexer->token, 3);
#endif
node = lexer->token;
GTDBG(doc,"text", node);
return node;
@ -2925,9 +2858,6 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
lexer->state = LEX_CONTENT;
lexer->waswhite = no;
#ifdef TIDY_STORE_ORIGINAL_TEXT
StoreOriginalTextInToken(doc, lexer->token, 0); /* hmm... */
#endif
node = lexer->token;
GTDBG(doc,"endtag", node);
return node; /* the endtag token */
@ -3008,9 +2938,6 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
TY_(RepairDuplicateAttributes)( doc, lexer->token, no );
} else
TY_(RepairDuplicateAttributes)( doc, lexer->token, yes );
#ifdef TIDY_STORE_ORIGINAL_TEXT
StoreOriginalTextInToken(doc, lexer->token, 0);
#endif
node = lexer->token;
GTDBG(doc,"starttag", node);
return node; /* return start tag */
@ -3475,9 +3402,6 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
lexer->txtend = lexer->lexsize;
}
lexer->token = TY_(TextToken)(lexer);
#ifdef TIDY_STORE_ORIGINAL_TEXT
StoreOriginalTextInToken(doc, lexer->token, 0); /* ? */
#endif
node = lexer->token;
GTDBG(doc,"textstring", node);
return node; /* the textstring token */
@ -4403,9 +4327,6 @@ static Node *ParseDocTypeDecl(TidyDocImpl* doc)
TY_(FreeNode)(doc, node);
return NULL;
}
#ifdef TIDY_STORE_ORIGINAL_TEXT
StoreOriginalTextInToken(doc, node, 0);
#endif
return node;
}
else

View file

@ -317,10 +317,6 @@ struct _Node
Bool closed; /* true if closed by explicit end tag */
Bool implicit; /* true if inferred */
Bool linebreak; /* true if followed by a line break */
#ifdef TIDY_STORE_ORIGINAL_TEXT
tmbstr otext;
#endif
};

View file

@ -110,20 +110,11 @@ StreamIn* TY_(initStreamIn)( TidyDocImpl* doc, int encoding )
in->allocator = doc->allocator;
in->charbuf = (tchar*)TidyDocAlloc(doc, sizeof(tchar) * in->bufsize);
InitLastPos( in );
#ifdef TIDY_STORE_ORIGINAL_TEXT
in->otextbuf = NULL;
in->otextlen = 0;
in->otextsize = 0;
#endif
return in;
}
void TY_(freeStreamIn)(StreamIn* in)
{
#ifdef TIDY_STORE_ORIGINAL_TEXT
if (in->otextbuf)
TidyFree(in->allocator, in->otextbuf);
#endif
TidyFree(in->allocator, in->charbuf);
TidyFree(in->allocator, in);
}
@ -222,40 +213,6 @@ int TY_(ReadBOMEncoding)(StreamIn *in)
return -1;
}
#ifdef TIDY_STORE_ORIGINAL_TEXT
void TY_(AddByteToOriginalText)(StreamIn *in, tmbchar c)
{
if (in->otextlen + 1 >= in->otextsize)
{
size_t size = in->otextsize ? 1 : 2;
in->otextbuf = TidyRealloc(in->allocator, in->otextbuf, in->otextsize + size);
in->otextsize += size;
}
in->otextbuf[in->otextlen++] = c;
in->otextbuf[in->otextlen ] = 0;
}
void TY_(AddCharToOriginalText)(StreamIn *in, tchar c)
{
int i, err, count = 0;
tmbchar buf[10] = {0};
err = TY_(EncodeCharToUTF8Bytes)(c, buf, NULL, &count);
if (err)
{
/* replacement character 0xFFFD encoded as UTF-8 */
buf[0] = (byte) 0xEF;
buf[1] = (byte) 0xBF;
buf[2] = (byte) 0xBD;
count = 3;
}
for (i = 0; i < count; ++i)
TY_(AddByteToOriginalText)(in, buf[i]);
}
#endif
static void InitLastPos( StreamIn *in )
{
in->curlastpos = 0;
@ -292,9 +249,6 @@ uint TY_(ReadChar)( StreamIn *in )
{
uint c = EndOfStream;
uint tabsize = cfg( in->doc, TidyTabSize );
#ifdef TIDY_STORE_ORIGINAL_TEXT
Bool added = no;
#endif
if ( in->pushed )
return PopChar( in );
@ -317,10 +271,6 @@ uint TY_(ReadChar)( StreamIn *in )
if (c == '\n')
{
#ifdef TIDY_STORE_ORIGINAL_TEXT
added = yes;
TY_(AddCharToOriginalText)(in, (tchar)c);
#endif
in->curcol = 1;
in->curline++;
break;
@ -328,10 +278,6 @@ uint TY_(ReadChar)( StreamIn *in )
if (c == '\t')
{
#ifdef TIDY_STORE_ORIGINAL_TEXT
added = yes;
TY_(AddCharToOriginalText)(in, (tchar)c);
#endif
in->tabs = tabsize > 0 ?
tabsize - ((in->curcol - 1) % tabsize) - 1
: 0;
@ -343,10 +289,6 @@ uint TY_(ReadChar)( StreamIn *in )
/* #427663 - map '\r' to '\n' - Andy Quick 11 Aug 00 */
if (c == '\r')
{
#ifdef TIDY_STORE_ORIGINAL_TEXT
added = yes;
TY_(AddCharToOriginalText)(in, (tchar)c);
#endif
c = ReadCharFromStream(in);
if (c != '\n')
{
@ -355,9 +297,6 @@ uint TY_(ReadChar)( StreamIn *in )
}
else
{
#ifdef TIDY_STORE_ORIGINAL_TEXT
TY_(AddCharToOriginalText)(in, (tchar)c);
#endif
}
in->curcol = 1;
in->curline++;
@ -477,11 +416,6 @@ uint TY_(ReadChar)( StreamIn *in )
break;
}
#ifdef TIDY_STORE_ORIGINAL_TEXT
if (!added)
TY_(AddCharToOriginalText)(in, (tchar)c);
#endif
return c;
}

View file

@ -83,12 +83,6 @@ struct _StreamIn
void* mlang;
#endif
#ifdef TIDY_STORE_ORIGINAL_TEXT
tmbstr otextbuf;
size_t otextsize;
uint otextlen;
#endif
/* Pointer back to document for error reporting */
TidyDocImpl* doc;
};

View file

@ -85,10 +85,6 @@ struct _TidyDocImpl
uint nClassId;
Bool inputHadBOM;
#ifdef TIDY_STORE_ORIGINAL_TEXT
Bool storeText;
#endif
#if PRESERVE_FILE_TIMES
struct utimbuf filetimes;
#endif