Skip to content

Commit d091027

Browse files
committed
Issue #377 add debug only output of constrained versions
1 parent 1dd06aa commit d091027

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

src/lexer.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,105 @@ static uint GetVersFromFPI(ctmbstr fpi)
326326
return 0;
327327
}
328328

329+
#if (defined(_MSC_VER) && !defined(NDEBUG))
330+
/* Issue #377 - Output diminishing version bits */
331+
typedef struct tagV2S {
332+
uint bit;
333+
ctmbstr val;
334+
}V2S, *PV2S;
335+
336+
static V2S v2s[] = {
337+
{ HT20, "HT20" },
338+
{ HT32, "HT32" },
339+
{ H40S, "H40S" },
340+
{ H40T, "H40T" },
341+
{ H40F, "H40F" },
342+
{ H41S, "H41S" },
343+
{ H41T, "H41T" },
344+
{ H41F, "H41F" },
345+
{ X10S, "X10S" },
346+
{ X10T, "X10T" },
347+
{ X10F, "X10F" },
348+
{ XH11, "XH11" },
349+
{ XB10, "XB10" }, /* 4096u */
350+
/* { VERS_SUN, "VSUN" }, */
351+
/* { VERS_NETSCAPE, "VNET" },
352+
/* { VERS_MICROSOFT, "VMIC" }, 32768u */
353+
{ VERS_XML, "VXML" }, /* 65536u */
354+
/* HTML5 */
355+
{ HT50, "HT50" }, /* 131072u */
356+
{ XH50, "XH50" }, /* 262144u */
357+
{ 0, 0 }
358+
};
359+
360+
/* Process the above table, adding a bit name,
361+
or '----' when not present */
362+
static char *add_vers_string( tmbstr buf, uint vers )
363+
{
364+
PV2S pv2s = v2s;
365+
int len = (int)strlen(buf);
366+
while (pv2s->val) {
367+
if (vers & pv2s->bit) {
368+
if (len) {
369+
strcat(buf,"|");
370+
len++;
371+
}
372+
strcat(buf,pv2s->val);
373+
len += (int)strlen(pv2s->val);
374+
vers &= ~(pv2s->bit);
375+
if (!vers)
376+
break;
377+
} else {
378+
if (len) {
379+
strcat(buf,"|");
380+
len++;
381+
}
382+
strcat(buf,"----");
383+
len += 4;
384+
385+
}
386+
pv2s++;
387+
}
388+
if (vers) { /* Should not have any here! */
389+
if (len)
390+
strcat(buf,"|");
391+
sprintf(EndBuf(buf),"%u",vers);
392+
}
393+
return buf;
394+
395+
}
396+
397+
/* Issue #377 - Show first Before: list, and then on any change
398+
Note the VERS_PROPRIETARY are exclude since they always remain */
399+
void TY_(ConstrainVersion)(TidyDocImpl* doc, uint vers)
400+
{
401+
static char vcur[256];
402+
static Bool dnfirst = no;
403+
uint curr = doc->lexer->versions; /* get current */
404+
doc->lexer->versions &= (vers | VERS_PROPRIETARY);
405+
if (curr != doc->lexer->versions) { /* only if different */
406+
if (!dnfirst) {
407+
dnfirst = yes;
408+
vcur[0] = 0;
409+
curr &= ~(VERS_PROPRIETARY);
410+
add_vers_string( vcur, curr );
411+
SPRTF("Before: %s\n", vcur);
412+
}
413+
vcur[0] = 0;
414+
curr = doc->lexer->versions;
415+
curr &= ~(VERS_PROPRIETARY);
416+
add_vers_string( vcur, curr );
417+
SPRTF("After : %s\n", vcur);
418+
}
419+
}
420+
#else /* !#if (defined(_MSC_VER) && !defined(NDEBUG)) */
329421
/* everything is allowed in proprietary version of HTML */
330422
/* this is handled here rather than in the tag/attr dicts */
331423
void TY_(ConstrainVersion)(TidyDocImpl* doc, uint vers)
332424
{
333425
doc->lexer->versions &= (vers | VERS_PROPRIETARY);
334426
}
427+
#endif /* #if (defined(_MSC_VER) && !defined(NDEBUG)) y/n */
335428

336429
Bool TY_(IsWhite)(uint c)
337430
{

0 commit comments

Comments
 (0)