Skip to content

Commit f5bdede

Browse files
committed
Cleanup
- Added doxygen documentation to `tags.h` - Consistency to `tags.c` header. - Moved TY_(DeclareUserTag) to tags.c/.h for consistency with the other list parsing declaratory functions. - Merged user tags parsing into the general list, eliminating a lot of redundant code.
1 parent 7beb591 commit f5bdede

File tree

9 files changed

+386
-218
lines changed

9 files changed

+386
-218
lines changed

include/tidy.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ TIDY_EXPORT Bool TIDY_CALL tidySetOptionCallback(TidyDoc tdoc,
584584
);
585585

586586
/** This typedef represents the required signature for your provided callback
587-
** function should you wish to register one with tidySetOptionCallback().
587+
** function should you wish to register one with tidySetConfigCallback().
588588
** Your callback function will be provided with the following parameters.
589589
** @param tdoc The document instance for which the callback was invoked.
590590
** @param option The option name that was provided.
@@ -599,14 +599,33 @@ typedef Bool (TIDY_CALL *TidyConfigCallback)(TidyDoc tdoc, ctmbstr option, ctmbs
599599
** configuration file options. Setting this callback allows a LibTidy
600600
** application developer to examine command-line and configuration file options
601601
** after LibTidy has examined them and failed to recognize them.
602-
** Note that this is deprecated and you should instead migrate to
603-
** tidySetConfigCallback().
604602
** @result Returns `yes` upon success.
605603
*/
606604
TIDY_EXPORT Bool TIDY_CALL tidySetConfigCallback(TidyDoc tdoc, /**< The document to apply the callback to. */
607605
TidyConfigCallback pConfigCallback /**< The name of a function of type TidyConfigCallback() to serve as your callback. */
608606
);
609607

608+
609+
/** This typedef represents the required signature for your provided callback
610+
** function should you wish to register one with tidySetConfigChangeCallback().
611+
** Your callback function will be provided with the following parameters.
612+
** @param tdoc The document instance for which the callback was invoked.
613+
** @param option The option that will be changed.
614+
*/
615+
typedef void (TIDY_CALL *TidyConfigChangeCallback)(TidyDoc tdoc, TidyOption option);
616+
617+
/** Applications using TidyLib may want to be informed when changes to options
618+
** are made. Temporary changes made internally by Tidy are not reported, but
619+
** permanent changes made by Tidy (such as indent-spaces or output-encoding)
620+
** will be reported.
621+
** @note This callback is not currently implemented.
622+
** @result Returns `yes` upon success.
623+
*/
624+
TIDY_EXPORT Bool TIDY_CALL tidySetConfigChangeCallback(TidyDoc tdoc, /**< The document to apply the callback to. */
625+
TidyConfigChangeCallback pCallback /**< The name of a function of type TidyConfigChangeCallback() to serve as your callback. */
626+
);
627+
628+
610629
/** @}
611630
** @name Option ID Discovery
612631
** @{

src/attrs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,8 +2186,6 @@ static
21862186
AttVal *SortAttVal( TidyDocImpl* doc, AttVal *list, TidyAttrSortStrategy strat)
21872187
{
21882188
/* Get the list from the passed-in tidyDoc. */
2189-
// ctmbstr* priorityList = (ctmbstr*)doc->attribs.priorityAttribs.list;
2190-
// ctmbstr priorityList[] = { "id", NULL };
21912189
ctmbstr* priorityList = (ctmbstr*)doc->attribs.priorityAttribs.list;
21922190

21932191
ptAttValComparator ptComparator = GetAttValComparator(strat, priorityList);

src/config.c

