~ubuntu-branches/ubuntu/precise/tidy/precise-updates

« back to all changes in this revision

Viewing changes to src/localize.c

  • Committer: Bazaar Package Importer
  • Author(s): Jason Thomas
  • Date: 2008-01-20 21:46:03 UTC
  • mfrom: (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080120214603-poklofici9og61tx
Tags: 20080116cvs-2
* debian/control: build depends on xsltproc
  (closes: #461608)
* debian/tidy.preinst,postinst: add code to move old config file
  (closes: #461623)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* localize.c -- text strings and routines to handle errors and general messages
2
2
 
3
 
  (c) 1998-2005 (W3C) MIT, ERCIM, Keio University
 
3
  (c) 1998-2007 (W3C) MIT, ERCIM, Keio University
4
4
  Portions Copyright University of Toronto
5
5
  See tidy.h and access.h for the copyright notice.
6
6
 
10
10
  CVS Info :
11
11
 
12
12
    $Author: arnaud02 $ 
13
 
    $Date: 2005/10/18 11:30:30 $ 
14
 
    $Revision: 1.144 $ 
 
13
    $Date: 2007/11/06 11:59:14 $ 
 
14
    $Revision: 1.177 $ 
15
15
 
16
16
*/
17
17
 
30
30
*/
31
31
#define ATRC_ACCESS_URL  "http://www.aprompt.ca/Tidy/accessibilitychecks.html"
32
32
 
33
 
static const char release_date[] = "1 September 2005";
 
33
#include "version.h"
34
34
 
35
 
ctmbstr ReleaseDate(void)
 
35
ctmbstr TY_(ReleaseDate)(void)
36
36
{
37
 
  return release_date;
 
37
  return TY_(release_date);
38
38
}
39
39
 
40
40
static struct _msgfmt
96
96
  { ILLEGAL_URI_REFERENCE,        "%s improperly escaped URI reference"                                     }, /* Error */
97
97
  { ESCAPED_ILLEGAL_URI,          "%s escaping malformed URI reference"                                     }, /* Error */
98
98
  { NEWLINE_IN_URI,               "%s discarding newline in URI reference"                                  }, /* Error */
 
99
  { WHITE_IN_URI,                 "%s discarding whitespace in URI reference"                               }, /* Error */
99
100
  { UNEXPECTED_EQUALSIGN,         "%s unexpected '=', expected attribute name"                              }, /* Error */
100
101
  { MISSING_IMAGEMAP,             "%s should use client-side image map"                                     }, /* Warning (but deprecated) */
101
102
 
156
157
  { UNKNOWN_ELEMENT,              "%s is not recognized!"                                                   }, /* Error */
157
158
  { UNEXPECTED_ENDTAG,            "unexpected </%s>"                                                }, /* Error */
158
159
 
 
160
/* */
 
161
  { PREVIOUS_LOCATION,            "<%s> previously mentioned"                                               }, /* Info */
 
162
 
159
163
#if SUPPORT_ACCESSIBILITY_CHECKS
160
164
 
161
165
/* ReportAccess */
284
288
  { LINK_TEXT_TOO_LONG,                            "[13.1.1.3]: link text too long."                                          }, /* Access */
285
289
  { LINK_TEXT_NOT_MEANINGFUL_CLICK_HERE,           "[13.1.1.4]: link text not meaningful (click here)."                       }, /* Access */
286
290
  { METADATA_MISSING,                              "[13.2.1.1]: Metadata missing."                                            }, /* Access */
287
 
  { METADATA_MISSING_LINK,                         "[13.2.1.2]: Metadata missing (link element)."                             }, /* Access */
288
291
  { METADATA_MISSING_REDIRECT_AUTOREFRESH,         "[13.2.1.3]: Metadata missing (redirect/auto-refresh)."                    }, /* Access */
289
292
  { SKIPOVER_ASCII_ART,                            "[13.10.1.1]: skip over ascii art."                                        }, /* Access */
290
293
 
345
348
static const TidyOptionId TidyPreTagsLinks[] =
346
349
  { TidyBlockTags, TidyEmptyTags, TidyInlineTags, TidyUnknownOption };
347
350
static const TidyOptionId TidyMergeDivsLinks[] =
348
 
  { TidyMakeClean, TidyUnknownOption };
 
351
  { TidyMakeClean, TidyMergeSpans, TidyUnknownOption };
 
352
static const TidyOptionId TidyMergeSpansLinks[] =
 
353
  { TidyMakeClean, TidyMergeDivs, TidyUnknownOption };
349
354
static const TidyOptionId TidyAsciiCharsLinks[] =
350
355
  { TidyMakeClean, TidyUnknownOption };
351
356
static const TidyOptionId TidyNumEntitiesLinks[] =
352
 
  { TidyDoctype, TidyUnknownOption };
 
357
  { TidyDoctype, TidyPreserveEntities, TidyUnknownOption };
 
358
static const TidyOptionId TidyDropFontTagsLinks[] =
 
359
  { TidyMakeClean, TidyUnknownOption };
 
360
static const TidyOptionId TidyMakeCleanTagsLinks[] =
 
361
  { TidyDropFontTags, TidyUnknownOption };
353
362
 
354
363
/* Documentation of options */
355
364
static const TidyOptionDoc option_docs[] =
394
403
   "should strip out surplus presentational tags and attributes replacing "
395
404
   "them by style rules and structural markup as appropriate. It works well "
396
405
   "on the HTML saved by Microsoft Office products. "
 
406
   , TidyMakeCleanTagsLinks
397
407
  },
398
408
  {TidyDoctype,
399
409
   "This option specifies the DOCTYPE declaration generated by Tidy. If set "
408
418
   "doctype: \"-//ACME//DTD HTML 3.14159//EN\"<br />"
409
419
   "<br />"
410
420
   "If you specify the FPI for an XHTML document, Tidy will set the "
411
 
   "system identifier to the empty string.  Tidy leaves the DOCTYPE for "
 
421
   "system identifier to an empty string. For an HTML document, Tidy adds a "
 
422
   "system identifier only if one was already present in order to preserve "
 
423
   "the processing mode of some browsers. Tidy leaves the DOCTYPE for "
412
424
   "generic XML documents unchanged. <code>--doctype omit</code> implies "
413
 
   "<code>--numeric-entities yes</code>. "
 
425
   "<code>--numeric-entities yes</code>. This option does not offer a "
 
426
   "validation of the document conformance. "
414
427
  },
415
428
  {TidyDropEmptyParas,
416
429
   "This option specifies if Tidy should discard empty paragraphs. "
419
432
   "This option specifies if Tidy should discard &lt;FONT&gt; and "
420
433
   "&lt;CENTER&gt; tags without creating the corresponding style rules. This "
421
434
   "option can be set independently of the clean option. "
 
435
   , TidyDropFontTagsLinks
422
436
  },
423
437
  {TidyDropPropAttrs,
424
438
   "This option specifies if Tidy should strip out proprietary attributes, "
496
510
   "are discarded with the exception of \"class\" and \"style\". "
497
511
   ,TidyMergeDivsLinks
498
512
  },
 
513
  {TidyMergeSpans,
 
514
   "Can be used to modify behavior of -c (--clean yes) option. "
 
515
   "This option specifies if Tidy should merge nested &lt;span&gt; such as "
 
516
   "\"&lt;span&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;\". The algorithm "
 
517
   "is identical to the one used by --merge-divs. "
 
518
   ,TidyMergeSpansLinks
 
519
  },
499
520
#if SUPPORT_ASIAN_ENCODINGS
500
521
  {TidyNCR,
501
522
   "This option specifies if Tidy should allow numeric character references. "
506
527
   "comma separated list of tag names. Unless you declare new tags, Tidy will "
507
528
   "refuse to generate a tidied file if the input includes previously unknown "
508
529
   "tags. Note you can't change the content model for elements such as "
509
 
   "&lt;TABLE&gt;, &lt;UL&gt;, &lt;OL&gt; and &lt;DL&gt;. "
 
530
   "&lt;TABLE&gt;, &lt;UL&gt;, &lt;OL&gt; and &lt;DL&gt;. This option is "
 
531
   "ignored in XML mode. "
510
532
   ,TidyBlockTagsLinks
511
533
  },
512
534
  {TidyEmptyTags,
514
536
   "or comma separated list of tag names. Unless you declare new tags, Tidy "
515
537
   "will refuse to generate a tidied file if the input includes previously "
516
538
   "unknown tags. Remember to also declare empty tags as either inline or "
517
 
   "blocklevel. "
 
539
   "blocklevel. This option is ignored in XML mode. "
518
540
   ,TidyEmptyTagsLinks
519
541
  },
520
542
  {TidyInlineTags,
521
543
   "This option specifies new non-empty inline tags. This option takes a "
522
544
   "space or comma separated list of tag names. Unless you declare new tags, "
523
545
   "Tidy will refuse to generate a tidied file if the input includes "
524
 
   "previously unknown tags. "
 
546
   "previously unknown tags. This option is ignored in XML mode. "
525
547
   ,TidyInlineTagsLinks
526
548
  },
527
549
  { TidyPreTags,
531
553
    "of tag names. Unless you declare new tags, Tidy will refuse to generate "
532
554
    "a tidied file if the input includes previously unknown tags. Note you "
533
555
    "can not as yet add new CDATA elements (similar to &lt;SCRIPT&gt;). "
 
556
    "This option is ignored in XML mode. "
534
557
    ,TidyPreTagsLinks
535
558
  },
536
559
  {TidyNumEntities,
537
560
   "This option specifies if Tidy should output entities other than the "
538
561
   "built-in HTML entities (&amp;amp;, &amp;lt;, &amp;gt; and &amp;quot;) in "
539
 
   "the numeric rather than the named entity form. "
 
562
   "the numeric rather than the named entity form. Only entities compatible "
 
563
   "with the DOCTYPE declaration generated are used. Entities that can be "
 
564
   "represented in the output encoding are translated correspondingly. "
540
565
    ,TidyNumEntitiesLinks
541
566
  },
542
567
  {TidyHtmlOut,
580
605
   "an attribute is repeated, e.g. has two align attributes. "
581
606
   , TidyDuplicateAttrsLinks
582
607
  },
 
608
  {TidySortAttributes,
 
609
   "This option specifies that tidy should sort attributes within an element "
 
610
   "using the specified sort algorithm. If set to \"alpha\", the algorithm is "
 
611
   "an ascending alphabetic sort. "
 
612
  },
583
613
  {TidyReplaceColor,
584
614
   "This option specifies if Tidy should replace numeric values in color "
585
615
   "attributes by HTML/XHTML color names where defined, e.g. replace "
587
617
  },
588
618
  {TidyBodyOnly,
589
619
   "This option specifies if Tidy should print only the contents of the "
590
 
   "body tag as an HTML fragment.  Useful for incorporating existing whole "
591
 
   "pages as a portion of another page. "
 
620
   "body tag as an HTML fragment. If set to \"auto\", this is performed only "
 
621
   "if the body tag has been inferred. Useful for incorporating "
 
622
   "existing whole pages as a portion of another page. "
 
623
   "This option has no effect if XML output is requested. "
592
624
  },
593
625
  {TidyUpperCaseAttrs,
594
626
   "This option specifies if Tidy should output attribute names in upper "
720
752
   "encodings e.g. ISO-2022-JP. For mac and win1252, Tidy will accept vendor "
721
753
   "specific character values, but will use entities for all characters whose "
722
754
   "value &gt; 127. "
 
755
   "For unsupported encodings, use an external utility to convert to and from "
 
756
   "UTF-8. "
723
757
   ,TidyCharEncodingLinks
724
758
  },
725
759
  {TidyInCharEncoding,
807
841
   "before tidying them, as on rare occasions the result may not be what you "
808
842
   "expect. "
809
843
  },
 
844
  {TidyDecorateInferredUL,
 
845
   "This option specifies if Tidy should decorate inferred UL elements with "
 
846
   "some CSS markup to avoid indentation to the right. "
 
847
  },
 
848
  {TidyPreserveEntities,
 
849
   "This option specifies if Tidy should preserve the well-formed entitites "
 
850
   "as found in the input. "
 
851
  },
810
852
  {N_TIDY_OPTIONS,
811
853
   NULL
812
854
  }
813
855
};
814
856
 
815
 
const TidyOptionDoc* tidyOptGetDocDesc( TidyOptionId optId )
 
857
const TidyOptionDoc* TY_(OptGetDocDesc)( TidyOptionId optId )
816
858
{
817
859
    uint i = 0;
818
860
 
832
874
  switch ( level )
833
875
  {
834
876
  case TidyInfo:
835
 
    tmbstrncpy( buf, "Info: ", count );
 
877
    TY_(tmbstrncpy)( buf, "Info: ", count );
836
878
    break;
837
879
  case TidyWarning:
838
 
    tmbstrncpy( buf, "Warning: ", count );
 
880
    TY_(tmbstrncpy)( buf, "Warning: ", count );
839
881
    break;
840
882
  case TidyConfig:
841
 
    tmbstrncpy( buf, "Config: ", count );
 
883
    TY_(tmbstrncpy)( buf, "Config: ", count );
842
884
    break;
843
885
  case TidyAccess:
844
 
    tmbstrncpy( buf, "Access: ", count );
 
886
    TY_(tmbstrncpy)( buf, "Access: ", count );
845
887
    break;
846
888
  case TidyError:
847
 
    tmbstrncpy( buf, "Error: ", count );
 
889
    TY_(tmbstrncpy)( buf, "Error: ", count );
848
890
    break;
849
891
  case TidyBadDocument:
850
 
    tmbstrncpy( buf, "Document: ", count );
 
892
    TY_(tmbstrncpy)( buf, "Document: ", count );
851
893
    break;
852
894
  case TidyFatal:
853
 
    tmbstrncpy( buf, "panic: ", count );
 
895
    TY_(tmbstrncpy)( buf, "panic: ", count );
854
896
    break;
855
897
  }
856
 
  return buf + tmbstrlen( buf );
 
898
  return buf + TY_(tmbstrlen)( buf );
857
899
}
858
900
 
859
901
/* Updates document message counts and
900
942
 
901
943
    /* Change formatting to be parsable by GNU Emacs */
902
944
    if ( cfgBool(doc, TidyEmacs) && cfgStr(doc, TidyEmacsFile) )
903
 
        tmbsnprintf(buf, count, "%s:%d:%d: ", 
904
 
                 cfgStr(doc, TidyEmacsFile), line, col);
 
945
        TY_(tmbsnprintf)(buf, count, "%s:%d:%d: ", 
 
946
                         cfgStr(doc, TidyEmacsFile), line, col);
905
947
    else /* traditional format */
906
 
        tmbsnprintf(buf, count, "line %d column %d - ", line, col);
907
 
    return buf + tmbstrlen( buf );
 
948
        TY_(tmbsnprintf)(buf, count, "line %d column %d - ", line, col);
 
949
    return buf + TY_(tmbstrlen)( buf );
908
950
}
909
951
 
