Skip to content

Commit 4509695

Browse files
committed
Updated documentation in file.
Simplified the update counting.
1 parent 6bce1b3 commit 4509695

File tree

1 file changed

+66
-50
lines changed

1 file changed

+66
-50
lines changed

src/message.c

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,45 +40,6 @@ ctmbstr TY_(tidyLibraryVersion)(void)
4040
* General Message Utility Functions
4141
*********************************************************************/
4242

43-
/* Updates document message counts and compares counts to options to
44-
** see if message display should go forward.
45-
*/
46-
static Bool UpdateCount( TidyDocImpl* doc, TidyReportLevel level )
47-
{
48-
/* keep quiet after <ShowErrors> errors */
49-
Bool go = ( doc->errors < cfg(doc, TidyShowErrors) );
50-
51-
switch ( level )
52-
{
53-
case TidyInfo:
54-
doc->infoMessages++;
55-
break;
56-
case TidyWarning:
57-
doc->warnings++;
58-
break;
59-
case TidyConfig:
60-
doc->optionErrors++;
61-
break;
62-
case TidyAccess:
63-
doc->accessErrors++;
64-
break;
65-
case TidyError:
66-
doc->errors++;
67-
break;
68-
case TidyBadDocument:
69-
doc->docErrors++;
70-
break;
71-
case TidyFatal:
72-
/* Ack! */
73-
break;
74-
default:
75-
break;
76-
}
77-
78-
return go;
79-
}
80-
81-
8243
/* Returns the given node's tag as a string. */
8344
static char* TagToString(Node* tag, char* buf, size_t count)
8445
{
@@ -157,7 +118,7 @@ static ctmbstr HTMLVersion( TidyDocImpl* doc )
157118
static void messageOut( TidyMessageImpl *message )
158119
{
159120
TidyDocImpl *doc;
160-
Bool go;
121+
Bool go = yes;
161122

162123
if ( !message )
163124
return;
@@ -167,10 +128,38 @@ static void messageOut( TidyMessageImpl *message )
167128
/* The filter has had a chance to suppress *any* message from output. */
168129
go = message->allowMessage;
169130

170-
/* Allow UpdateCount a chance to suppress further report messages. */
131+
/* Update the count of each report type. */
132+
switch ( message->level )
133+
{
134+
case TidyInfo:
135+
doc->infoMessages++;
136+
break;
137+
case TidyWarning:
138+
doc->warnings++;
139+
break;
140+
case TidyConfig:
141+
doc->optionErrors++;
142+
break;
143+
case TidyAccess:
144+
doc->accessErrors++;
145+
break;
146+
case TidyError:
147+
doc->errors++;
148+
break;
149+
case TidyBadDocument:
150+
doc->docErrors++;
151+
break;
152+
case TidyFatal:
153+
/* Ack! */
154+
break;
155+
default:
156+
break;
157+
}
158+
159+
/* Suppress report messages if we've already reached the reporting limit. */
171160
if ( message->level <= TidyFatal )
172161
{
173-
go = go & UpdateCount( doc, message->level );
162+
go = go & ( doc->errors < cfg(doc, TidyShowErrors) );
174163
}
175164

176165
/* If suppressing TidyInfo/TidyDialogueInfo on Reports, suppress them. */
@@ -229,7 +218,11 @@ static void messageOut( TidyMessageImpl *message )
229218

230219
/* Functions of this type will create new instances of TidyMessage specific to
231220
** the type of report being emitted. Many messages share the same fomatter for
232-
** messages, but new ones can be written as required.
221+
** messages, but new ones can be written as required. Please have a look at
222+
** the existing formatters in order to determine if an existing signature is
223+
** compatible with the report you wish to output before adding a new formatter.
224+
** In particular, if an existing formatter provides most of the local variables
225+
** required to populate your format string, try to use it.
233226
*/
234227
typedef TidyMessageImpl*(messageFormatter)(TidyDocImpl* doc, Node *element, Node *node, uint code, uint level, va_list args);
235228

@@ -244,7 +237,7 @@ static messageFormatter formatStandardDynamic;
244237

245238
/* This structure ties together for each report Code the default
246239
** TidyReportLevel, the Formatter to be used to construct the message, and the
247-
** Next code to output, if applicable. Assuming an existing formatter can,
240+
** next code to output, if applicable. Assuming an existing formatter can,
248241
** this it makes it simple to output new reports, or to change report level by
249242
** modifying this array.
250243
*/
@@ -485,14 +478,30 @@ static struct _dispatchTable {
485478
*********************************************************************/
486479

487480

488-
/* Provides formatting for the Attribute-related reports. */
481+
/* Provides formatting for the Attribute-related reports. This formatter
482+
** should be reserved for messages generated by Tidy's accessibility module,
483+
** even if the signature matches some unrelated report that you wish to
484+
** generate.
485+
*/
489486
TidyMessageImpl *formatAccessReport(TidyDocImpl* doc, Node *element, Node *node, uint code, uint level, va_list args)
490487
{
491488
doc->badAccess |= BA_WAI;
492-
return TY_(tidyMessageCreateWithNode)(doc, node, code, level );
489+
490+
/* Currently *all* cases are handled in the default, but maintain this
491+
structure for possible future cases. */
492+
switch (code)
493+
{
494+
default:
495+
return TY_(tidyMessageCreateWithNode)(doc, node, code, level );
496+
}
497+
498+
return NULL;
493499
}
494500

495-
/* Provides formatting for the Attribute-related reports. */
501+
/* Provides formatting for the Attribute-related reports. This formatter
502+
** provides local variables that are used principally in the formats used for
503+
** the attribute related reports.
504+
*/
496505
TidyMessageImpl *formatAttributeReport(TidyDocImpl* doc, Node *element, Node *node, uint code, uint level, va_list args)
497506
{
498507
AttVal *av = NULL;
@@ -573,7 +582,8 @@ TidyMessageImpl *formatAttributeReport(TidyDocImpl* doc, Node *element, Node *no
573582

574583

575584
/* Provides report formatting *and* additional status settings for Tidy's
576-
** encoding reports.
585+
** encoding reports. Provides the local variables typically used for this type
586+
** of report.
577587
** @todo: These status changes probably SHOULD be made in the calling code;
578588
** however these states are captured to generate future output, which may be
579589
** useful here in the long run.
@@ -633,6 +643,9 @@ TidyMessageImpl *formatEncodingReport(TidyDocImpl* doc, Node *element, Node *nod
633643
** reports use the same basic data derived from the element and node, this
634644
** formatter covers the vast majority of Tidy's report messages. Note that this
635645
** formatter guarantees the values of TidyReportLevel in the dispatchTable[].
646+
** Some of the cases in this formatter start new contexts from the va_list
647+
** when the required data is simple. For complex local variable needs, it may
648+
** be preferred to write a new formatter.
636649
*/
637650
TidyMessageImpl *formatStandard(TidyDocImpl* doc, Node *element, Node *node, uint code, uint level, va_list args)
638651
{
@@ -880,7 +893,9 @@ static void vReport(TidyDocImpl* doc, Node *element, Node *node, uint code, va_l
880893
** possible, relevant data that can be reported. The only real drawbacks are
881894
** having to pass NULL when some of the values aren't used, and the lack of
882895
** type safety by using the variable arguments. To counter this some convenience
883-
** report output functions exist, too.
896+
** report output functions exist, too. Any new reports you wish to create must
897+
** be able to use this function signature, although convenience functions should
898+
** be added to abstract the full fuction signature and to preserve type safety.
884899
*/
885900
void TY_(Report)(TidyDocImpl* doc, Node *element, Node *node, uint code, ...)
886901
{
@@ -894,7 +909,8 @@ void TY_(Report)(TidyDocImpl* doc, Node *element, Node *node, uint code, ...)
894909
/*********************************************************************
895910
* Convenience Reporting Functions
896911
* Functions that don't require the full signature of TY_(Report),
897-
* and help protect type safety by avoiding variable arguments.
912+
* and help protect type safety by avoiding variable arguments in the
913+
* rest of Tidy's code.
898914
*********************************************************************/
899915

900916
#if SUPPORT_ACCESSIBILITY_CHECKS

0 commit comments

Comments
 (0)