Lines changed: 15 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ static ParseProperty ParseList;
157157
static ParseProperty ParseName;
158158
static ParseProperty ParseCSS1Selector;
159159
static ParseProperty ParseString;
160-
static ParseProperty ParseTagNames;
161160
static ParseProperty ParseCharEnc;
162161
static ParseProperty ParseDocType;
163162
static ParseProperty ParseTabs;
@@ -173,13 +172,13 @@ static const TidyOptionImpl option_defs[] =
173172
{ TidyAltText, MR, "alt-text", ST, 0, ParseString, NULL },
174173
{ TidyAnchorAsName, MR, "anchor-as-name", BL, yes, ParsePickList, &boolPicks },
175174
{ TidyAsciiChars, ME, "ascii-chars", BL, no, ParsePickList, &boolPicks },
176-
{ TidyBlockTags, MT, "new-blocklevel-tags", ST, 0, ParseTagNames, NULL },
175+
{ TidyBlockTags, MT, "new-blocklevel-tags", ST, 0, ParseList, NULL },
177176
{ TidyBodyOnly, DD, "show-body-only", IN, no, ParsePickList, &autoBoolPicks },
178177
{ TidyBreakBeforeBR, PP, "break-before-br", BL, no, ParsePickList, &boolPicks },
179178
{ TidyCharEncoding, CE, "char-encoding", IN, UTF8, ParseCharEnc, &charEncPicks },
180179
{ TidyCoerceEndTags, MR, "coerce-endtags", BL, yes, ParsePickList, &boolPicks },
181180
{ TidyCSSPrefix, MR, "css-prefix", ST, 0, ParseCSS1Selector, NULL, "c" },
182-
{ TidyCustomTags, IR, "new-custom-tags", ST, 0, ParseTagNames, NULL }, /* 20170309 - Issue #119 */
181+
{ TidyCustomTags, IR, "new-custom-tags", ST, 0, ParseList, NULL }, /* 20170309 - Issue #119 */
183182
{ TidyDecorateInferredUL, MX, "decorate-inferred-ul", BL, no, ParsePickList, &boolPicks },
184183
{ TidyDoctype, DT, "doctype", ST, 0, ParseDocType, &doctypePicks },
185184
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -193,7 +192,7 @@ static const TidyOptionImpl option_defs[] =
193192
#ifndef DOXYGEN_SHOULD_SKIP_THIS
194193
{ TidyEmacsFile, IR, "gnu-emacs-file", ST, 0, ParseString, NULL },
195194
#endif
196-
{ TidyEmptyTags, MT, "new-empty-tags", ST, 0, ParseTagNames, NULL },
195+
{ TidyEmptyTags, MT, "new-empty-tags", ST, 0, ParseList, NULL },
197196
{ TidyEncloseBlockText, MR, "enclose-block-text", BL, no, ParsePickList, &boolPicks },
198197
{ TidyEncloseBodyText, MR, "enclose-text", BL, no, ParsePickList, &boolPicks },
199198
{ TidyErrFile, IO, "error-file", ST, 0, ParseString, NULL },
@@ -211,7 +210,7 @@ static const TidyOptionImpl option_defs[] =
211210
{ TidyIndentCdata, PP, "indent-cdata", BL, no, ParsePickList, &boolPicks },
212211
{ TidyIndentContent, PP, "indent", IN, TidyNoState, ParsePickList, &autoBoolPicks },
213212
{ TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL },
214-
{ TidyInlineTags, MT, "new-inline-tags", ST, 0, ParseTagNames, NULL },
213+
{ TidyInlineTags, MT, "new-inline-tags", ST, 0, ParseList, NULL },
215214
{ TidyJoinClasses, MX, "join-classes", BL, no, ParsePickList, &boolPicks },
216215
{ TidyJoinStyles, MX, "join-styles", BL, yes, ParsePickList, &boolPicks },
217216
{ TidyKeepFileTimes, IO, "keep-time", BL, no, ParsePickList, &boolPicks },
@@ -234,7 +233,7 @@ static const TidyOptionImpl option_defs[] =
234233
{ TidyOutputBOM, CE, "output-bom", IN, TidyAutoState, ParsePickList, &autoBoolPicks },
235234
{ TidyPPrintTabs, PP, "indent-with-tabs", BL, no, ParseTabs, &boolPicks }, /* 20150515 - Issue #108 */
236235
{ TidyPreserveEntities, ME, "preserve-entities", BL, no, ParsePickList, &boolPicks },
237-
{ TidyPreTags, MT, "new-pre-tags", ST, 0, ParseTagNames, NULL },
236+
{ TidyPreTags, MT, "new-pre-tags", ST, 0, ParseList, NULL },
238237
{ TidyPriorityAttributes, PP, "priority-attributes", ST, 0, ParseList, NULL },
239238
{ TidyPunctWrap, PP, "punctuation-wrap", BL, no, ParsePickList, &boolPicks },
240239
{ TidyQuiet, DD, "quiet", BL, no, ParsePickList, &boolPicks },
@@ -292,7 +291,7 @@ static const struct {
292291
ctmbstr name; /**< name of the deprecated option */
293292
TidyOptionId replacementId; /**< Id of the replacement option, or 0 if none. */
294293
} deprecatedOptions[] = {
295-
// { "show-body-only", TidyBodyOnly },
294+
/* { "show-body-only", TidyBodyOnly }, */
296295
{ NULL }
297296
};
298297