910
952
/* General message writing routine.
927
969
static void messagePos( TidyDocImpl* doc, TidyReportLevel level,
928
970
                        int line, int col, ctmbstr msg, va_list args )
929
971
{
930
 
    char messageBuf[ 2048 ];
 
972
    enum { sizeMessageBuf=2048 };
 
973
    char *messageBuf = TidyDocAlloc(doc,sizeMessageBuf);
931
974
    Bool go = UpdateCount( doc, level );
932
975
 
933
976
    if ( go )
934
977
    {
935
 
        tmbvsnprintf(messageBuf, sizeof(messageBuf), msg, args);
 
978
        TY_(tmbvsnprintf)(messageBuf, sizeMessageBuf, msg, args);
936
979
        if ( doc->mssgFilt )
937
980
        {
938
981
            TidyDoc tdoc = tidyImplToDoc( doc );
942
985
 
943
986
    if ( go )
944
987
    {
945
 
        char buf[ 64 ];
 
988
        enum { sizeBuf=1024 };
 
989
        char *buf = TidyDocAlloc(doc,sizeBuf);
946
990
        const char *cp;
947
991
        if ( line > 0 && col > 0 )
948
992
        {
949
 
            ReportPosition(doc, line, col, buf, sizeof(buf));
 
993
            ReportPosition(doc, line, col, buf, sizeBuf);
950
994
            for ( cp = buf; *cp; ++cp )
951
 
                WriteChar( *cp, doc->errout );
 
995
                TY_(WriteChar)( *cp, doc->errout );
952
996
        }
953
997
 
954
 
        LevelPrefix( level, buf, sizeof(buf) );
 
998
        LevelPrefix( level, buf, sizeBuf );
955
999
        for ( cp = buf; *cp; ++cp )
956
 
            WriteChar( *cp, doc->errout );
 
1000
            TY_(WriteChar)( *cp, doc->errout );
957
1001
 
958
1002
        for ( cp = messageBuf; *cp; ++cp )
959
 
            WriteChar( *cp, doc->errout );
960
 
        WriteChar( '\n', doc->errout );
 
1003
            TY_(WriteChar)( *cp, doc->errout );
 
1004
        TY_(WriteChar)( '\n', doc->errout );
 
1005
        TidyDocFree(doc, buf);
961
1006
    }
 
1007
    TidyDocFree(doc, messageBuf);
962
1008
}
963
1009
 
 
1010
/* Reports error at current Lexer line/column. */ 
 