@@ -980,7 +979,7 @@ Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optval )
980979
if (NULL != doc->pOptCallback)
981980
status = (*doc->pOptCallback)( optnam, optval );
982981
if (NULL != doc->pConfigCallback )
983-
status = status && (*doc->pConfigCallback)( tidyImplToDoc(doc), optnam, optval );
982+
status = status || (*doc->pConfigCallback)( tidyImplToDoc(doc), optnam, optval );
984983
if (!status && isDeprecated)
985984
status = subDeprecatedOption( doc, optnam, optval);
986985
if (!status)
@@ -1195,6 +1194,14 @@ void TY_(DeclareListItem)( TidyDocImpl* doc, const TidyOptionImpl* opt, ctmbstr
11951194
TY_(DefineMutedMessage)( doc, opt, name );
11961195
break;
11971196

1197+
case TidyInlineTags:
1198+
case TidyBlockTags:
1199+
case TidyEmptyTags:
1200+
case TidyPreTags:
1201+
case TidyCustomTags:
1202+
TY_(DeclareUserTag)( doc, opt, name );
1203+
break;
1204+
11981205
default:
11991206
break;
12001207
}
@@ -1438,115 +1445,6 @@ Bool ParseTabs( TidyDocImpl* doc, const TidyOptionImpl* entry )
14381445
}
14391446

14401447