1011
static
 
1012
void message( TidyDocImpl* doc, TidyReportLevel level, ctmbstr msg, ... )
 
1013
#ifdef __GNUC__
 
1014
__attribute__((format(printf, 3, 4)))
 
1015
#endif
 
1016
;
 
1017
 
 
1018
/* Reports error at node line/column. */ 
 
1019
static
 
1020
void messageNode( TidyDocImpl* doc, TidyReportLevel level,
 
1021
                  Node* node, ctmbstr msg, ... )
 
1022
#ifdef __GNUC__
 
1023
__attribute__((format(printf, 4, 5)))
 
1024
#endif
 
1025
;
 
1026
 
 
1027
/* Reports error at given line/column. */ 
 
1028
static
 
1029
void messageLexer( TidyDocImpl* doc, TidyReportLevel level, 
 
1030
                   ctmbstr msg, ... )
 
1031
#ifdef __GNUC__
 
1032
__attribute__((format(printf, 3, 4)))
 
1033
#endif
 
1034
;
 
1035
 
 
1036
/* For general reporting.  Emits nothing if --quiet yes */
 
1037
static
 
1038
void tidy_out( TidyDocImpl* doc, ctmbstr msg, ... )
 
1039
#ifdef __GNUC__
 
1040
__attribute__((format(printf, 2, 3)))
 
1041
#endif
 
1042
;
 
1043
 
 
1044
 
964
1045
void message( TidyDocImpl* doc, TidyReportLevel level, ctmbstr msg, ... )
965
1046
{
966
1047
    va_list args;
1000
1081
    if ( !cfgBool(doc, TidyQuiet) )
1001
1082
    {
1002
1083
        ctmbstr cp;
1003
 
        char buf[ 2048 ];
 
1084
        enum { sizeBuf=2048 };
 
1085
        char *buf = TidyDocAlloc(doc,sizeBuf);
1004
1086
 
1005
1087
        va_list args;
1006
1088
        va_start( args, msg );
1007
 
        tmbvsnprintf(buf, sizeof(buf), msg, args);
 
1089
        TY_(tmbvsnprintf)(buf, sizeBuf, msg, args);
1008
1090
        va_end( args );
1009
1091
 
1010
1092
        for ( cp=buf; *cp; ++cp )
1011
 
          WriteChar( *cp, doc->errout );
 
1093
          TY_(WriteChar)( *cp, doc->errout );
 
1094
        TidyDocFree(doc, buf);
1012
1095
    }
1013
1096
}
1014
1097
 
 
1098
#if 0
1015
1099
void ShowVersion( TidyDocImpl* doc )
1016
1100
{
1017
1101
    ctmbstr platform = "", helper = "";
1023
1107
 
1024
1108
    tidy_out( doc, "\nHTML Tidy%s%s (release date: %s; built on %s, at %s)\n"
1025
1109
                   "See http://tidy.sourceforge.net/ for details.\n",
1026
 
              helper, platform, release_date, __DATE__, __TIME__ );
 
1110
              helper, platform, TY_(release_date), __DATE__, __TIME__ );
1027
1111
}
 
1112
#endif
1028
1113
 
1029
 
void FileError( TidyDocImpl* doc, ctmbstr file, TidyReportLevel level )
 
1114
void TY_(FileError)( TidyDocImpl* doc, ctmbstr file, TidyReportLevel level )
1030
1115
{
1031
1116
    message( doc, level, "Can't open \"%s\"\n", file );
1032
1117
}
1036
1121
    *buf = 0;
1037
1122
    if (tag)
1038
1123
    {
1039
 
        if (nodeIsElement(tag))
1040
 
            tmbsnprintf(buf, count, "<%s>", tag->element);
 
1124
        if (TY_(nodeIsElement)(tag))
 
1125
            TY_(tmbsnprintf)(buf, count, "<%s>", tag->element);
1041
1126
        else if (tag->type == EndTag)
1042
 
            tmbsnprintf(buf, count, "</%s>", tag->element);
 
1127
            TY_(tmbsnprintf)(buf, count, "</%s>", tag->element);
1043
1128
        else if (tag->type == DocTypeTag)
1044
 
            tmbsnprintf(buf, count, "<!DOCTYPE>");
 
1129
            TY_(tmbsnprintf)(buf, count, "<!DOCTYPE>");
1045
1130
        else if (tag->type == TextNode)
1046
 
            tmbsnprintf(buf, count, "plain text");
 
1131
            TY_(tmbsnprintf)(buf, count, "plain text");
1047
1132
        else if (tag->type == XmlDecl)
1048
 
            tmbsnprintf(buf, count, "XML declaration");
 
1133
            TY_(tmbsnprintf)(buf, count, "XML declaration");
1049
1134
        else if (tag->element)
1050
 
            tmbsnprintf(buf, count, "%s", tag->element);
 
1135
            TY_(tmbsnprintf)(buf, count, "%s", tag->element);
1051
1136
    }
1052
 
    return buf + tmbstrlen(buf);
 
1137
    return buf + TY_(tmbstrlen)(buf);
1053
1138
}
1054
1139
 
1055
1140
/* lexer is not defined when this is called */
1056
 
void ReportUnknownOption( TidyDocImpl* doc, ctmbstr option )
 
1141
void TY_(ReportUnknownOption)( TidyDocImpl* doc, ctmbstr option )
1057
1142
{
1058
1143
    assert( option != NULL );
1059
1144
    message( doc, TidyConfig, "unknown option: %s", option );
1060
1145
}
1061
1146
 
1062
1147
/* lexer is not defined when this is called */
1063
 
void ReportBadArgument( TidyDocImpl* doc, ctmbstr option )
 
1148
void TY_(ReportBadArgument)( TidyDocImpl* doc, ctmbstr option )
1064
1149
{
1065
1150
    assert( option != NULL );
1066
1151
    message( doc, TidyConfig,
1093
1178
    str[n+1] = '\0';
1094
1179
}
1095
1180
 
1096
 
void ReportEncodingWarning(TidyDocImpl* doc, uint code, uint encoding)
 
1181
void TY_(ReportEncodingWarning)(TidyDocImpl* doc, uint code, uint encoding)
1097
1182
{
1098
1183
    switch(code)
1099
1184
    {
1100
1185
    case ENCODING_MISMATCH:
1101
1186
        messageLexer(doc, TidyWarning, GetFormatFromCode(code), 
1102
 
                     CharEncodingName(doc->docIn->encoding),
1103
 
                     CharEncodingName(encoding));
 
1187
                     TY_(CharEncodingName)(doc->docIn->encoding),
 
1188
                     TY_(CharEncodingName)(encoding));
1104
1189
        doc->badChars |= BC_ENCODING_MISMATCH;
1105
1190
        break;
1106
1191
    }
1107
1192
}
1108
1193
 