1441-
/* Coordinates Config update and Tags data */
1442-
void TY_(DeclareUserTag)( TidyDocImpl* doc, TidyOptionId optId,
1443-
UserTagType tagType, ctmbstr name )
1444-
{
1445-
ctmbstr prvval = cfgStr( doc, optId );
1446-
tmbstr catval = NULL;
1447-
ctmbstr theval = name;
1448-
if ( prvval )
1449-
{
1450-
uint len = TY_(tmbstrlen)(name) + TY_(tmbstrlen)(prvval) + 3;
1451-
catval = TY_(tmbstrndup)( doc->allocator, prvval, len );
1452-
TY_(tmbstrcat)( catval, ", " );
1453-
TY_(tmbstrcat)( catval, name );
1454-
theval = catval;
1455-
}
1456-
TY_(DefineTag)( doc, tagType, name );
1457-
SetOptionValue( doc, optId, theval );
1458-
if ( catval )
1459-
TidyDocFree( doc, catval );
1460-
}
1461-
1462-
1463-
/* a space or comma separated list of tag names */
1464-
Bool ParseTagNames( TidyDocImpl* doc, const TidyOptionImpl* option )
1465-
{
1466-
TidyConfigImpl* cfg = &doc->config;
1467-
tmbchar buf[1024];
1468-
uint i = 0, nTags = 0;
1469-
uint c = SkipWhite( cfg );
1470-
UserTagType ttyp = tagtype_null;
1471-
1472-
switch ( option->id )
1473-
{
1474-
case TidyInlineTags: ttyp = tagtype_inline; break;
1475-
case TidyBlockTags: ttyp = tagtype_block; break;
1476-
case TidyEmptyTags: ttyp = tagtype_empty; break;
1477-
case TidyPreTags: ttyp = tagtype_pre; break;
1478-
case TidyCustomTags: ttyp = cfg(doc, TidyUseCustomTags); break;
1479-
default:
1480-
TY_(ReportUnknownOption)( doc, option->name );
1481-
return no;
1482-
}
1483-
1484-
SetOptionValue( doc, option->id, NULL );
1485-
TY_(FreeDeclaredTags)( doc, ttyp );
1486-
cfg->defined_tags |= ttyp;
1487-
1488-
do
1489-
{
1490-
if (c == ' ' || c == '\t' || c == ',')
1491-
{
1492-
c = AdvanceChar( cfg );
1493-
continue;
1494-
}
1495-
1496-
if ( c == '\r' || c == '\n' )
1497-
{
1498-
uint c2 = AdvanceChar( cfg );
1499-
if ( c == '\r' && c2 == '\n' )
1500-
c = AdvanceChar( cfg );
1501-
else
1502-
c = c2;
1503-
1504-
if ( !TY_(IsWhite)(c) )
1505-
{
1506-
buf[i] = 0;
1507-
TY_(UngetChar)( c, cfg->cfgIn );
1508-
TY_(UngetChar)( '\n', cfg->cfgIn );
1509-
break;
1510-
}
1511-
}
1512-
1513-
/*
1514-
if ( c == '\n' )
1515-
{
1516-
c = AdvanceChar( cfg );
1517-
if ( !TY_(IsWhite)(c) )
1518-
{
1519-
buf[i] = 0;
1520-
TY_(UngetChar)( c, cfg->cfgIn );
1521-
TY_(UngetChar)( '\n', cfg->cfgIn );
1522-
break;
1523-
}
1524-
}
1525-
*/
1526-
1527-
while ( i < sizeof(buf)-2 && c != EndOfStream && !TY_(IsWhite)(c) && c != ',' )
1528-
{
1529-
buf[i++] = (tmbchar) c;
1530-
c = AdvanceChar( cfg );
1531-
}
1532-
1533-
buf[i] = '\0';
1534-
if (i == 0) /* Skip empty tag definition. Possible when */
1535-
continue; /* there is a trailing space on the line. */
1536-
1537-
/* add tag to dictionary */
1538-
TY_(DeclareUserTag)( doc, option->id, ttyp, buf );
1539-
i = 0;
1540-
++nTags;
1541-
}
1542-
while ( c != EndOfStream );
1543-
1544-
if ( i > 0 )
1545-
TY_(DeclareUserTag)( doc, option->id, ttyp, buf );
1546-
return ( nTags > 0 );
1547-
}
1548-
1549-
15501448
/* a string including whitespace */
15511449
/* munges whitespace sequences */
15521450
Bool ParseString( TidyDocImpl* doc, const TidyOptionImpl* option )

src/config.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,6 @@ ctmbstr TY_(CharEncodingName)( int encoding );
366366
ctmbstr TY_(CharEncodingOptName)( int encoding );
367367

368368

369-
/** Coordinates Config update and Tags data.
370-
** @param doc The Tidy document.
371-
** @param optId The option ID the tag is intended for.
372-
** @param tagType The type of tag (pre, inline, etc.).
373-
** @param name The name of the new tag.
374-
*/
375-
void TY_(DeclareUserTag)( TidyDocImpl* doc, TidyOptionId optId,
376-
uint tagType, ctmbstr name );
377-
378369
/** Coordinates Config update and list data.
379370
** @param doc The Tidy document.
380371
** @param opt The option the list item is intended for.

src/forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct _TidyDocImpl TidyDocImpl;
3434
struct _TidyMessageImpl;
3535
typedef struct _TidyMessageImpl TidyMessageImpl;
3636

37+
/* @todo: this name isn't very instructive! */
3738
struct _Dict;
3839
typedef struct _Dict Dict;
3940