1109
 
void ReportEncodingError(TidyDocImpl* doc, uint code, uint c, Bool discarded)
 
1194
void TY_(ReportEncodingError)(TidyDocImpl* doc, uint code, uint c, Bool discarded)
1110
1195
{
1111
1196
    char buf[ 32 ] = {'\0'};
1112
1197
 
1127
1212
        break;
1128
1213
 
1129
1214
    case INVALID_UTF8:
1130
 
        tmbsnprintf(buf, sizeof(buf), "U+%04X", c);
 
1215
        TY_(tmbsnprintf)(buf, sizeof(buf), "U+%04X", c);
1131
1216
        doc->badChars |= BC_INVALID_UTF8;
1132
1217
        break;
1133
1218
 
1134
1219
#if SUPPORT_UTF16_ENCODINGS
1135
1220
    case INVALID_UTF16:
1136
 
        tmbsnprintf(buf, sizeof(buf), "U+%04X", c);
 
1221
        TY_(tmbsnprintf)(buf, sizeof(buf), "U+%04X", c);
1137
1222
        doc->badChars |= BC_INVALID_UTF16;
1138
1223
        break;
1139
1224
#endif
1148
1233
        messageLexer( doc, TidyWarning, fmt, action, buf );
1149
1234
}
1150
1235
 
1151
 
void ReportEntityError( TidyDocImpl* doc, uint code, ctmbstr entity,
1152
 
                        int ARG_UNUSED(c) )
 
1236
void TY_(ReportEntityError)( TidyDocImpl* doc, uint code, ctmbstr entity,
 
1237
                             int ARG_UNUSED(c) )
1153
1238
{
1154
1239
    ctmbstr entityname = ( entity ? entity : "NULL" );
1155
1240
    ctmbstr fmt = GetFormatFromCode(code);
1158
1243
        messageLexer( doc, TidyWarning, fmt, entityname );
1159
1244
}
1160
1245
 
1161
 
void ReportAttrError(TidyDocImpl* doc, Node *node, AttVal *av, uint code)
 
1246
void TY_(ReportAttrError)(TidyDocImpl* doc, Node *node, AttVal *av, uint code)
1162
1247
{
1163
1248
    char const *name = "NULL", *value = "NULL";
1164
1249
    char tagdesc[64];
1201
1286
    case ILLEGAL_URI_REFERENCE:
1202
1287
    case ESCAPED_ILLEGAL_URI:
1203
1288
    case NEWLINE_IN_URI:
 
1289
    case WHITE_IN_URI:
1204
1290
    case UNEXPECTED_GT:
1205
1291
    case INVALID_XML_ID:
1206
1292
    case UNEXPECTED_EQUALSIGN:
1215
1301
        break;
1216
1302
 
1217
1303
 
1218
 
    case MISSING_IMAGEMAP:  /* this is not used anywhere */
 
1304
    case MISSING_IMAGEMAP:
1219
1305
        messageNode(doc, TidyWarning, node, fmt, tagdesc);
1220
 
        doc->badAccess |= MISSING_IMAGE_MAP;
 
1306
        doc->badAccess |= BA_MISSING_IMAGE_MAP;
1221
1307
        break;
1222
1308
 
1223
1309
    case REPEATED_ATTRIBUTE:
1233
1319
    }
1234
1320
}
1235
1321
 
1236
 
void ReportMissingAttr( TidyDocImpl* doc, Node* node, ctmbstr name )
 
1322
void TY_(ReportMissingAttr)( TidyDocImpl* doc, Node* node, ctmbstr name )
1237
1323
{
1238
1324
    char tagdesc[ 64 ];
1239
1325
    ctmbstr fmt = GetFormatFromCode(MISSING_ATTRIBUTE);
1256
1342
* with the cells.
1257
1343
*********************************************************/
1258
1344
 
1259
 
void DisplayHTMLTableAlgorithm( TidyDocImpl* doc )
 
1345
void TY_(DisplayHTMLTableAlgorithm)( TidyDocImpl* doc )
1260
1346
{
1261
1347
    tidy_out(doc, " \n");
1262
1348
    tidy_out(doc, "      - First, search left from the cell's position to find row header cells.\n");
1275
1361
    tidy_out(doc, " \n");
1276
1362
}
1277
1363
 
1278
 
void ReportAccessWarning( TidyDocImpl* doc, Node* node, uint code )
 
1364
void TY_(ReportAccessWarning)( TidyDocImpl* doc, Node* node, uint code )
1279
1365
{
1280
1366
    ctmbstr fmt = GetFormatFromCode(code);
1281
 
    doc->badAccess = yes;
 
1367
    doc->badAccess |= BA_WAI;
1282
1368
    messageNode( doc, TidyAccess, node, fmt );
1283
1369
}
1284
1370
 
1285
 
void ReportAccessError( TidyDocImpl* doc, Node* node, uint code )
 
1371
void TY_(ReportAccessError)( TidyDocImpl* doc, Node* node, uint code )
1286
1372
{
1287
1373
    ctmbstr fmt = GetFormatFromCode(code);
1288
 
    doc->badAccess = yes;
 
1374
    doc->badAccess |= BA_WAI;
1289
1375
    messageNode( doc, TidyAccess, node, fmt );
1290
1376
}
1291
1377
 
1292
1378
#endif /* SUPPORT_ACCESSIBILITY_CHECKS */
1293
1379
 
1294
 
void ReportWarning(TidyDocImpl* doc, Node *element, Node *node, uint code)
 
1380
void TY_(ReportWarning)(TidyDocImpl* doc, Node *element, Node *node, uint code)
1295
1381
{
1296
1382
    Node* rpt = (element ? element : node);
1297
1383
    ctmbstr fmt = GetFormatFromCode(code);
1322
1408
    }
1323
1409
}
1324
1410
 
1325
 
void ReportNotice(TidyDocImpl* doc, Node *element, Node *node, uint code)
 
1411
void TY_(ReportNotice)(TidyDocImpl* doc, Node *element, Node *node, uint code)
1326
1412
{
1327
1413
    Node* rpt = ( element ? element : node );
1328
1414
    ctmbstr fmt = GetFormatFromCode(code);
1347
1433
    }
1348
1434
}
1349
1435
 
1350
 
void ReportError(TidyDocImpl* doc, Node *element, Node *node, uint code)
 
1436
void TY_(ReportError)(TidyDocImpl* doc, Node *element, Node *node, uint code)
1351
1437
{
1352
1438
    char nodedesc[ 256 ] = {0};
1353
1439
    char elemdesc[ 256 ] = {0};
1397
1483
    case UNEXPECTED_ENDTAG_IN:
1398
1484
    case TOO_MANY_ELEMENTS_IN:
1399
1485
        messageNode(doc, TidyWarning, node, fmt, node->element, element->element);
 
1486
        if (cfgBool( doc, TidyShowWarnings ))
 
1487
            messageNode(doc, TidyInfo, node, GetFormatFromCode(PREVIOUS_LOCATION),
 
1488
                        element->element);
1400
1489
        break;
1401
1490
 
1402
1491
    case ENCODING_IO_CONFLICT:
1428
1517
        break;
1429
1518
 
1430
1519
    case TAG_NOT_ALLOWED_IN:
1431
 
        messageNode(doc, TidyWarning, rpt, fmt, nodedesc, element->element);
 
1520
        messageNode(doc, TidyWarning, node, fmt, nodedesc, element->element);
 
1521
        if (cfgBool( doc, TidyShowWarnings ))
 
1522
            messageNode(doc, TidyInfo, element,
 
1523
                        GetFormatFromCode(PREVIOUS_LOCATION), element->element);
1432
1524
        break;
1433
1525
 
1434
1526
    case REPLACING_UNEX_ELEMENT:
1438
1530
    }
1439
1531
}
1440
1532
 
1441
 
void ReportFatal( TidyDocImpl* doc, Node *element, Node *node, uint code)
 
1533
void TY_(ReportFatal)( TidyDocImpl* doc, Node *element, Node *node, uint code)
1442
1534
{
1443
1535
    char nodedesc[ 256 ] = {0};
1444
1536
    Node* rpt = ( element ? element : node );
1466
1558
    }
1467
1559
}
1468
1560
 
1469
 
void ErrorSummary( TidyDocImpl* doc )
 