src/tags.c

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/* tags.c -- recognize HTML tags
2-
3-
(c) 1998-2008 (W3C) MIT, ERCIM, Keio University
4-
See tidy.h for the copyright notice.
5-
6-
The HTML tags are stored as 8 bit ASCII strings.
7-
8-
*/
1+
/* tags.c
2+
* Recognize HTML tags.
3+
*
4+
* Copyright (c) 1998-2017 World Wide Web Consortium (Massachusetts
5+
* Institute of Technology, European Research Consortium for Informatics
6+
* and Mathematics, Keio University) and HTACG.
7+
*
8+
* See tidy.h for the copyright notice.
9+
*/
910

1011
#include "tidy-int.h"
1112
#include "message.h"
@@ -475,6 +476,38 @@ static void declare( TidyDocImpl* doc, TidyTagImpl* tags,
475476
}
476477
}
477478

479+
480+
/* Coordinates Config update and Tags data */
481+
void TY_(DeclareUserTag)( TidyDocImpl* doc, const TidyOptionImpl* opt, ctmbstr name )
482+
{
483+
UserTagType tagType;
484+
485+
switch ( opt->id )
486+
{
487+
case TidyInlineTags: tagType = tagtype_inline; break;
488+
case TidyBlockTags: tagType = tagtype_block; break;
489+
case TidyEmptyTags: tagType = tagtype_empty; break;
490+
case TidyPreTags: tagType = tagtype_pre; break;
491+
case TidyCustomTags:
492+
{
493+
switch (cfg( doc, TidyUseCustomTags ))
494+
{
495+
case TidyCustomBlocklevel: tagType = tagtype_block; break;
496+
case TidyCustomEmpty: tagType = tagtype_empty; break;
497+
case TidyCustomInline: tagType = tagtype_inline; break;
498+
case TidyCustomPre: tagType = tagtype_pre; break;
499+
default: TY_(ReportUnknownOption)( doc, opt->name ); return;
500+
}
501+
} break;
502+
default:
503+
TY_(ReportUnknownOption)( doc, opt->name );
504+
return;
505+
}
506+
507+
TY_(DefineTag)( doc, tagType, name );
508+
}
509+
510+
478511
#if defined(ENABLE_DEBUG_LOG)
479512
void ListElementsPerVersion( uint vers, Bool has )
480513
{
@@ -526,7 +559,6 @@ void show_have_html5(void)
526559
/* public interface for finding tag by name */
527560
Bool TY_(FindTag)( TidyDocImpl* doc, Node *node )
528561
{
529-
TidyUseCustomTagsState configtype = cfg( doc, TidyUseCustomTags );
530562
const Dict *np = NULL;
531563

532564
if ( cfgBool(doc, TidyXmlTags) )
@@ -545,18 +577,9 @@ Bool TY_(FindTag)( TidyDocImpl* doc, Node *node )
545577
earlier, although if it's earlier we will complain about it elsewhere. */
546578
if ( TY_(nodeIsAutonomousCustomTag)( doc, node) )
547579
{
548-
UserTagType type;
549-
550-
if ( configtype == TidyCustomEmpty )
551-
type = tagtype_empty;
552-
else if ( configtype == TidyCustomInline )
553-
type = tagtype_inline;
554-
else if ( configtype == TidyCustomPre )
555-
type = tagtype_pre;
556-
else
557-
type = tagtype_block;
558-
559-
TY_(DeclareUserTag)( doc, TidyCustomTags, type, node->element );
580+
const TidyOptionImpl* opt = TY_(getOption)( TidyCustomTags );
581+
582+
TY_(DeclareUserTag)( doc, opt, node->element );
560583
node->tag = tagsLookup(doc, &doc->tags, node->element);
561584

562585
/* Output a message the first time we encounter an autonomous custom

0 commit comments

Comments
 (0)