1561
void TY_(ErrorSummary)( TidyDocImpl* doc )
1470
1562
{
1471
 
    /* adjust badAccess to that its NULL if frames are ok */
1472
1563
    ctmbstr encnam = "specified";
1473
1564
    int charenc = cfg( doc, TidyCharEncoding ); 
1474
1565
    if ( charenc == WIN1252 ) 
1480
1571
    else if ( charenc == LATIN0 )
1481
1572
        encnam = "latin0";
1482
1573
 
1483
 
    if ( doc->badAccess & (USING_FRAMES | USING_NOFRAMES) )
 
1574
    /* adjust badAccess to that it is 0 if frames are ok */
 
1575
    if ( doc->badAccess & (BA_USING_FRAMES | BA_USING_NOFRAMES) )
1484
1576
    {
1485
 
        if (!((doc->badAccess & USING_FRAMES) && !(doc->badAccess & USING_NOFRAMES)))
1486
 
            doc->badAccess &= ~(USING_FRAMES | USING_NOFRAMES);
 
1577
        if (!((doc->badAccess & BA_USING_FRAMES) && !(doc->badAccess & BA_USING_NOFRAMES)))
 
1578
            doc->badAccess &= ~(BA_USING_FRAMES | BA_USING_NOFRAMES);
1487
1579
    }
1488
1580
 
1489
1581
    if (doc->badChars)
1565
1657
    
1566
1658
    if (doc->badAccess)
1567
1659
    {
1568
 
      if ( cfg(doc, TidyAccessibilityCheckLevel) > 0 )
1569
 
      {
1570
 
        tidy_out(doc, "For further advice on how to make your pages accessible, see\n");
1571
 
        tidy_out(doc, "%s", ACCESS_URL );
1572
 
        tidy_out(doc, "and\n" );
1573
 
        tidy_out(doc, "%s", ATRC_ACCESS_URL );
 
1660
        /* Tidy "classic" accessibility tests */
 
1661
        if ( cfg(doc, TidyAccessibilityCheckLevel) == 0 )
 
1662
        {
 
1663
            if (doc->badAccess & BA_MISSING_SUMMARY)
 
1664
            {
 
1665
                tidy_out(doc, "The table summary attribute should be used to describe\n");
 
1666
                tidy_out(doc, "the table structure. It is very helpful for people using\n");
 
1667
                tidy_out(doc, "non-visual browsers. The scope and headers attributes for\n");
 
1668
                tidy_out(doc, "table cells are useful for specifying which headers apply\n");
 
1669
                tidy_out(doc, "to each table cell, enabling non-visual browsers to provide\n");
 
1670
                tidy_out(doc, "a meaningful context for each cell.\n\n");
 
1671
            }
 
1672
 
 
1673
            if (doc->badAccess & BA_MISSING_IMAGE_ALT)
 
1674
            {
 
1675
                tidy_out(doc, "The alt attribute should be used to give a short description\n");
 
1676
                tidy_out(doc, "of an image; longer descriptions should be given with the\n");
 
1677
                tidy_out(doc, "longdesc attribute which takes a URL linked to the description.\n");
 
1678
                tidy_out(doc, "These measures are needed for people using non-graphical browsers.\n\n");
 
1679
            }
 
1680
 
 
1681
            if (doc->badAccess & BA_MISSING_IMAGE_MAP)
 
1682
            {
 
1683
                tidy_out(doc, "Use client-side image maps in preference to server-side image\n");
 
1684
                tidy_out(doc, "maps as the latter are inaccessible to people using non-\n");
 
1685
                tidy_out(doc, "graphical browsers. In addition, client-side maps are easier\n");
 
1686
                tidy_out(doc, "to set up and provide immediate feedback to users.\n\n");
 
1687
            }
 
1688
 
 
1689
            if (doc->badAccess & BA_MISSING_LINK_ALT)
 
1690
            {
 
1691
                tidy_out(doc, "For hypertext links defined using a client-side image map, you\n");
 
1692
                tidy_out(doc, "need to use the alt attribute to provide a textual description\n");
 
1693
                tidy_out(doc, "of the link for people using non-graphical browsers.\n\n");
 
1694
            }
 
1695
 
 
1696
            if ((doc->badAccess & BA_USING_FRAMES) && !(doc->badAccess & BA_USING_NOFRAMES))
 
1697
            {
 
1698
                tidy_out(doc, "Pages designed using frames presents problems for\n");
 
1699
                tidy_out(doc, "people who are either blind or using a browser that\n");
 
1700
                tidy_out(doc, "doesn't support frames. A frames-based page should always\n");
 
1701
                tidy_out(doc, "include an alternative layout inside a NOFRAMES element.\n\n");
 
1702
            }
 
1703
 
 
1704
        }
 
1705
 
 
1706
        tidy_out(doc, "For further advice on how to make your pages accessible\n");
 
1707
        tidy_out(doc, "see %s", ACCESS_URL );
 
1708
        if ( cfg(doc, TidyAccessibilityCheckLevel) > 0 )
 
1709
            tidy_out(doc, " and %s", ATRC_ACCESS_URL );
1574
1710
        tidy_out(doc, ".\n" );
1575
 
        tidy_out(doc, "You may also want to try \"http://www.cast.org/bobby/\" which is a free Web-based\n");
1576
 
        tidy_out(doc, "service for checking URLs for accessibility.\n\n");
1577
 
      }
1578
 
      else
1579
 
      {
1580
 
        if (doc->badAccess & MISSING_SUMMARY)
1581
 
        {
1582
 
          tidy_out(doc, "The table summary attribute should be used to describe\n");
1583
 
          tidy_out(doc, "the table structure. It is very helpful for people using\n");
1584
 
          tidy_out(doc, "non-visual browsers. The scope and headers attributes for\n");
1585
 
          tidy_out(doc, "table cells are useful for specifying which headers apply\n");
1586
 
          tidy_out(doc, "to each table cell, enabling non-visual browsers to provide\n");
1587
 
          tidy_out(doc, "a meaningful context for each cell.\n\n");
1588
 
        }
1589
 
 
1590
 
        if (doc->badAccess & MISSING_IMAGE_ALT)
1591
 
        {
1592
 
          tidy_out(doc, "The alt attribute should be used to give a short description\n");
1593
 
          tidy_out(doc, "of an image; longer descriptions should be given with the\n");
1594
 
          tidy_out(doc, "longdesc attribute which takes a URL linked to the description.\n");
1595
 
          tidy_out(doc, "These measures are needed for people using non-graphical browsers.\n\n");
1596
 
        }
1597
 
 
1598
 
        if (doc->badAccess & MISSING_IMAGE_MAP)
1599
 
        {
1600
 
          tidy_out(doc, "Use client-side image maps in preference to server-side image\n");
1601
 
          tidy_out(doc, "maps as the latter are inaccessible to people using non-\n");
1602
 
          tidy_out(doc, "graphical browsers. In addition, client-side maps are easier\n");
1603
 
          tidy_out(doc, "to set up and provide immediate feedback to users.\n\n");
1604
 
        }
1605
 
 
1606
 
        if (doc->badAccess & MISSING_LINK_ALT)
1607
 
        {
1608
 
          tidy_out(doc, "For hypertext links defined using a client-side image map, you\n");
1609
 
          tidy_out(doc, "need to use the alt attribute to provide a textual description\n");
1610
 
          tidy_out(doc, "of the link for people using non-graphical browsers.\n\n");
1611
 
        }
1612
 
 
1613
 
        if ((doc->badAccess & USING_FRAMES) && !(doc->badAccess & USING_NOFRAMES))
1614
 
        {
1615
 
          tidy_out(doc, "Pages designed using frames presents problems for\n");
1616
 
          tidy_out(doc, "people who are either blind or using a browser that\n");
1617
 
          tidy_out(doc, "doesn't support frames. A frames-based page should always\n");
1618
 
          tidy_out(doc, "include an alternative layout inside a NOFRAMES element.\n\n");
1619
 
        }
1620
 
 
1621
 
        tidy_out(doc, "For further advice on how to make your pages accessible\n");
1622
 
        tidy_out(doc, "see " );
1623
 
        tidy_out(doc, ACCESS_URL );
1624
1711
        tidy_out(doc, ". You may also want to try\n" );
1625
1712
        tidy_out(doc, "\"http://www.cast.org/bobby/\" which is a free Web-based\n");
1626
1713
        tidy_out(doc, "service for checking URLs for accessibility.\n\n");
1627
 
      }
1628
1714
    }
1629
1715
 
1630
1716
    if (doc->badLayout)
1665
1751
    }
1666
1752
}
1667
1753
 
1668
 
void UnknownOption( TidyDocImpl* doc, char c )
 
1754
#if 0
 
1755
void TY_(UnknownOption)( TidyDocImpl* doc, char c )
1669
1756
{
1670
1757
    message( doc, TidyConfig,
1671
1758
             "unrecognized option -%c use -help to list options\n", c );
1672
1759
}
1673
1760
 
1674
 
void UnknownFile( TidyDocImpl* doc, ctmbstr program, ctmbstr file )
 
1761
void TY_(UnknownFile)( TidyDocImpl* doc, ctmbstr program, ctmbstr file )
1675
1762
{
1676
1763
    message( doc, TidyConfig, 
1677
1764
             "%s: can't open file \"%s\"\n", program, file );
1678
1765
}
 
1766
#endif
1679
1767
 
1680
 
void NeedsAuthorIntervention( TidyDocImpl* doc )
 
1768
void TY_(NeedsAuthorIntervention)( TidyDocImpl* doc )
1681
1769
{
1682
1770
    tidy_out(doc, "This document has errors that must be fixed before\n");
1683
1771
    tidy_out(doc, "using HTML Tidy to generate a tidied up version.\n\n");
1684
1772
}
1685
1773
 
1686
 
void GeneralInfo( TidyDocImpl* doc )
 
1774
void TY_(GeneralInfo)( TidyDocImpl* doc )
1687
1775
{
1688
1776
    tidy_out(doc, "To learn more about HTML Tidy see http://tidy.sourceforge.net\n");
1689
 
    tidy_out(doc, "Please send bug reports to html-tidy@w3.org\n");
 
1777
    tidy_out(doc, "Please fill bug reports and queries using the \"tracker\" on the Tidy web site.\n");
 
1778
    tidy_out(doc, "Additionally, questions can be sent to html-tidy@w3.org\n");
1690
1779
    tidy_out(doc, "HTML and CSS specifications are available from http://www.w3.org/\n");
1691
1780
    tidy_out(doc, "Lobby your company to join W3C, see http://www.w3.org/Consortium\n");
1692
1781
}
1693
1782
 
1694
1783
#if SUPPORT_ACCESSIBILITY_CHECKS
1695
1784
 
1696
 
void AccessibilityHelloMessage( TidyDocImpl* doc )
 
1785
void TY_(AccessibilityHelloMessage)( TidyDocImpl* doc )
1697
1786
{
1698
1787
    tidy_out( doc, "\n" );
1699
1788
    tidy_out( doc, "Accessibility Checks: Version 0.1\n" );
1702
1791
 
1703
1792
#endif /* SUPPORT_ACCESSIBILITY_CHECKS */
1704
1793
 
1705
 
void HelloMessage( TidyDocImpl* doc, ctmbstr date, ctmbstr filename )
 
1794
#if 0
 
1795
void TY_(HelloMessage)( TidyDocImpl* doc, ctmbstr date, ctmbstr filename )
1706
1796
{
1707
1797
    tmbchar buf[ 2048 ];
1708
1798
    ctmbstr platform = "", helper = "";
1714
1804
    helper = " for ";
1715
1805
#endif
1716
1806
    
1717
 
    if ( tmbstrcmp(filename, "stdin") == 0 )
 
1807
    if ( TY_(tmbstrcmp)(filename, "stdin") == 0 )
1718
1808
    {
1719
1809
        /* Filename will be ignored at end of varargs */
1720
1810
        msgfmt = "\nHTML Tidy for %s (vers %s; built on %s, at %s)\n"
1721
1811
                 "Parsing console input (stdin)\n";
1722
1812
    }
1723
1813
    
1724
 
    tmbsnprintf(buf, sizeof(buf), msgfmt, helper, platform, 
1725
 
             date, __DATE__, __TIME__, filename);
 
1814
    TY_(tmbsnprintf)(buf, sizeof(buf), msgfmt, helper, platform, 
 
1815
                     date, __DATE__, __TIME__, filename);
1726
1816
    tidy_out( doc, buf );
1727
1817
}
 
1818
#endif
1728
1819
 
1729
 
void ReportMarkupVersion( TidyDocImpl* doc )
 
1820
void TY_(ReportMarkupVersion)( TidyDocImpl* doc )
1730
1821
{
1731
1822
    if (doc->givenDoctype)
1732
1823
    {
1740
1831
        uint apparentVers;
1741
1832
        ctmbstr vers;
1742
1833
 
1743
 
        apparentVers = ApparentVersion( doc );
 
1834
        apparentVers = TY_(ApparentVersion)( doc );
1744
1835
 
1745
 
        vers = HTMLVersionNameFromCode( apparentVers, isXhtml );
 
1836
        vers = TY_(HTMLVersionNameFromCode)( apparentVers, isXhtml );
1746
1837
 
1747
1838
        if (!vers)
1748
1839
            vers = "HTML Proprietary";
1749
1840
 
1750
1841
        message( doc, TidyInfo, "Document content looks like %s", vers );
 
1842
 
 
1843
        /* Warn about missing sytem identifier (SI) in emitted doctype */
 
1844
        if ( TY_(WarnMissingSIInEmittedDocType)( doc ) )
 
1845
            message( doc, TidyInfo, "No system identifier in emitted doctype" );
1751
1846
    }
1752
1847
}
1753
1848
 
1754
 
void ReportNumWarnings( TidyDocImpl* doc )
 
1849
void TY_(ReportNumWarnings)( TidyDocImpl* doc )
1755
1850
{
1756
1851
    if ( doc->warnings > 0 || doc->errors > 0 )
1757
1852
    {
1758
 
        tidy_out( doc, "%d %s, %d %s were found!",
 
1853
        tidy_out( doc, "%u %s, %u %s were found!",
1759
1854
                  doc->warnings, doc->warnings == 1 ? "warning" : "warnings",
1760
1855
                  doc->errors, doc->errors == 1 ? "error" : "errors" );
1761
1856
 
1768
1863
    else
1769
1864
        tidy_out( doc, "No warnings or errors were found.\n\n" );
1770
1865
}
 
1866
 
 
1867
/*
 
1868
 * local variables:
 
1869
 * mode: c
 
1870
 * indent-tabs-mode: nil
 
1871
 * c-basic-offset: 4
 
1872
 * eval: (c-set-offset 'substatement-open 0)
 
1873
 * end:
 
1874
 */