diff --git a/console/tidy.c b/console/tidy.c index 9e0619a..9f0d68e 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -1,11 +1,11 @@ /* tidy.c - HTML TidyLib command line driver - + Copyright (c) 1998-2008 World Wide Web Consortium (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved. - + */ #include "tidy.h" @@ -36,9 +36,9 @@ static FILE* errout = NULL; /* set to stderr */ static Bool samefile( ctmbstr filename1, ctmbstr filename2 ) { #if FILENAMES_CASE_SENSITIVE - return ( strcmp( filename1, filename2 ) == 0 ); + return ( strcmp( filename1, filename2 ) == 0 ); #else - return ( strcasecmp( filename1, filename2 ) == 0 ); + return ( strcasecmp( filename1, filename2 ) == 0 ); #endif } @@ -48,8 +48,8 @@ static Bool samefile( ctmbstr filename1, ctmbstr filename2 ) */ static void outOfMemory(void) { - fprintf(stderr, "%s", tidyLocalizedString(TC_STRING_OUT_OF_MEMORY)); - exit(1); + fprintf(stderr, "%s", tidyLocalizedString(TC_STRING_OUT_OF_MEMORY)); + exit(1); } @@ -58,46 +58,46 @@ static void outOfMemory(void) */ static const char *cutToWhiteSpace(const char *s, uint offset, char *sbuf) { - if (!s) - { - sbuf[0] = '\0'; - return NULL; - } - else if (strlen(s) <= offset) - { - strcpy(sbuf,s); - sbuf[offset] = '\0'; - return NULL; - } - else - { - uint j, l, n; - /* scan forward looking for newline */ - j = 0; - while(j < offset && s[j] != '\n') - ++j; - if ( j == offset ) { - /* scan backward looking for first space */ - j = offset; - while(j && s[j] != ' ') - --j; - l = j; - n = j+1; - /* no white space */ - if (j==0) - { - l = offset; - n = offset; - } - } else - { - l = j; - n = j+1; - } - strncpy(sbuf,s,l); - sbuf[l] = '\0'; - return s+n; - } + if (!s) + { + sbuf[0] = '\0'; + return NULL; + } + else if (strlen(s) <= offset) + { + strcpy(sbuf,s); + sbuf[offset] = '\0'; + return NULL; + } + else + { + uint j, l, n; + /* scan forward looking for newline */ + j = 0; + while(j < offset && s[j] != '\n') + ++j; + if ( j == offset ) { + /* scan backward looking for first space */ + j = offset; + while(j && s[j] != ' ') + --j; + l = j; + n = j+1; + /* no white space */ + if (j==0) + { + l = offset; + n = offset; + } + } else + { + l = j; + n = j+1; + } + strncpy(sbuf,s,l); + sbuf[l] = '\0'; + return s+n; + } } /** @@ -105,75 +105,74 @@ static const char *cutToWhiteSpace(const char *s, uint offset, char *sbuf) */ static void print1Column( const char* fmt, uint l1, const char *c1 ) { - const char *pc1=c1; - char *c1buf = (char *)malloc(l1+1); - if (!c1buf) outOfMemory(); - - do - { - pc1 = cutToWhiteSpace(pc1, l1, c1buf); - printf(fmt, c1buf[0] !='\0' ? c1buf : ""); - } while (pc1); - free(c1buf); + const char *pc1=c1; + char *c1buf = (char *)malloc(l1+1); + if (!c1buf) outOfMemory(); + + do + { + pc1 = cutToWhiteSpace(pc1, l1, c1buf); + printf(fmt, c1buf[0] !='\0' ? c1buf : ""); + } while (pc1); + free(c1buf); } /** ** Outputs two columns of text. */ static void print2Columns( const char* fmt, uint l1, uint l2, - const char *c1, const char *c2 ) + const char *c1, const char *c2 ) { - const char *pc1=c1, *pc2=c2; - char *c1buf = (char *)malloc(l1+1); - char *c2buf = (char *)malloc(l2+1); - if (!c1buf) outOfMemory(); - if (!c2buf) outOfMemory(); - - do - { - pc1 = cutToWhiteSpace(pc1, l1, c1buf); - pc2 = cutToWhiteSpace(pc2, l2, c2buf); - printf(fmt, - c1buf[0]!='\0'?c1buf:"", - c2buf[0]!='\0'?c2buf:""); - } while (pc1 || pc2); - free(c1buf); - free(c2buf); + const char *pc1=c1, *pc2=c2; + char *c1buf = (char *)malloc(l1+1); + char *c2buf = (char *)malloc(l2+1); + if (!c1buf) outOfMemory(); + if (!c2buf) outOfMemory(); + + do + { + pc1 = cutToWhiteSpace(pc1, l1, c1buf); + pc2 = cutToWhiteSpace(pc2, l2, c2buf); + printf(fmt, + c1buf[0]!='\0'?c1buf:"", + c2buf[0]!='\0'?c2buf:""); + } while (pc1 || pc2); + free(c1buf); + free(c2buf); } /** ** Outputs three columns of text. */ static void print3Columns( const char* fmt, uint l1, uint l2, uint l3, - const char *c1, const char *c2, const char *c3 ) + const char *c1, const char *c2, const char *c3 ) { - const char *pc1=c1, *pc2=c2, *pc3=c3; - char *c1buf = (char *)malloc(l1+1); - char *c2buf = (char *)malloc(l2+1); - char *c3buf = (char *)malloc(l3+1); - if (!c1buf) outOfMemory(); - if (!c2buf) outOfMemory(); - if (!c3buf) outOfMemory(); - - do - { - pc1 = cutToWhiteSpace(pc1, l1, c1buf); - pc2 = cutToWhiteSpace(pc2, l2, c2buf); - pc3 = cutToWhiteSpace(pc3, l3, c3buf); - printf(fmt, - c1buf[0]!='\0'?c1buf:"", - c2buf[0]!='\0'?c2buf:"", - c3buf[0]!='\0'?c3buf:""); - } while (pc1 || pc2 || pc3); - free(c1buf); - free(c2buf); - free(c3buf); + const char *pc1=c1, *pc2=c2, *pc3=c3; + char *c1buf = (char *)malloc(l1+1); + char *c2buf = (char *)malloc(l2+1); + char *c3buf = (char *)malloc(l3+1); + if (!c1buf) outOfMemory(); + if (!c2buf) outOfMemory(); + if (!c3buf) outOfMemory(); + + do + { + pc1 = cutToWhiteSpace(pc1, l1, c1buf); + pc2 = cutToWhiteSpace(pc2, l2, c2buf); + pc3 = cutToWhiteSpace(pc3, l3, c3buf); + printf(fmt, + c1buf[0]!='\0'?c1buf:"", + c2buf[0]!='\0'?c2buf:"", + c3buf[0]!='\0'?c3buf:""); + } while (pc1 || pc2 || pc3); + free(c1buf); + free(c2buf); + free(c3buf); } /** ** Format strings and decorations used in output. */ -//static const char helpfmt[] = " %-19.19s %-58.58s\n"; static const char helpfmt[] = " %-25.25s %-52.52s\n"; static const char helpul[] = "-----------------------------------------------------------------"; static const char fmt[] = "%-27.27s %-9.9s %-40.40s\n"; @@ -185,27 +184,27 @@ static const char ul[] = "================================================= */ typedef enum { - CmdOptFileManip, - CmdOptCatFIRST = CmdOptFileManip, - CmdOptProcDir, - CmdOptCharEnc, - CmdOptMisc, - CmdOptXML, - CmdOptCatLAST + CmdOptFileManip, + CmdOptCatFIRST = CmdOptFileManip, + CmdOptProcDir, + CmdOptCharEnc, + CmdOptMisc, + CmdOptXML, + CmdOptCatLAST } CmdOptCategory; /** ** This array contains headings that will be used in help ouput. */ static const struct { - ctmbstr mnemonic; /**< Used in XML as a class. */ - uint key; /**< Key to fetch the localized string. */ + ctmbstr mnemonic; /**< Used in XML as a class. */ + uint key; /**< Key to fetch the localized string. */ } cmdopt_catname[] = { - { "file-manip", TC_STRING_FILE_MANIP }, - { "process-directives", TC_STRING_PROCESS_DIRECTIVES }, - { "char-encoding", TC_STRING_CHAR_ENCODING }, - { "misc", TC_STRING_MISC }, - { "xml", TC_STRING_XML } + { "file-manip", TC_STRING_FILE_MANIP }, + { "process-directives", TC_STRING_PROCESS_DIRECTIVES }, + { "char-encoding", TC_STRING_CHAR_ENCODING }, + { "misc", TC_STRING_MISC }, + { "xml", TC_STRING_XML } }; /** @@ -213,69 +212,69 @@ static const struct { ** because we _also_ output all of this stuff as as XML. */ typedef struct { - CmdOptCategory cat; /**< Category */ - ctmbstr name1; /**< Name */ - uint key; /**< Key to fetch the localized description. */ - uint subKey; /**< Secondary substitution key. */ - ctmbstr eqconfig; /**< Equivalent configuration option */ - ctmbstr name2; /**< Name */ - ctmbstr name3; /**< Name */ + CmdOptCategory cat; /**< Category */ + ctmbstr name1; /**< Name */ + uint key; /**< Key to fetch the localized description. */ + uint subKey; /**< Secondary substitution key. */ + ctmbstr eqconfig; /**< Equivalent configuration option */ + ctmbstr name2; /**< Name */ + ctmbstr name3; /**< Name */ } CmdOptDesc; /* All instances of %s will be substituted with localized string specified by the subKey field. */ static const CmdOptDesc cmdopt_defs[] = { - { CmdOptFileManip, "-output <%s>", TC_OPT_OUTPUT, TC_LABEL_FILE, "output-file: <%s>", "-o <%s>" }, - { CmdOptFileManip, "-config <%s>", TC_OPT_CONFIG, TC_LABEL_FILE, NULL }, - { CmdOptFileManip, "-file <%s>", TC_OPT_FILE, TC_LABEL_FILE, "error-file: <%s>", "-f <%s>" }, - { CmdOptFileManip, "-modify", TC_OPT_MODIFY, 0, "write-back: yes", "-m" }, - { CmdOptProcDir, "-indent", TC_OPT_INDENT, 0, "indent: auto", "-i" }, - { CmdOptProcDir, "-wrap <%s>", TC_OPT_WRAP, TC_LABEL_COL, "wrap: <%s>", "-w <%s>" }, - { CmdOptProcDir, "-upper", TC_OPT_UPPER, 0, "uppercase-tags: yes", "-u" }, - { CmdOptProcDir, "-clean", TC_OPT_CLEAN, 0, "clean: yes", "-c" }, - { CmdOptProcDir, "-bare", TC_OPT_BARE, 0, "bare: yes", "-b" }, - { CmdOptProcDir, "-gdoc", TC_OPT_GDOC, 0, "gdoc: yes", "-g" }, - { CmdOptProcDir, "-numeric", TC_OPT_NUMERIC, 0, "numeric-entities: yes", "-n" }, - { CmdOptProcDir, "-errors", TC_OPT_ERRORS, 0, "markup: no", "-e" }, - { CmdOptProcDir, "-quiet", TC_OPT_QUIET, 0, "quiet: yes", "-q" }, - { CmdOptProcDir, "-omit", TC_OPT_OMIT, 0, "omit-optional-tags: yes" }, - { CmdOptProcDir, "-xml", TC_OPT_XML, 0, "input-xml: yes" }, - { CmdOptProcDir, "-asxml", TC_OPT_ASXML, 0, "output-xhtml: yes", "-asxhtml" }, - { CmdOptProcDir, "-ashtml", TC_OPT_ASHTML, 0, "output-html: yes" }, + { CmdOptFileManip, "-output <%s>", TC_OPT_OUTPUT, TC_LABEL_FILE, "output-file: <%s>", "-o <%s>" }, + { CmdOptFileManip, "-config <%s>", TC_OPT_CONFIG, TC_LABEL_FILE, NULL }, + { CmdOptFileManip, "-file <%s>", TC_OPT_FILE, TC_LABEL_FILE, "error-file: <%s>", "-f <%s>" }, + { CmdOptFileManip, "-modify", TC_OPT_MODIFY, 0, "write-back: yes", "-m" }, + { CmdOptProcDir, "-indent", TC_OPT_INDENT, 0, "indent: auto", "-i" }, + { CmdOptProcDir, "-wrap <%s>", TC_OPT_WRAP, TC_LABEL_COL, "wrap: <%s>", "-w <%s>" }, + { CmdOptProcDir, "-upper", TC_OPT_UPPER, 0, "uppercase-tags: yes", "-u" }, + { CmdOptProcDir, "-clean", TC_OPT_CLEAN, 0, "clean: yes", "-c" }, + { CmdOptProcDir, "-bare", TC_OPT_BARE, 0, "bare: yes", "-b" }, + { CmdOptProcDir, "-gdoc", TC_OPT_GDOC, 0, "gdoc: yes", "-g" }, + { CmdOptProcDir, "-numeric", TC_OPT_NUMERIC, 0, "numeric-entities: yes", "-n" }, + { CmdOptProcDir, "-errors", TC_OPT_ERRORS, 0, "markup: no", "-e" }, + { CmdOptProcDir, "-quiet", TC_OPT_QUIET, 0, "quiet: yes", "-q" }, + { CmdOptProcDir, "-omit", TC_OPT_OMIT, 0, "omit-optional-tags: yes" }, + { CmdOptProcDir, "-xml", TC_OPT_XML, 0, "input-xml: yes" }, + { CmdOptProcDir, "-asxml", TC_OPT_ASXML, 0, "output-xhtml: yes", "-asxhtml" }, + { CmdOptProcDir, "-ashtml", TC_OPT_ASHTML, 0, "output-html: yes" }, #if SUPPORT_ACCESSIBILITY_CHECKS - { CmdOptProcDir, "-access <%s>", TC_OPT_ACCESS, TC_LABEL_LEVL, "accessibility-check: <%s>" }, + { CmdOptProcDir, "-access <%s>", TC_OPT_ACCESS, TC_LABEL_LEVL, "accessibility-check: <%s>" }, #endif - { CmdOptCharEnc, "-raw", TC_OPT_RAW, 0, NULL }, - { CmdOptCharEnc, "-ascii", TC_OPT_ASCII, 0, NULL }, - { CmdOptCharEnc, "-latin0", TC_OPT_LATIN0, 0, NULL }, - { CmdOptCharEnc, "-latin1", TC_OPT_LATIN1, 0, NULL }, + { CmdOptCharEnc, "-raw", TC_OPT_RAW, 0, NULL }, + { CmdOptCharEnc, "-ascii", TC_OPT_ASCII, 0, NULL }, + { CmdOptCharEnc, "-latin0", TC_OPT_LATIN0, 0, NULL }, + { CmdOptCharEnc, "-latin1", TC_OPT_LATIN1, 0, NULL }, #ifndef NO_NATIVE_ISO2022_SUPPORT - { CmdOptCharEnc, "-iso2022", TC_OPT_ISO2022, 0, NULL }, + { CmdOptCharEnc, "-iso2022", TC_OPT_ISO2022, 0, NULL }, #endif - { CmdOptCharEnc, "-utf8", TC_OPT_UTF8, 0, NULL }, - { CmdOptCharEnc, "-mac", TC_OPT_MAC, 0, NULL }, - { CmdOptCharEnc, "-win1252", TC_OPT_WIN1252, 0, NULL }, - { CmdOptCharEnc, "-ibm858", TC_OPT_IBM858, 0, NULL }, + { CmdOptCharEnc, "-utf8", TC_OPT_UTF8, 0, NULL }, + { CmdOptCharEnc, "-mac", TC_OPT_MAC, 0, NULL }, + { CmdOptCharEnc, "-win1252", TC_OPT_WIN1252, 0, NULL }, + { CmdOptCharEnc, "-ibm858", TC_OPT_IBM858, 0, NULL }, #if SUPPORT_UTF16_ENCODINGS - { CmdOptCharEnc, "-utf16le", TC_OPT_UTF16LE, 0, NULL }, - { CmdOptCharEnc, "-utf16be", TC_OPT_UTF16BE, 0, NULL }, - { CmdOptCharEnc, "-utf16", TC_OPT_UTF16, 0, NULL }, + { CmdOptCharEnc, "-utf16le", TC_OPT_UTF16LE, 0, NULL }, + { CmdOptCharEnc, "-utf16be", TC_OPT_UTF16BE, 0, NULL }, + { CmdOptCharEnc, "-utf16", TC_OPT_UTF16, 0, NULL }, #endif #if SUPPORT_ASIAN_ENCODINGS /* #431953 - RJ */ - { CmdOptCharEnc, "-big5", TC_OPT_BIG5, 0, NULL }, - { CmdOptCharEnc, "-shiftjis", TC_OPT_SHIFTJIS, 0, NULL }, + { CmdOptCharEnc, "-big5", TC_OPT_BIG5, 0, NULL }, + { CmdOptCharEnc, "-shiftjis", TC_OPT_SHIFTJIS, 0, NULL }, #endif - { CmdOptMisc, "-version", TC_OPT_VERSION, 0, NULL, "-v" }, - { CmdOptMisc, "-help", TC_OPT_HELP, 0, NULL, "-h", "-?" }, - { CmdOptMisc, "-help-config", TC_OPT_HELPCFG, 0, NULL }, - { CmdOptMisc, "-show-config", TC_OPT_SHOWCFG, 0, NULL }, - { CmdOptMisc, "-help-option <%s>", TC_OPT_HELPOPT, TC_LABEL_OPT, NULL }, - { CmdOptMisc, "-language <%s>", TC_OPT_LANGUAGE, TC_LABEL_LANG, "language: <%s>" }, - { CmdOptXML, "-xml-help", TC_OPT_XMLHELP, 0, NULL }, - { CmdOptXML, "-xml-config", TC_OPT_XMLCFG, 0, NULL }, - { CmdOptXML, "-xml-strings", TC_OPT_XMLSTRG, 0, NULL }, - { CmdOptXML, "-xml-options-strings", TC_OPT_XMLOPTS, 0, NULL }, - { CmdOptMisc, NULL, 0, 0, NULL } + { CmdOptMisc, "-version", TC_OPT_VERSION, 0, NULL, "-v" }, + { CmdOptMisc, "-help", TC_OPT_HELP, 0, NULL, "-h", "-?" }, + { CmdOptMisc, "-help-config", TC_OPT_HELPCFG, 0, NULL }, + { CmdOptMisc, "-show-config", TC_OPT_SHOWCFG, 0, NULL }, + { CmdOptMisc, "-help-option <%s>", TC_OPT_HELPOPT, TC_LABEL_OPT, NULL }, + { CmdOptMisc, "-language <%s>", TC_OPT_LANGUAGE, TC_LABEL_LANG, "language: <%s>" }, + { CmdOptXML, "-xml-help", TC_OPT_XMLHELP, 0, NULL }, + { CmdOptXML, "-xml-config", TC_OPT_XMLCFG, 0, NULL }, + { CmdOptXML, "-xml-strings", TC_OPT_XMLSTRG, 0, NULL }, + { CmdOptXML, "-xml-options-strings", TC_OPT_XMLOPTS, 0, NULL }, + { CmdOptMisc, NULL, 0, 0, NULL } }; /** @@ -283,22 +282,22 @@ static const CmdOptDesc cmdopt_defs[] = { */ static tmbstr stringWithFormat( const ctmbstr fmt, ... ) { - va_list argList; - tmbstr result = NULL; - int len = 0; - - va_start(argList, fmt); - len = vsnprintf( result, 0, fmt, argList ); - va_end(argList); - - if (!(result = malloc( len + 1) )) - outOfMemory(); - - va_start(argList, fmt); - vsnprintf( result, len + 1, fmt, argList); - va_end(argList); - - return result; + va_list argList; + tmbstr result = NULL; + int len = 0; + + va_start(argList, fmt); + len = vsnprintf( result, 0, fmt, argList ); + va_end(argList); + + if (!(result = malloc( len + 1) )) + outOfMemory(); + + va_start(argList, fmt); + vsnprintf( result, len + 1, fmt, argList); + va_end(argList); + + return result; } @@ -308,12 +307,12 @@ static tmbstr stringWithFormat( const ctmbstr fmt, ... ) */ static void localize_option_names( CmdOptDesc *pos) { - ctmbstr fileString = tidyLocalizedString(pos->subKey); - pos->name1 = stringWithFormat(pos->name1, fileString); - if ( pos->name2 ) - pos->name2 = stringWithFormat(pos->name2, fileString); - if ( pos->name3 ) - pos->name3 = stringWithFormat(pos->name3, fileString); + ctmbstr fileString = tidyLocalizedString(pos->subKey); + pos->name1 = stringWithFormat(pos->name1, fileString); + if ( pos->name2 ) + pos->name2 = stringWithFormat(pos->name2, fileString); + if ( pos->name3 ) + pos->name3 = stringWithFormat(pos->name3, fileString); } /** @@ -322,35 +321,35 @@ static void localize_option_names( CmdOptDesc *pos) */ static tmbstr get_option_names( const CmdOptDesc* pos ) { - tmbstr name; - uint len; - CmdOptDesc localPos = *pos; - - localize_option_names( &localPos ); - - len = strlen(localPos.name1); - if (localPos.name2) - len += 2+strlen(localPos.name2); - if (localPos.name3) - len += 2+strlen(localPos.name3); - - name = (tmbstr)malloc(len+1); - if (!name) outOfMemory(); - strcpy(name, localPos.name1); - free((tmbstr)localPos.name1); - if (localPos.name2) - { - strcat(name, ", "); - strcat(name, localPos.name2); - free((tmbstr)localPos.name2); - } - if (localPos.name3) - { - strcat(name, ", "); - strcat(name, localPos.name3); - free((tmbstr)localPos.name3); - } - return name; + tmbstr name; + uint len; + CmdOptDesc localPos = *pos; + + localize_option_names( &localPos ); + + len = strlen(localPos.name1); + if (localPos.name2) + len += 2+strlen(localPos.name2); + if (localPos.name3) + len += 2+strlen(localPos.name3); + + name = (tmbstr)malloc(len+1); + if (!name) outOfMemory(); + strcpy(name, localPos.name1); + free((tmbstr)localPos.name1); + if (localPos.name2) + { + strcat(name, ", "); + strcat(name, localPos.name2); + free((tmbstr)localPos.name2); + } + if (localPos.name3) + { + strcat(name, ", "); + strcat(name, localPos.name3); + free((tmbstr)localPos.name3); + } + return name; } /** @@ -358,49 +357,49 @@ static tmbstr get_option_names( const CmdOptDesc* pos ) */ static tmbstr get_escaped_name( ctmbstr name ) { - tmbstr escpName; - char aux[2]; - uint len = 0; - ctmbstr c; - for(c=name; *c!='\0'; ++c) - switch(*c) - { - case '<': - case '>': - len += 4; - break; - case '"': - len += 6; - break; - default: - len += 1; - break; - } - - escpName = (tmbstr)malloc(len+1); - if (!escpName) outOfMemory(); - escpName[0] = '\0'; - - aux[1] = '\0'; - for(c=name; *c!='\0'; ++c) - switch(*c) - { - case '<': - strcat(escpName, "<"); - break; - case '>': - strcat(escpName, ">"); - break; - case '"': - strcat(escpName, """); - break; - default: - aux[0] = *c; - strcat(escpName, aux); - break; - } - - return escpName; + tmbstr escpName; + char aux[2]; + uint len = 0; + ctmbstr c; + for(c=name; *c!='\0'; ++c) + switch(*c) + { + case '<': + case '>': + len += 4; + break; + case '"': + len += 6; + break; + default: + len += 1; + break; + } + + escpName = (tmbstr)malloc(len+1); + if (!escpName) outOfMemory(); + escpName[0] = '\0'; + + aux[1] = '\0'; + for(c=name; *c!='\0'; ++c) + switch(*c) + { + case '<': + strcat(escpName, "<"); + break; + case '>': + strcat(escpName, ">"); + break; + case '"': + strcat(escpName, """); + break; + default: + aux[0] = *c; + strcat(escpName, aux); + break; + } + + return escpName; } /** @@ -408,26 +407,26 @@ static tmbstr get_escaped_name( ctmbstr name ) */ static void print_help_option( void ) { - CmdOptCategory cat = CmdOptCatFIRST; - const CmdOptDesc* pos = cmdopt_defs; - - for( cat=CmdOptCatFIRST; cat!=CmdOptCatLAST; ++cat) - { - ctmbstr name = tidyLocalizedString(cmdopt_catname[cat].key); - size_t len = strlen(name); - printf("%s\n", name ); - printf("%*.*s\n", (int)len, (int)len, helpul ); - for( pos=cmdopt_defs; pos->name1; ++pos) - { - tmbstr name; - if (pos->cat != cat) - continue; - name = get_option_names( pos ); - print2Columns( helpfmt, 25, 52, name, tidyLocalizedString( pos->key ) ); - free(name); - } - printf("\n"); - } + CmdOptCategory cat = CmdOptCatFIRST; + const CmdOptDesc* pos = cmdopt_defs; + + for( cat=CmdOptCatFIRST; cat!=CmdOptCatLAST; ++cat) + { + ctmbstr name = tidyLocalizedString(cmdopt_catname[cat].key); + size_t len = strlen(name); + printf("%s\n", name ); + printf("%*.*s\n", (int)len, (int)len, helpul ); + for( pos=cmdopt_defs; pos->name1; ++pos) + { + tmbstr name; + if (pos->cat != cat) + continue; + name = get_option_names( pos ); + print2Columns( helpfmt, 25, 52, name, tidyLocalizedString( pos->key ) ); + free(name); + } + printf("\n"); + } } /** @@ -435,12 +434,12 @@ static void print_help_option( void ) */ static void print_xml_help_option_element( ctmbstr element, ctmbstr name ) { - tmbstr escpName; - if (!name) - return; - printf(" <%s>%s\n", element, escpName = get_escaped_name(name), - element); - free(escpName); + tmbstr escpName; + if (!name) + return; + printf(" <%s>%s\n", element, escpName = get_escaped_name(name), + element); + free(escpName); } /** @@ -448,21 +447,21 @@ static void print_xml_help_option_element( ctmbstr element, ctmbstr name ) */ static void print_xml_help_option( void ) { - const CmdOptDesc* pos = cmdopt_defs; - - for( pos=cmdopt_defs; pos->name1; ++pos) - { - printf(" \n"); - } + const CmdOptDesc* pos = cmdopt_defs; + + for( pos=cmdopt_defs; pos->name1; ++pos) + { + printf(" \n"); + } } /** @@ -470,10 +469,10 @@ static void print_xml_help_option( void ) */ static void xml_help( void ) { - printf( "\n" - "\n", tidyLibraryVersion()); - print_xml_help_option(); - printf( "\n" ); + printf( "\n" + "\n", tidyLibraryVersion()); + print_xml_help_option(); + printf( "\n" ); } /** @@ -481,15 +480,15 @@ static void xml_help( void ) */ static ctmbstr get_final_name( ctmbstr prog ) { - ctmbstr name = prog; - int c; - size_t i, len = strlen(prog); - for (i = 0; i < len; i++) { - c = prog[i]; - if ((( c == '/' ) || ( c == '\\' )) && prog[i+1]) - name = &prog[i+1]; - } - return name; + ctmbstr name = prog; + int c; + size_t i, len = strlen(prog); + for (i = 0; i < len; i++) { + c = prog[i]; + if ((( c == '/' ) || ( c == '\\' )) && prog[i+1]) + name = &prog[i+1]; + } + return name; } /** @@ -497,23 +496,23 @@ static ctmbstr get_final_name( ctmbstr prog ) */ static void help( ctmbstr prog ) { - tmbstr title_line = NULL; - - printf( tidyLocalizedString(TC_TXT_HELP_1), get_final_name(prog),tidyLibraryVersion() ); - + tmbstr title_line = NULL; + + printf( tidyLocalizedString(TC_TXT_HELP_1), get_final_name(prog),tidyLibraryVersion() ); + #ifdef PLATFORM_NAME - title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2A), PLATFORM_NAME); + title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2A), PLATFORM_NAME); #else - title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2B) ); + title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2B) ); #endif - printf( "%s\n", title_line ); - printf("%*.*s\n", (int)strlen(title_line), (int)strlen(title_line), ul); - free( title_line ); - printf( "\n"); - - print_help_option(); - - printf( "%s", tidyLocalizedString(TC_TXT_HELP_3) ); + printf( "%s\n", title_line ); + printf("%*.*s\n", (int)strlen(title_line), (int)strlen(title_line), ul); + free( title_line ); + printf( "\n"); + + print_help_option(); + + printf( "%s", tidyLocalizedString(TC_TXT_HELP_3) ); } /** @@ -521,20 +520,20 @@ static void help( ctmbstr prog ) */ static Bool isAutoBool( TidyOption topt ) { - TidyIterator pos; - ctmbstr def; - - if ( tidyOptGetType( topt ) != TidyInteger) - return no; - - pos = tidyOptGetPickList( topt ); - while ( pos ) - { - def = tidyOptGetNextPick( topt, &pos ); - if (0==strcmp(def,"yes")) - return yes; - } - return no; + TidyIterator pos; + ctmbstr def; + + if ( tidyOptGetType( topt ) != TidyInteger) + return no; + + pos = tidyOptGetPickList( topt ); + while ( pos ) + { + def = tidyOptGetNextPick( topt, &pos ); + if (0==strcmp(def,"yes")) + return yes; + } + return no; } /** @@ -544,38 +543,38 @@ static Bool isAutoBool( TidyOption topt ) */ static ctmbstr ConfigCategoryName( TidyConfigCategory id ) { - switch( id ) - { - case TidyMarkup: - return tidyLocalizedString( TC_CAT_MARKUP ); - case TidyDiagnostics: - return tidyLocalizedString( TC_CAT_DIAGNOSTICS ); - case TidyPrettyPrint: - return tidyLocalizedString( TC_CAT_PRETTYPRINT ); - case TidyEncoding: - return tidyLocalizedString( TC_CAT_ENCODING ); - case TidyMiscellaneous: - return tidyLocalizedString( TC_CAT_MISC ); - } - fprintf(stderr, tidyLocalizedString(TC_STRING_FATAL_ERROR), (int)id); + switch( id ) + { + case TidyMarkup: + return tidyLocalizedString( TC_CAT_MARKUP ); + case TidyDiagnostics: + return tidyLocalizedString( TC_CAT_DIAGNOSTICS ); + case TidyPrettyPrint: + return tidyLocalizedString( TC_CAT_PRETTYPRINT ); + case TidyEncoding: + return tidyLocalizedString( TC_CAT_ENCODING ); + case TidyMiscellaneous: + return tidyLocalizedString( TC_CAT_MISC ); + } + fprintf(stderr, tidyLocalizedString(TC_STRING_FATAL_ERROR), (int)id); fprintf(stderr, "\n"); - assert(0); - abort(); - return "never_here"; /* only for the compiler warning */ + assert(0); + abort(); + return "never_here"; /* only for the compiler warning */ } /** ** Structure maintains a description of an option. */ typedef struct { - ctmbstr name; /**< Name */ - ctmbstr cat; /**< Category */ - ctmbstr type; /**< "String, ... */ - ctmbstr vals; /**< Potential values. If NULL, use an external function */ - ctmbstr def; /**< default */ - tmbchar tempdefs[80]; /**< storage for default such as integer */ - Bool haveVals; /**< if yes, vals is valid */ + ctmbstr name; /**< Name */ + ctmbstr cat; /**< Category */ + ctmbstr type; /**< "String, ... */ + ctmbstr vals; /**< Potential values. If NULL, use an external function */ + ctmbstr def; /**< default */ + tmbchar tempdefs[80]; /**< storage for default such as integer */ + Bool haveVals; /**< if yes, vals is valid */ } OptionDesc; typedef void (*OptionFunc)( TidyDoc, TidyOption, OptionDesc * ); @@ -587,109 +586,109 @@ typedef void (*OptionFunc)( TidyDoc, TidyOption, OptionDesc * ); static void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) { - TidyOptionId optId = tidyOptGetId( topt ); - TidyOptionType optTyp = tidyOptGetType( topt ); - - d->name = tidyOptGetName( topt ); - d->cat = ConfigCategoryName( tidyOptGetCategory( topt ) ); - d->vals = NULL; - d->def = NULL; - d->haveVals = yes; - - /* Handle special cases first. - */ - switch ( optId ) - { - case TidyDuplicateAttrs: - case TidySortAttributes: - case TidyNewline: - case TidyAccessibilityCheckLevel: - d->type = "enum"; - d->vals = NULL; - d->def = - optId==TidyNewline ? - "Platform dependent" - :tidyOptGetCurrPick( tdoc, optId ); - break; - - case TidyDoctype: - d->type = "DocType"; - d->vals = NULL; - { - ctmbstr sdef = NULL; - sdef = tidyOptGetCurrPick( tdoc, TidyDoctypeMode ); - if ( !sdef || *sdef == '*' ) - sdef = tidyOptGetValue( tdoc, TidyDoctype ); - d->def = sdef; - } - break; - - case TidyInlineTags: - case TidyBlockTags: - case TidyEmptyTags: - case TidyPreTags: - d->type = "Tag names"; - d->vals = "tagX, tagY, ..."; - d->def = NULL; - break; - - case TidyCharEncoding: - case TidyInCharEncoding: - case TidyOutCharEncoding: - d->type = "Encoding"; - d->def = tidyOptGetEncName( tdoc, optId ); - if (!d->def) - d->def = "?"; - d->vals = NULL; - break; - - /* General case will handle remaining */ - default: - switch ( optTyp ) - { - case TidyBoolean: - d->type = "Boolean"; - d->vals = "y/n, yes/no, t/f, true/false, 1/0"; - d->def = tidyOptGetCurrPick( tdoc, optId ); - break; - - case TidyInteger: - if (isAutoBool(topt)) - { - d->type = "AutoBool"; - d->vals = "auto, y/n, yes/no, t/f, true/false, 1/0"; - d->def = tidyOptGetCurrPick( tdoc, optId ); - } - else - { - uint idef; - d->type = "Integer"; - if ( optId == TidyWrapLen ) - d->vals = "0 (no wrapping), 1, 2, ..."; - else - d->vals = "0, 1, 2, ..."; - - idef = tidyOptGetInt( tdoc, optId ); - sprintf(d->tempdefs, "%u", idef); - d->def = d->tempdefs; - } - break; - - case TidyString: - d->type = "String"; - d->vals = NULL; - d->haveVals = no; - d->def = tidyOptGetValue( tdoc, optId ); - break; - } - } + TidyOptionId optId = tidyOptGetId( topt ); + TidyOptionType optTyp = tidyOptGetType( topt ); + + d->name = tidyOptGetName( topt ); + d->cat = ConfigCategoryName( tidyOptGetCategory( topt ) ); + d->vals = NULL; + d->def = NULL; + d->haveVals = yes; + + /* Handle special cases first. + */ + switch ( optId ) + { + case TidyDuplicateAttrs: + case TidySortAttributes: + case TidyNewline: + case TidyAccessibilityCheckLevel: + d->type = "enum"; + d->vals = NULL; + d->def = + optId==TidyNewline ? + "Platform dependent" + :tidyOptGetCurrPick( tdoc, optId ); + break; + + case TidyDoctype: + d->type = "DocType"; + d->vals = NULL; + { + ctmbstr sdef = NULL; + sdef = tidyOptGetCurrPick( tdoc, TidyDoctypeMode ); + if ( !sdef || *sdef == '*' ) + sdef = tidyOptGetValue( tdoc, TidyDoctype ); + d->def = sdef; + } + break; + + case TidyInlineTags: + case TidyBlockTags: + case TidyEmptyTags: + case TidyPreTags: + d->type = "Tag names"; + d->vals = "tagX, tagY, ..."; + d->def = NULL; + break; + + case TidyCharEncoding: + case TidyInCharEncoding: + case TidyOutCharEncoding: + d->type = "Encoding"; + d->def = tidyOptGetEncName( tdoc, optId ); + if (!d->def) + d->def = "?"; + d->vals = NULL; + break; + + /* General case will handle remaining */ + default: + switch ( optTyp ) + { + case TidyBoolean: + d->type = "Boolean"; + d->vals = "y/n, yes/no, t/f, true/false, 1/0"; + d->def = tidyOptGetCurrPick( tdoc, optId ); + break; + + case TidyInteger: + if (isAutoBool(topt)) + { + d->type = "AutoBool"; + d->vals = "auto, y/n, yes/no, t/f, true/false, 1/0"; + d->def = tidyOptGetCurrPick( tdoc, optId ); + } + else + { + uint idef; + d->type = "Integer"; + if ( optId == TidyWrapLen ) + d->vals = "0 (no wrapping), 1, 2, ..."; + else + d->vals = "0, 1, 2, ..."; + + idef = tidyOptGetInt( tdoc, optId ); + sprintf(d->tempdefs, "%u", idef); + d->def = d->tempdefs; + } + break; + + case TidyString: + d->type = "String"; + d->vals = NULL; + d->haveVals = no; + d->def = tidyOptGetValue( tdoc, optId ); + break; + } + } } /** ** Array holding all options. Contains a trailing sentinel. */ typedef struct { - TidyOption topt[N_TIDY_OPTIONS]; + TidyOption topt[N_TIDY_OPTIONS]; } AllOption_t; /** @@ -697,9 +696,9 @@ typedef struct { **/ static int cmpOpt(const void* e1_, const void *e2_) { - const TidyOption* e1 = (const TidyOption*)e1_; - const TidyOption* e2 = (const TidyOption*)e2_; - return strcmp(tidyOptGetName(*e1), tidyOptGetName(*e2)); + const TidyOption* e1 = (const TidyOption*)e1_; + const TidyOption* e2 = (const TidyOption*)e2_; + return strcmp(tidyOptGetName(*e1), tidyOptGetName(*e2)); } /** @@ -707,22 +706,22 @@ static int cmpOpt(const void* e1_, const void *e2_) **/ static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption ) { - TidyIterator pos = tidyGetOptionList( tdoc ); - uint i = 0; - - while ( pos ) - { - TidyOption topt = tidyGetNextOption( tdoc, &pos ); - tOption->topt[i] = topt; - ++i; - } - tOption->topt[i] = NULL; /* sentinel */ - - qsort(tOption->topt, - /* Do not sort the sentinel: hence `-1' */ - sizeof(tOption->topt)/sizeof(tOption->topt[0])-1, - sizeof(tOption->topt[0]), - cmpOpt); + TidyIterator pos = tidyGetOptionList( tdoc ); + uint i = 0; + + while ( pos ) + { + TidyOption topt = tidyGetNextOption( tdoc, &pos ); + tOption->topt[i] = topt; + ++i; + } + tOption->topt[i] = NULL; /* sentinel */ + + qsort(tOption->topt, + /* Do not sort the sentinel: hence `-1' */ + sizeof(tOption->topt)/sizeof(tOption->topt[0])-1, + sizeof(tOption->topt[0]), + cmpOpt); } /** @@ -730,17 +729,17 @@ static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption ) **/ static void ForEachSortedOption( TidyDoc tdoc, OptionFunc OptionPrint ) { - AllOption_t tOption; - const TidyOption *topt; - - getSortedOption( tdoc, &tOption ); - for( topt = tOption.topt; *topt; ++topt) - { - OptionDesc d; - - GetOption( tdoc, *topt, &d ); - (*OptionPrint)( tdoc, *topt, &d ); - } + AllOption_t tOption; + const TidyOption *topt; + + getSortedOption( tdoc, &tOption ); + for( topt = tOption.topt; *topt; ++topt) + { + OptionDesc d; + + GetOption( tdoc, *topt, &d ); + (*OptionPrint)( tdoc, *topt, &d ); + } } /** @@ -748,16 +747,16 @@ static void ForEachSortedOption( TidyDoc tdoc, OptionFunc OptionPrint ) **/ static void ForEachOption( TidyDoc tdoc, OptionFunc OptionPrint ) { - TidyIterator pos = tidyGetOptionList( tdoc ); - - while ( pos ) - { - TidyOption topt = tidyGetNextOption( tdoc, &pos ); - OptionDesc d; - - GetOption( tdoc, topt, &d ); - (*OptionPrint)( tdoc, topt, &d ); - } + TidyIterator pos = tidyGetOptionList( tdoc ); + + while ( pos ) + { + TidyOption topt = tidyGetNextOption( tdoc, &pos ); + OptionDesc d; + + GetOption( tdoc, topt, &d ); + (*OptionPrint)( tdoc, topt, &d ); + } } /** @@ -765,18 +764,18 @@ static void ForEachOption( TidyDoc tdoc, OptionFunc OptionPrint ) **/ static void PrintAllowedValuesFromPick( TidyOption topt ) { - TidyIterator pos = tidyOptGetPickList( topt ); - Bool first = yes; - ctmbstr def; - while ( pos ) - { - if (first) - first = no; - else - printf(", "); - def = tidyOptGetNextPick( topt, &pos ); - printf("%s", def); - } + TidyIterator pos = tidyOptGetPickList( topt ); + Bool first = yes; + ctmbstr def; + while ( pos ) + { + if (first) + first = no; + else + printf(", "); + def = tidyOptGetNextPick( topt, &pos ); + printf("%s", def); + } } /** @@ -784,10 +783,10 @@ static void PrintAllowedValuesFromPick( TidyOption topt ) **/ static void PrintAllowedValues( TidyOption topt, const OptionDesc *d ) { - if (d->vals) - printf( "%s", d->vals ); - else - PrintAllowedValuesFromPick( topt ); + if (d->vals) + printf( "%s", d->vals ); + else + PrintAllowedValuesFromPick( topt ); } /** @@ -795,18 +794,18 @@ static void PrintAllowedValues( TidyOption topt, const OptionDesc *d ) **/ static void printXMLDescription( TidyDoc tdoc, TidyOption topt ) { - ctmbstr doc = tidyOptGetDoc( tdoc, topt ); - - if (doc) - printf(" %s\n", doc); - else - { - printf(" \n"); - fprintf(stderr, tidyLocalizedString(TC_STRING_OPT_NOT_DOCUMENTED), - tidyOptGetName( topt )); + ctmbstr doc = tidyOptGetDoc( tdoc, topt ); + + if (doc) + printf(" %s\n", doc); + else + { + printf(" \n"); + fprintf(stderr, tidyLocalizedString(TC_STRING_OPT_NOT_DOCUMENTED), + tidyOptGetName( topt )); fprintf(stderr, "\n"); - } + } } /** @@ -814,13 +813,13 @@ static void printXMLDescription( TidyDoc tdoc, TidyOption topt ) **/ static void printXMLCrossRef( TidyDoc tdoc, TidyOption topt ) { - TidyOption optLinked; - TidyIterator pos = tidyOptGetDocLinksList(tdoc, topt); - while( pos ) - { - optLinked = tidyOptGetNextDocLinks(tdoc, &pos ); - printf(" %s\n",tidyOptGetName(optLinked)); - } + TidyOption optLinked; + TidyIterator pos = tidyOptGetDocLinksList(tdoc, topt); + while( pos ) + { + optLinked = tidyOptGetNextDocLinks(tdoc, &pos ); + printf(" %s\n",tidyOptGetName(optLinked)); + } } @@ -829,29 +828,29 @@ static void printXMLCrossRef( TidyDoc tdoc, TidyOption topt ) **/ static void printXMLOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) { - if ( tidyOptIsReadOnly(topt) ) - return; - - printf( " \n" ); + if ( tidyOptIsReadOnly(topt) ) + return; + + printf( " \n" ); } @@ -860,10 +859,10 @@ static void printXMLOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) **/ static void XMLoptionhelp( TidyDoc tdoc ) { - printf( "\n" - "\n", tidyLibraryVersion()); - ForEachOption( tdoc, printXMLOption ); - printf( "\n" ); + printf( "\n" + "\n", tidyLibraryVersion()); + ForEachOption( tdoc, printXMLOption ); + printf( "\n" ); } /** @@ -874,7 +873,7 @@ void tidyPrintWindowsLanguageNames( ctmbstr format ) { const tidyLocaleMapItem *item; TidyIterator i = getWindowsLanguageList(); - + while (i) { item = getNextWindowsLanguage(&i); if ( format ) @@ -893,7 +892,7 @@ void tidyPrintTidyLanguageNames( ctmbstr format ) { ctmbstr item; TidyIterator i = getInstalledLanguageList(); - + while (i) { item = getNextInstalledLanguage(&i); if ( format ) @@ -909,38 +908,38 @@ void tidyPrintTidyLanguageNames( ctmbstr format ) */ static tmbstr GetAllowedValuesFromPick( TidyOption topt ) { - TidyIterator pos; - Bool first; - ctmbstr def; - uint len = 0; - tmbstr val; - - pos = tidyOptGetPickList( topt ); - first = yes; - while ( pos ) - { - if (first) - first = no; - else - len += 2; - def = tidyOptGetNextPick( topt, &pos ); - len += strlen(def); - } - val = (tmbstr)malloc(len+1); - if (!val) outOfMemory(); - val[0] = '\0'; - pos = tidyOptGetPickList( topt ); - first = yes; - while ( pos ) - { - if (first) - first = no; - else - strcat(val, ", "); - def = tidyOptGetNextPick( topt, &pos ); - strcat(val, def); - } - return val; + TidyIterator pos; + Bool first; + ctmbstr def; + uint len = 0; + tmbstr val; + + pos = tidyOptGetPickList( topt ); + first = yes; + while ( pos ) + { + if (first) + first = no; + else + len += 2; + def = tidyOptGetNextPick( topt, &pos ); + len += strlen(def); + } + val = (tmbstr)malloc(len+1); + if (!val) outOfMemory(); + val[0] = '\0'; + pos = tidyOptGetPickList( topt ); + first = yes; + while ( pos ) + { + if (first) + first = no; + else + strcat(val, ", "); + def = tidyOptGetNextPick( topt, &pos ); + strcat(val, def); + } + return val; } /** @@ -948,43 +947,43 @@ static tmbstr GetAllowedValuesFromPick( TidyOption topt ) */ static tmbstr GetAllowedValues( TidyOption topt, const OptionDesc *d ) { - if (d->vals) - { - tmbstr val = (tmbstr)malloc(1+strlen(d->vals)); - if (!val) outOfMemory(); - strcpy(val, d->vals); - return val; - } - else - return GetAllowedValuesFromPick( topt ); + if (d->vals) + { + tmbstr val = (tmbstr)malloc(1+strlen(d->vals)); + if (!val) outOfMemory(); + strcpy(val, d->vals); + return val; + } + else + return GetAllowedValuesFromPick( topt ); } /** ** Prints a single option. */ static void printOption( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, - OptionDesc *d ) + OptionDesc *d ) { - if ( tidyOptIsReadOnly(topt) ) - return; - - if ( *d->name || *d->type ) - { - ctmbstr pval = d->vals; - tmbstr val = NULL; - if (!d->haveVals) - { - pval = "-"; - } - else if (pval == NULL) - { - val = GetAllowedValues( topt, d); - pval = val; - } - print3Columns( fmt, 27, 9, 40, d->name, d->type, pval ); - if (val) - free(val); - } + if ( tidyOptIsReadOnly(topt) ) + return; + + if ( *d->name || *d->type ) + { + ctmbstr pval = d->vals; + tmbstr val = NULL; + if (!d->haveVals) + { + pval = "-"; + } + else if (pval == NULL) + { + val = GetAllowedValues( topt, d); + pval = val; + } + print3Columns( fmt, 27, 9, 40, d->name, d->type, pval ); + if (val) + free(val); + } } /** @@ -992,16 +991,16 @@ static void printOption( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, */ static void optionhelp( TidyDoc tdoc ) { - printf( "%s", tidyLocalizedString( TC_TXT_HELP_CONFIG ) ); - - printf( fmt, - tidyLocalizedString( TC_TXT_HELP_CONFIG_NAME ), - tidyLocalizedString( TC_TXT_HELP_CONFIG_TYPE ), - tidyLocalizedString( TC_TXT_HELP_CONFIG_ALLW ) ); - - printf( fmt, ul, ul, ul ); - - ForEachSortedOption( tdoc, printOption ); + printf( "%s", tidyLocalizedString( TC_TXT_HELP_CONFIG ) ); + + printf( fmt, + tidyLocalizedString( TC_TXT_HELP_CONFIG_NAME ), + tidyLocalizedString( TC_TXT_HELP_CONFIG_TYPE ), + tidyLocalizedString( TC_TXT_HELP_CONFIG_ALLW ) ); + + printf( fmt, ul, ul, ul ); + + ForEachSortedOption( tdoc, printOption ); } @@ -1012,257 +1011,257 @@ static void optionhelp( TidyDoc tdoc ) */ static tmbstr cleanup_description( ctmbstr description ) { - /* Substitutions - this might be a good spot to introduce platform - dependent definitions for colorized output on different terminals - that support, for example, ANSI escape sequences. The assumption - is made the Mac and Linux targets support ANSI colors, but even - so debugger terminals may not. Note that the line-wrapping - function also doesn't account for non-printing characters. */ - static struct { - ctmbstr tag; - ctmbstr replacement; - } const replacements[] = { - { "lt", "<" }, - { "gt", ">" }, - { "br/", "\n\n" }, + /* Substitutions - this might be a good spot to introduce platform + dependent definitions for colorized output on different terminals + that support, for example, ANSI escape sequences. The assumption + is made the Mac and Linux targets support ANSI colors, but even + so debugger terminals may not. Note that the line-wrapping + function also doesn't account for non-printing characters. */ + static struct { + ctmbstr tag; + ctmbstr replacement; + } const replacements[] = { + { "lt", "<" }, + { "gt", ">" }, + { "br/", "\n\n" }, #if defined(LINUX_OS) || defined(MAC_OS_X) - { "code", "\x1b[36m" }, - { "/code", "\x1b[0m" }, - { "em", "\x1b[4m" }, - { "/em", "\x1b[0m" }, - { "strong", "\x1b[31m" }, - { "/strong", "\x1b[0m" }, + { "code", "\x1b[36m" }, + { "/code", "\x1b[0m" }, + { "em", "\x1b[4m" }, + { "/em", "\x1b[0m" }, + { "strong", "\x1b[31m" }, + { "/strong", "\x1b[0m" }, #endif - /* MUST be last */ - { NULL, NULL }, - }; + /* MUST be last */ + { NULL, NULL }, + }; - /* State Machine Setup */ - typedef enum { - s_DONE, - s_DATA, - s_WRITING, - s_TAG_OPEN, - s_TAG_NAME, - s_ERROR, - s_LAST /* MUST be last */ - } states; + /* State Machine Setup */ + typedef enum { + s_DONE, + s_DATA, + s_WRITING, + s_TAG_OPEN, + s_TAG_NAME, + s_ERROR, + s_LAST /* MUST be last */ + } states; - typedef enum { - c_NIL, - c_EOF, - c_BRACKET_CLOSE, - c_BRACKET_OPEN, - c_OTHER - } charstates; + typedef enum { + c_NIL, + c_EOF, + c_BRACKET_CLOSE, + c_BRACKET_OPEN, + c_OTHER + } charstates; - typedef enum { - a_NIL, - a_BUILD_NAME, - a_CONSUME, - a_EMIT, - a_EMIT_SUBS, - a_WRITE, - a_ERROR - } actions; + typedef enum { + a_NIL, + a_BUILD_NAME, + a_CONSUME, + a_EMIT, + a_EMIT_SUBS, + a_WRITE, + a_ERROR + } actions; - typedef struct { - states state; - charstates charstate; - actions action; - states next_state; - } transitionType; + typedef struct { + states state; + charstates charstate; + actions action; + states next_state; + } transitionType; - const transitionType transitions[] = { - { s_DATA, c_EOF, a_NIL, s_DONE }, - { s_DATA, c_BRACKET_OPEN, a_CONSUME, s_TAG_OPEN }, - /* special case allows ; */ - { s_DATA, c_BRACKET_CLOSE, a_EMIT, s_WRITING }, - { s_DATA, c_OTHER, a_EMIT, s_WRITING }, - { s_WRITING, c_OTHER, a_WRITE, s_DATA }, - { s_WRITING, c_BRACKET_CLOSE, a_WRITE, s_DATA }, - { s_TAG_OPEN, c_EOF, a_ERROR, s_DONE }, - { s_TAG_OPEN, c_OTHER, a_NIL, s_TAG_NAME }, - { s_TAG_NAME, c_BRACKET_OPEN, a_ERROR, s_DONE }, - { s_TAG_NAME, c_EOF, a_ERROR, s_DONE }, - { s_TAG_NAME, c_BRACKET_CLOSE, a_EMIT_SUBS, s_WRITING }, - { s_TAG_NAME, c_OTHER, a_BUILD_NAME, s_TAG_NAME }, - { s_ERROR, 0, a_ERROR, s_DONE }, - { s_DONE, 0, a_NIL, 0 }, - /* MUST be last: */ - { s_LAST, 0, 0, 0 }, - }; + const transitionType transitions[] = { + { s_DATA, c_EOF, a_NIL, s_DONE }, + { s_DATA, c_BRACKET_OPEN, a_CONSUME, s_TAG_OPEN }, + /* special case allows ; */ + { s_DATA, c_BRACKET_CLOSE, a_EMIT, s_WRITING }, + { s_DATA, c_OTHER, a_EMIT, s_WRITING }, + { s_WRITING, c_OTHER, a_WRITE, s_DATA }, + { s_WRITING, c_BRACKET_CLOSE, a_WRITE, s_DATA }, + { s_TAG_OPEN, c_EOF, a_ERROR, s_DONE }, + { s_TAG_OPEN, c_OTHER, a_NIL, s_TAG_NAME }, + { s_TAG_NAME, c_BRACKET_OPEN, a_ERROR, s_DONE }, + { s_TAG_NAME, c_EOF, a_ERROR, s_DONE }, + { s_TAG_NAME, c_BRACKET_CLOSE, a_EMIT_SUBS, s_WRITING }, + { s_TAG_NAME, c_OTHER, a_BUILD_NAME, s_TAG_NAME }, + { s_ERROR, 0, a_ERROR, s_DONE }, + { s_DONE, 0, a_NIL, 0 }, + /* MUST be last: */ + { s_LAST, 0, 0, 0 }, + }; - /* Output Setup */ - tmbstr result = NULL; - int g_result = 100; // minimum buffer grow size - int l_result = 0; // buffer current size - int i_result = 0; // current string position - int writer_len = 0; // writer length + /* Output Setup */ + tmbstr result = NULL; + int g_result = 100; // minimum buffer grow size + int l_result = 0; // buffer current size + int i_result = 0; // current string position + int writer_len = 0; // writer length - ctmbstr writer = NULL; + ctmbstr writer = NULL; - /* Current tag name setup */ - tmbstr name = NULL; // tag name - int g_name = 10; // buffer grow size - int l_name = 0; // buffer current size - int i_name = 0; // current string position + /* Current tag name setup */ + tmbstr name = NULL; // tag name + int g_name = 10; // buffer grow size + int l_name = 0; // buffer current size + int i_name = 0; // current string position - /* Pump Setup */ - int i = 0; - states state = s_DATA; - charstates charstate; - char c; - int j = 0, k = 0; - transitionType transition; + /* Pump Setup */ + int i = 0; + states state = s_DATA; + charstates charstate; + char c; + int j = 0, k = 0; + transitionType transition; - if ( !description || (strlen(description) < 1) ) - { - return NULL; - } - - /* Process the HTML Snippet */ - do { - c = description[i]; + if ( !description || (strlen(description) < 1) ) + { + return NULL; + } - /* Determine secondary state. */ - switch (c) - { - case '\0': - charstate = c_EOF; - break; + /* Process the HTML Snippet */ + do { + c = description[i]; - case '<': - case '&': - charstate = c_BRACKET_OPEN; - break; + /* Determine secondary state. */ + switch (c) + { + case '\0': + charstate = c_EOF; + break; - case '>': - case ';': - charstate = c_BRACKET_CLOSE; - break; + case '<': + case '&': + charstate = c_BRACKET_OPEN; + break; - default: - charstate = c_OTHER; - break; - } + case '>': + case ';': + charstate = c_BRACKET_CLOSE; + break; - /* Find the correct instruction */ - j = 0; - while (transitions[j].state != s_LAST) - { - transition = transitions[j]; - if ( transition.state == state && transition.charstate == charstate ) { - switch ( transition.action ) - { - /* This action is building the name of an HTML tag. */ - case a_BUILD_NAME: - if ( !name ) - { - l_name = g_name; - name = calloc(l_name, 1); - } + default: + charstate = c_OTHER; + break; + } - if ( i_name >= l_name ) - { - l_name = l_name + g_name; - name = realloc(name, l_name); - } + /* Find the correct instruction */ + j = 0; + while (transitions[j].state != s_LAST) + { + transition = transitions[j]; + if ( transition.state == state && transition.charstate == charstate ) { + switch ( transition.action ) + { + /* This action is building the name of an HTML tag. */ + case a_BUILD_NAME: + if ( !name ) + { + l_name = g_name; + name = calloc(l_name, 1); + } - strncpy(name + i_name, &c, 1); - i_name++; - i++; - break; + if ( i_name >= l_name ) + { + l_name = l_name + g_name; + name = realloc(name, l_name); + } - /* This character will be emitted into the output - stream. The only purpose of this action is to - ensure that `writer` is NULL as a flag that we - will output the current `c` */ - case a_EMIT: - writer = NULL; // flag to use c - break; + strncpy(name + i_name, &c, 1); + i_name++; + i++; + break; - /* Now that we've consumed a tag, we will emit the - substitution if any has been specified in - `replacements`. */ - case a_EMIT_SUBS: - name[i_name] = '\0'; - i_name = 0; - k = 0; - writer = ""; - while ( replacements[k].tag ) - { - if ( strcmp( replacements[k].tag, name ) == 0 ) - { - writer = replacements[k].replacement; - } - k++; - } - break; + /* This character will be emitted into the output + stream. The only purpose of this action is to + ensure that `writer` is NULL as a flag that we + will output the current `c` */ + case a_EMIT: + writer = NULL; // flag to use c + break; - /* This action will add to our `result` string, expanding - the buffer as necessary in reasonable chunks. */ - case a_WRITE: - if ( !writer ) - writer_len = 1; - else - writer_len = strlen( writer ); - /* Lazy buffer creation */ - if ( !result ) - { - l_result = writer_len + g_result; - result = calloc(l_result, 1); - } - /* Grow the buffer if needed */ - if ( i_result + writer_len >= l_result ) - { - l_result = l_result + writer_len + g_result; - result = realloc(result, l_result); - } - /* Add current writer to the buffer */ - if ( !writer ) - { - result[i_result] = c; - result[i_result +1] = '\0'; - } - else - { - strncpy( result + i_result, writer, writer_len ); - } + /* Now that we've consumed a tag, we will emit the + substitution if any has been specified in + `replacements`. */ + case a_EMIT_SUBS: + name[i_name] = '\0'; + i_name = 0; + k = 0; + writer = ""; + while ( replacements[k].tag ) + { + if ( strcmp( replacements[k].tag, name ) == 0 ) + { + writer = replacements[k].replacement; + } + k++; + } + break; - i_result += writer_len; - i++; - break; + /* This action will add to our `result` string, expanding + the buffer as necessary in reasonable chunks. */ + case a_WRITE: + if ( !writer ) + writer_len = 1; + else + writer_len = strlen( writer ); + /* Lazy buffer creation */ + if ( !result ) + { + l_result = writer_len + g_result; + result = calloc(l_result, 1); + } + /* Grow the buffer if needed */ + if ( i_result + writer_len >= l_result ) + { + l_result = l_result + writer_len + g_result; + result = realloc(result, l_result); + } + /* Add current writer to the buffer */ + if ( !writer ) + { + result[i_result] = c; + result[i_result +1] = '\0'; + } + else + { + strncpy( result + i_result, writer, writer_len ); + } - /* This action could be more robust but it serves the - current purpose. Cross our fingers and count on our - localizers not to give bad HTML descriptions. */ - case a_ERROR: - printf(" The localized string probably has bad HTML.\n"); - goto EXIT_CLEANLY; + i_result += writer_len; + i++; + break; - /* Just a NOP. */ - case a_NIL: - break; + /* This action could be more robust but it serves the + current purpose. Cross our fingers and count on our + localizers not to give bad HTML descriptions. */ + case a_ERROR: + printf(" The localized string probably has bad HTML.\n"); + goto EXIT_CLEANLY; - /* The default case also handles the CONSUME action. */ - default: - i++; - break; - } + /* Just a NOP. */ + case a_NIL: + break; - state = transition.next_state; - break; - } - j++; - } - } while ( description[i] ); + /* The default case also handles the CONSUME action. */ + default: + i++; + break; + } + + state = transition.next_state; + break; + } + j++; + } + } while ( description[i] ); EXIT_CLEANLY: - if ( name ) - free(name); - return result; + if ( name ) + free(name); + return result; } @@ -1271,26 +1270,26 @@ EXIT_CLEANLY: */ static void optionDescribe( TidyDoc tdoc, char *tag ) { - tmbstr result = NULL; - TidyOptionId topt; + tmbstr result = NULL; + TidyOptionId topt; - topt = tidyOptGetIdForName( tag ); + topt = tidyOptGetIdForName( tag ); - if (topt < N_TIDY_OPTIONS) - { - result = cleanup_description( tidyOptGetDoc( tdoc, tidyGetOption( tdoc, topt ) ) ); - } - else - { - result = (tmbstr)tidyLocalizedString(TC_STRING_UNKNOWN_OPTION_B); - } + if (topt < N_TIDY_OPTIONS) + { + result = cleanup_description( tidyOptGetDoc( tdoc, tidyGetOption( tdoc, topt ) ) ); + } + else + { + result = (tmbstr)tidyLocalizedString(TC_STRING_UNKNOWN_OPTION_B); + } - printf( "\n" ); - printf( "`--%s`\n\n", tag ); - print1Column( "%-68.68s\n", 68, result ); - printf( "\n" ); - if ( (topt < N_TIDY_OPTIONS) && ( result ) ) - free ( result ); + printf( "\n" ); + printf( "`--%s`\n\n", tag ); + print1Column( "%-68.68s\n", 68, result ); + printf( "\n" ); + if ( (topt < N_TIDY_OPTIONS) && ( result ) ) + free ( result ); } @@ -1298,51 +1297,51 @@ static void optionDescribe( TidyDoc tdoc, char *tag ) * Prints the option value for a given option. */ static void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, - OptionDesc *d ) + OptionDesc *d ) { - TidyOptionId optId = tidyOptGetId( topt ); - ctmbstr ro = tidyOptIsReadOnly( topt ) ? "*" : "" ; - - switch ( optId ) - { - case TidyInlineTags: - case TidyBlockTags: - case TidyEmptyTags: - case TidyPreTags: - { - TidyIterator pos = tidyOptGetDeclTagList( tdoc ); - while ( pos ) - { - d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos); - if ( pos ) - { - if ( *d->name ) - printf( valfmt, d->name, d->type, ro, d->def ); - else - printf( fmt, d->name, d->type, d->def ); - d->name = ""; - d->type = ""; - } - } - } - break; - case TidyNewline: - d->def = tidyOptGetCurrPick( tdoc, optId ); - break; - default: - break; - } - - /* fix for http://tidy.sf.net/bug/873921 */ - if ( *d->name || *d->type || (d->def && *d->def) ) - { - if ( ! d->def ) - d->def = ""; - if ( *d->name ) - printf( valfmt, d->name, d->type, ro, d->def ); - else - printf( fmt, d->name, d->type, d->def ); - } + TidyOptionId optId = tidyOptGetId( topt ); + ctmbstr ro = tidyOptIsReadOnly( topt ) ? "*" : "" ; + + switch ( optId ) + { + case TidyInlineTags: + case TidyBlockTags: + case TidyEmptyTags: + case TidyPreTags: + { + TidyIterator pos = tidyOptGetDeclTagList( tdoc ); + while ( pos ) + { + d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos); + if ( pos ) + { + if ( *d->name ) + printf( valfmt, d->name, d->type, ro, d->def ); + else + printf( fmt, d->name, d->type, d->def ); + d->name = ""; + d->type = ""; + } + } + } + break; + case TidyNewline: + d->def = tidyOptGetCurrPick( tdoc, optId ); + break; + default: + break; + } + + /* fix for http://tidy.sf.net/bug/873921 */ + if ( *d->name || *d->type || (d->def && *d->def) ) + { + if ( ! d->def ) + d->def = ""; + if ( *d->name ) + printf( valfmt, d->name, d->type, ro, d->def ); + else + printf( fmt, d->name, d->type, d->def ); + } } /** @@ -1350,15 +1349,15 @@ static void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, */ static void optionvalues( TidyDoc tdoc ) { - printf( "\n%s\n\n", tidyLocalizedString(TC_STRING_CONF_HEADER) ); - printf( fmt, tidyLocalizedString(TC_STRING_CONF_NAME), - tidyLocalizedString(TC_STRING_CONF_TYPE), - tidyLocalizedString(TC_STRING_CONF_VALUE) ); - printf( fmt, ul, ul, ul ); - - ForEachSortedOption( tdoc, printOptionValues ); - - printf( "\n\n%s\n\n", tidyLocalizedString(TC_STRING_CONF_NOTE) ); + printf( "\n%s\n\n", tidyLocalizedString(TC_STRING_CONF_HEADER) ); + printf( fmt, tidyLocalizedString(TC_STRING_CONF_NAME), + tidyLocalizedString(TC_STRING_CONF_TYPE), + tidyLocalizedString(TC_STRING_CONF_VALUE) ); + printf( fmt, ul, ul, ul ); + + ForEachSortedOption( tdoc, printOptionValues ); + + printf( "\n\n%s\n\n", tidyLocalizedString(TC_STRING_CONF_NOTE) ); } /** @@ -1367,9 +1366,9 @@ static void optionvalues( TidyDoc tdoc ) static void version( void ) { #ifdef PLATFORM_NAME - printf( tidyLocalizedString( TC_STRING_VERS_A ), PLATFORM_NAME, tidyLibraryVersion() ); + printf( tidyLocalizedString( TC_STRING_VERS_A ), PLATFORM_NAME, tidyLibraryVersion() ); #else - printf( tidyLocalizedString( TC_STRING_VERS_B ), tidyLibraryVersion() ); + printf( tidyLocalizedString( TC_STRING_VERS_B ), tidyLibraryVersion() ); #endif printf("\n"); } @@ -1381,18 +1380,18 @@ static void version( void ) **/ static void printXMLOptionString( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) { - tmbstr description; - - if ( tidyOptIsReadOnly(topt) ) - return; + tmbstr description; - description = cleanup_description( tidyOptGetDoc( tdoc, topt ) ); - - printf( " \n" ); - free( description ); + if ( tidyOptIsReadOnly(topt) ) + return; + + description = cleanup_description( tidyOptGetDoc( tdoc, topt ) ); + + printf( " \n" ); + free( description ); } /** @@ -1403,10 +1402,10 @@ static void printXMLOptionString( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) **/ static void xml_options_strings( TidyDoc tdoc ) { - printf( "\n" - "\n", tidyLibraryVersion()); - ForEachOption( tdoc, printXMLOptionString); - printf( "\n" ); + printf( "\n" + "\n", tidyLibraryVersion()); + ForEachOption( tdoc, printXMLOptionString); + printf( "\n" ); } @@ -1419,31 +1418,31 @@ static void xml_strings( void ) { uint i; TidyIterator j; - - ctmbstr current_language = tidyGetLanguage(); - Bool skip_current = strcmp( current_language, "en" ) == 0; - Bool matches_base; - - printf( "\n" - "\n", tidyLibraryVersion()); - j = getStringKeyList(); + ctmbstr current_language = tidyGetLanguage(); + Bool skip_current = strcmp( current_language, "en" ) == 0; + Bool matches_base; + + printf( "\n" + "\n", tidyLibraryVersion()); + + j = getStringKeyList(); while (j) { i = getNextStringKey(&j); - printf( "\n", i ); - printf( " ", "en" ); - printf("%s", tidyDefaultString(i)); - printf( "\n" ); - if ( !skip_current ) { - matches_base = strcmp( tidyLocalizedString(i), tidyDefaultString(i) ) == 0; - printf( " ", tidyGetLanguage(), matches_base ? "yes" : "no" ); - printf("%s", tidyLocalizedString(i)); - printf( "\n" ); - } - printf( "\n"); - } - - printf( "\n" ); + printf( "\n", i ); + printf( " ", "en" ); + printf("%s", tidyDefaultString(i)); + printf( "\n" ); + if ( !skip_current ) { + matches_base = strcmp( tidyLocalizedString(i), tidyDefaultString(i) ) == 0; + printf( " ", tidyGetLanguage(), matches_base ? "yes" : "no" ); + printf("%s", tidyLocalizedString(i)); + printf( "\n" ); + } + printf( "\n"); + } + + printf( "\n" ); } @@ -1452,11 +1451,11 @@ static void xml_strings( void ) */ static void lang_help( void ) { - printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_1) ); - tidyPrintWindowsLanguageNames(" %-20s -> %s\n"); - printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_2) ); - tidyPrintTidyLanguageNames(" %s\n"); - printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_3) ); + printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_1) ); + tidyPrintWindowsLanguageNames(" %-20s -> %s\n"); + printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_2) ); + tidyPrintTidyLanguageNames(" %s\n"); + printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_3) ); } @@ -1465,7 +1464,7 @@ static void lang_help( void ) */ static void unknownOption( uint c ) { - fprintf( errout, tidyLocalizedString( TC_STRING_UNKNOWN_OPTION ), (char)c ); + fprintf( errout, tidyLocalizedString( TC_STRING_UNKNOWN_OPTION ), (char)c ); fprintf( errout, "\n"); } @@ -1474,7 +1473,7 @@ static void unknownOption( uint c ) */ void progressTester( TidyDoc tdoc, uint srcLine, uint srcCol, uint dstLine) { - fprintf(stderr, "srcLine = %u, srcCol = %u, dstLine = %u\n", srcLine, srcCol, dstLine); + fprintf(stderr, "srcLine = %u, srcCol = %u, dstLine = %u\n", srcLine, srcCol, dstLine); } @@ -1483,499 +1482,499 @@ void progressTester( TidyDoc tdoc, uint srcLine, uint srcCol, uint dstLine) */ int main( int argc, char** argv ) { - ctmbstr prog = argv[0]; - ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL; - TidyDoc tdoc = tidyCreate(); - int status = 0; - tmbstr locale = NULL; - - uint contentErrors = 0; - uint contentWarnings = 0; - uint accessWarnings = 0; - - errout = stderr; /* initialize to stderr */ + ctmbstr prog = argv[0]; + ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL; + TidyDoc tdoc = tidyCreate(); + int status = 0; + tmbstr locale = NULL; + + uint contentErrors = 0; + uint contentWarnings = 0; + uint accessWarnings = 0; + + errout = stderr; /* initialize to stderr */ + + /* Set the locale for tidy's output. */ + locale = tidySystemLocale(locale); + tidySetLanguage(locale); + if ( locale ) + free( locale ); - /* Set the locale for tidy's output. */ - locale = tidySystemLocale(locale); - tidySetLanguage(locale); - if ( locale ) - free( locale ); - #if !defined(NDEBUG) && defined(_MSC_VER) - set_log_file((char *)"temptidy.txt", 0); - // add_append_log(1); + set_log_file((char *)"temptidy.txt", 0); + // add_append_log(1); #endif - /* - * Look for default configuration files using any of - * the following possibilities: - * - TIDY_CONFIG_FILE - from tidyplatform.h, typically /etc/tidy.conf - * - HTML_TIDY - environment variable - * - TIDY_USER_CONFIG_FILE - from tidyplatform.h, typically ~/tidy.conf - */ + /* + * Look for default configuration files using any of + * the following possibilities: + * - TIDY_CONFIG_FILE - from tidyplatform.h, typically /etc/tidy.conf + * - HTML_TIDY - environment variable + * - TIDY_USER_CONFIG_FILE - from tidyplatform.h, typically ~/tidy.conf + */ #ifdef TIDY_CONFIG_FILE - if ( tidyFileExists( tdoc, TIDY_CONFIG_FILE) ) - { - status = tidyLoadConfig( tdoc, TIDY_CONFIG_FILE ); - if ( status != 0 ) { - fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status); - fprintf(errout, "\n"); - } - } + if ( tidyFileExists( tdoc, TIDY_CONFIG_FILE) ) + { + status = tidyLoadConfig( tdoc, TIDY_CONFIG_FILE ); + if ( status != 0 ) { + fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status); + fprintf(errout, "\n"); + } + } #endif /* TIDY_CONFIG_FILE */ - - if ( (cfgfil = getenv("HTML_TIDY")) != NULL ) - { - status = tidyLoadConfig( tdoc, cfgfil ); - if ( status != 0 ) { - fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status); - fprintf(errout, "\n"); - } - } + + if ( (cfgfil = getenv("HTML_TIDY")) != NULL ) + { + status = tidyLoadConfig( tdoc, cfgfil ); + if ( status != 0 ) { + fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status); + fprintf(errout, "\n"); + } + } #ifdef TIDY_USER_CONFIG_FILE - else if ( tidyFileExists( tdoc, TIDY_USER_CONFIG_FILE) ) - { - status = tidyLoadConfig( tdoc, TIDY_USER_CONFIG_FILE ); - if ( status != 0 ) { - fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status); - fprintf(errout, "\n"); - } - } + else if ( tidyFileExists( tdoc, TIDY_USER_CONFIG_FILE) ) + { + status = tidyLoadConfig( tdoc, TIDY_USER_CONFIG_FILE ); + if ( status != 0 ) { + fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status); + fprintf(errout, "\n"); + } + } #endif /* TIDY_USER_CONFIG_FILE */ - /* - * Read command line - */ + /* + * Read command line + */ - while ( argc > 0 ) - { - if (argc > 1 && argv[1][0] == '-') - { - /* support -foo and --foo */ - ctmbstr arg = argv[1] + 1; - - if ( strcasecmp(arg, "xml") == 0) - tidyOptSetBool( tdoc, TidyXmlTags, yes ); - - else if ( strcasecmp(arg, "asxml") == 0 || - strcasecmp(arg, "asxhtml") == 0 ) - { - tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); - } - else if ( strcasecmp(arg, "ashtml") == 0 ) - tidyOptSetBool( tdoc, TidyHtmlOut, yes ); - - else if ( strcasecmp(arg, "indent") == 0 ) - { - tidyOptSetInt( tdoc, TidyIndentContent, TidyAutoState ); - if ( tidyOptGetInt(tdoc, TidyIndentSpaces) == 0 ) - tidyOptResetToDefault( tdoc, TidyIndentSpaces ); - } - else if ( strcasecmp(arg, "omit") == 0 ) - tidyOptSetBool( tdoc, TidyOmitOptionalTags, yes ); - - else if ( strcasecmp(arg, "upper") == 0 ) - tidyOptSetBool( tdoc, TidyUpperCaseTags, yes ); - - else if ( strcasecmp(arg, "clean") == 0 ) - tidyOptSetBool( tdoc, TidyMakeClean, yes ); - - else if ( strcasecmp(arg, "gdoc") == 0 ) - tidyOptSetBool( tdoc, TidyGDocClean, yes ); - - else if ( strcasecmp(arg, "bare") == 0 ) - tidyOptSetBool( tdoc, TidyMakeBare, yes ); - - else if ( strcasecmp(arg, "raw") == 0 || - strcasecmp(arg, "ascii") == 0 || - strcasecmp(arg, "latin0") == 0 || - strcasecmp(arg, "latin1") == 0 || - strcasecmp(arg, "utf8") == 0 || + while ( argc > 0 ) + { + if (argc > 1 && argv[1][0] == '-') + { + /* support -foo and --foo */ + ctmbstr arg = argv[1] + 1; + + if ( strcasecmp(arg, "xml") == 0) + tidyOptSetBool( tdoc, TidyXmlTags, yes ); + + else if ( strcasecmp(arg, "asxml") == 0 || + strcasecmp(arg, "asxhtml") == 0 ) + { + tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); + } + else if ( strcasecmp(arg, "ashtml") == 0 ) + tidyOptSetBool( tdoc, TidyHtmlOut, yes ); + + else if ( strcasecmp(arg, "indent") == 0 ) + { + tidyOptSetInt( tdoc, TidyIndentContent, TidyAutoState ); + if ( tidyOptGetInt(tdoc, TidyIndentSpaces) == 0 ) + tidyOptResetToDefault( tdoc, TidyIndentSpaces ); + } + else if ( strcasecmp(arg, "omit") == 0 ) + tidyOptSetBool( tdoc, TidyOmitOptionalTags, yes ); + + else if ( strcasecmp(arg, "upper") == 0 ) + tidyOptSetBool( tdoc, TidyUpperCaseTags, yes ); + + else if ( strcasecmp(arg, "clean") == 0 ) + tidyOptSetBool( tdoc, TidyMakeClean, yes ); + + else if ( strcasecmp(arg, "gdoc") == 0 ) + tidyOptSetBool( tdoc, TidyGDocClean, yes ); + + else if ( strcasecmp(arg, "bare") == 0 ) + tidyOptSetBool( tdoc, TidyMakeBare, yes ); + + else if ( strcasecmp(arg, "raw") == 0 || + strcasecmp(arg, "ascii") == 0 || + strcasecmp(arg, "latin0") == 0 || + strcasecmp(arg, "latin1") == 0 || + strcasecmp(arg, "utf8") == 0 || #ifndef NO_NATIVE_ISO2022_SUPPORT - strcasecmp(arg, "iso2022") == 0 || + strcasecmp(arg, "iso2022") == 0 || #endif #if SUPPORT_UTF16_ENCODINGS - strcasecmp(arg, "utf16le") == 0 || - strcasecmp(arg, "utf16be") == 0 || - strcasecmp(arg, "utf16") == 0 || + strcasecmp(arg, "utf16le") == 0 || + strcasecmp(arg, "utf16be") == 0 || + strcasecmp(arg, "utf16") == 0 || #endif #if SUPPORT_ASIAN_ENCODINGS - strcasecmp(arg, "shiftjis") == 0 || - strcasecmp(arg, "big5") == 0 || + strcasecmp(arg, "shiftjis") == 0 || + strcasecmp(arg, "big5") == 0 || #endif - strcasecmp(arg, "mac") == 0 || - strcasecmp(arg, "win1252") == 0 || - strcasecmp(arg, "ibm858") == 0 ) - { - tidySetCharEncoding( tdoc, arg ); - } - else if ( strcasecmp(arg, "numeric") == 0 ) - tidyOptSetBool( tdoc, TidyNumEntities, yes ); - - else if ( strcasecmp(arg, "modify") == 0 || - strcasecmp(arg, "change") == 0 || /* obsolete */ - strcasecmp(arg, "update") == 0 ) /* obsolete */ - { - tidyOptSetBool( tdoc, TidyWriteBack, yes ); - } - else if ( strcasecmp(arg, "errors") == 0 ) - tidyOptSetBool( tdoc, TidyShowMarkup, no ); - - else if ( strcasecmp(arg, "quiet") == 0 ) - tidyOptSetBool( tdoc, TidyQuiet, yes ); - - /* Currenly user must specify a language - prior to anything that causes output */ - else if ( strcasecmp(arg, "language") == 0 || - strcasecmp(arg, "lang") == 0 ) - if ( argc >= 3) - { - if ( strcasecmp(argv[2], "help") == 0 ) - { - lang_help(); - exit(0); - } - if ( !tidySetLanguage( argv[2] ) ) - { - printf(tidyLocalizedString(TC_STRING_LANG_NOT_FOUND), - argv[2], tidyGetLanguage()); - printf("\n"); - } else { + strcasecmp(arg, "mac") == 0 || + strcasecmp(arg, "win1252") == 0 || + strcasecmp(arg, "ibm858") == 0 ) + { + tidySetCharEncoding( tdoc, arg ); + } + else if ( strcasecmp(arg, "numeric") == 0 ) + tidyOptSetBool( tdoc, TidyNumEntities, yes ); + + else if ( strcasecmp(arg, "modify") == 0 || + strcasecmp(arg, "change") == 0 || /* obsolete */ + strcasecmp(arg, "update") == 0 ) /* obsolete */ + { + tidyOptSetBool( tdoc, TidyWriteBack, yes ); + } + else if ( strcasecmp(arg, "errors") == 0 ) + tidyOptSetBool( tdoc, TidyShowMarkup, no ); + + else if ( strcasecmp(arg, "quiet") == 0 ) + tidyOptSetBool( tdoc, TidyQuiet, yes ); + + /* Currenly user must specify a language + prior to anything that causes output */ + else if ( strcasecmp(arg, "language") == 0 || + strcasecmp(arg, "lang") == 0 ) + if ( argc >= 3) + { + if ( strcasecmp(argv[2], "help") == 0 ) + { + lang_help(); + exit(0); + } + if ( !tidySetLanguage( argv[2] ) ) + { + printf(tidyLocalizedString(TC_STRING_LANG_NOT_FOUND), + argv[2], tidyGetLanguage()); + printf("\n"); + } else { #if defined(_WIN32) - /* If we set a language then force Windows console to use UTF, - * otherwise many characters will be garbage. @todo: aggregate - * all of this application's exits and returns so that we can - * reset the original code page upon termination. - */ - SetConsoleOutputCP(65001); + /* If we set a language then force Windows console to use UTF, + * otherwise many characters will be garbage. @todo: aggregate + * all of this application's exits and returns so that we can + * reset the original code page upon termination. + */ + SetConsoleOutputCP(65001); #endif - } - --argc; - ++argv; - } - else - { - printf( "%s\n", tidyLocalizedString(TC_STRING_LANG_MUST_SPECIFY)); - } + } + --argc; + ++argv; + } + else + { + printf( "%s\n", tidyLocalizedString(TC_STRING_LANG_MUST_SPECIFY)); + } + + else if ( strcasecmp(arg, "help") == 0 || + strcasecmp(arg, "-help") == 0 || + strcasecmp(arg, "h") == 0 || *arg == '?' ) + { + help( prog ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "xml-help") == 0) + { + xml_help( ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "xml-options-strings") == 0) + { + xml_options_strings( tdoc ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "xml-strings") == 0) + { + xml_strings( ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "help-config") == 0 ) + { + optionhelp( tdoc ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "help-option") == 0 ) + { + if ( argc >= 3) + { + optionDescribe( tdoc, argv[2] ); + } + else + { + printf( "%s\n", tidyLocalizedString(TC_STRING_MUST_SPECIFY)); + } + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "xml-config") == 0 ) + { + XMLoptionhelp( tdoc ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "show-config") == 0 ) + { + optionvalues( tdoc ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "config") == 0 ) + { + if ( argc >= 3 ) + { + ctmbstr post; + + tidyLoadConfig( tdoc, argv[2] ); + + /* Set new error output stream if setting changed */ + post = tidyOptGetValue( tdoc, TidyErrFile ); + if ( post && (!errfil || !samefile(errfil, post)) ) + { + errfil = post; + errout = tidySetErrorFile( tdoc, post ); + } + + --argc; + ++argv; + } + } + + else if ( strcasecmp(arg, "output") == 0 || + strcasecmp(arg, "-output-file") == 0 || + strcasecmp(arg, "o") == 0 ) + { + if ( argc >= 3 ) + { + tidyOptSetValue( tdoc, TidyOutFile, argv[2] ); + --argc; + ++argv; + } + } + else if ( strcasecmp(arg, "file") == 0 || + strcasecmp(arg, "-file") == 0 || + strcasecmp(arg, "f") == 0 ) + { + if ( argc >= 3 ) + { + errfil = argv[2]; + errout = tidySetErrorFile( tdoc, errfil ); + --argc; + ++argv; + } + } + else if ( strcasecmp(arg, "wrap") == 0 || + strcasecmp(arg, "-wrap") == 0 || + strcasecmp(arg, "w") == 0 ) + { + if ( argc >= 3 ) + { + uint wraplen = 0; + int nfields = sscanf( argv[2], "%u", &wraplen ); + tidyOptSetInt( tdoc, TidyWrapLen, wraplen ); + if (nfields > 0) + { + --argc; + ++argv; + } + } + } + else if ( strcasecmp(arg, "version") == 0 || + strcasecmp(arg, "-version") == 0 || + strcasecmp(arg, "v") == 0 ) + { + version(); + tidyRelease( tdoc ); + return 0; /* success */ + + } + else if ( strncmp(argv[1], "--", 2 ) == 0) + { + if ( tidyOptParseValue(tdoc, argv[1]+2, argv[2]) ) + { + /* Set new error output stream if setting changed */ + ctmbstr post = tidyOptGetValue( tdoc, TidyErrFile ); + if ( post && (!errfil || !samefile(errfil, post)) ) + { + errfil = post; + errout = tidySetErrorFile( tdoc, post ); + } + + ++argv; + --argc; + } + } - else if ( strcasecmp(arg, "help") == 0 || - strcasecmp(arg, "-help") == 0 || - strcasecmp(arg, "h") == 0 || *arg == '?' ) - { - help( prog ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "xml-help") == 0) - { - xml_help( ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "xml-options-strings") == 0) - { - xml_options_strings( tdoc ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "xml-strings") == 0) - { - xml_strings( ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "help-config") == 0 ) - { - optionhelp( tdoc ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "help-option") == 0 ) - { - if ( argc >= 3) - { - optionDescribe( tdoc, argv[2] ); - } - else - { - printf( "%s\n", tidyLocalizedString(TC_STRING_MUST_SPECIFY)); - } - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "xml-config") == 0 ) - { - XMLoptionhelp( tdoc ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "show-config") == 0 ) - { - optionvalues( tdoc ); - tidyRelease( tdoc ); - return 0; /* success */ - } - else if ( strcasecmp(arg, "config") == 0 ) - { - if ( argc >= 3 ) - { - ctmbstr post; - - tidyLoadConfig( tdoc, argv[2] ); - - /* Set new error output stream if setting changed */ - post = tidyOptGetValue( tdoc, TidyErrFile ); - if ( post && (!errfil || !samefile(errfil, post)) ) - { - errfil = post; - errout = tidySetErrorFile( tdoc, post ); - } - - --argc; - ++argv; - } - } - - else if ( strcasecmp(arg, "output") == 0 || - strcasecmp(arg, "-output-file") == 0 || - strcasecmp(arg, "o") == 0 ) - { - if ( argc >= 3 ) - { - tidyOptSetValue( tdoc, TidyOutFile, argv[2] ); - --argc; - ++argv; - } - } - else if ( strcasecmp(arg, "file") == 0 || - strcasecmp(arg, "-file") == 0 || - strcasecmp(arg, "f") == 0 ) - { - if ( argc >= 3 ) - { - errfil = argv[2]; - errout = tidySetErrorFile( tdoc, errfil ); - --argc; - ++argv; - } - } - else if ( strcasecmp(arg, "wrap") == 0 || - strcasecmp(arg, "-wrap") == 0 || - strcasecmp(arg, "w") == 0 ) - { - if ( argc >= 3 ) - { - uint wraplen = 0; - int nfields = sscanf( argv[2], "%u", &wraplen ); - tidyOptSetInt( tdoc, TidyWrapLen, wraplen ); - if (nfields > 0) - { - --argc; - ++argv; - } - } - } - else if ( strcasecmp(arg, "version") == 0 || - strcasecmp(arg, "-version") == 0 || - strcasecmp(arg, "v") == 0 ) - { - version(); - tidyRelease( tdoc ); - return 0; /* success */ - - } - else if ( strncmp(argv[1], "--", 2 ) == 0) - { - if ( tidyOptParseValue(tdoc, argv[1]+2, argv[2]) ) - { - /* Set new error output stream if setting changed */ - ctmbstr post = tidyOptGetValue( tdoc, TidyErrFile ); - if ( post && (!errfil || !samefile(errfil, post)) ) - { - errfil = post; - errout = tidySetErrorFile( tdoc, post ); - } - - ++argv; - --argc; - } - } - #if SUPPORT_ACCESSIBILITY_CHECKS - else if ( strcasecmp(arg, "access") == 0 ) - { - if ( argc >= 3 ) - { - uint acclvl = 0; - int nfields = sscanf( argv[2], "%u", &acclvl ); - tidyOptSetInt( tdoc, TidyAccessibilityCheckLevel, acclvl ); - if (nfields > 0) - { - --argc; - ++argv; - } - } - } + else if ( strcasecmp(arg, "access") == 0 ) + { + if ( argc >= 3 ) + { + uint acclvl = 0; + int nfields = sscanf( argv[2], "%u", &acclvl ); + tidyOptSetInt( tdoc, TidyAccessibilityCheckLevel, acclvl ); + if (nfields > 0) + { + --argc; + ++argv; + } + } + } #endif - - else - { - uint c; - ctmbstr s = argv[1]; - - while ( (c = *++s) != '\0' ) - { - switch ( c ) - { - case 'i': - tidyOptSetInt( tdoc, TidyIndentContent, TidyAutoState ); - if ( tidyOptGetInt(tdoc, TidyIndentSpaces) == 0 ) - tidyOptResetToDefault( tdoc, TidyIndentSpaces ); - break; - - /* Usurp -o for output file. Anyone hiding end tags? - case 'o': - tidyOptSetBool( tdoc, TidyHideEndTags, yes ); - break; - */ - - case 'u': - tidyOptSetBool( tdoc, TidyUpperCaseTags, yes ); - break; - - case 'c': - tidyOptSetBool( tdoc, TidyMakeClean, yes ); - break; - - case 'g': - tidyOptSetBool( tdoc, TidyGDocClean, yes ); - break; - - case 'b': - tidyOptSetBool( tdoc, TidyMakeBare, yes ); - break; - - case 'n': - tidyOptSetBool( tdoc, TidyNumEntities, yes ); - break; - - case 'm': - tidyOptSetBool( tdoc, TidyWriteBack, yes ); - break; - - case 'e': - tidyOptSetBool( tdoc, TidyShowMarkup, no ); - break; - - case 'q': - tidyOptSetBool( tdoc, TidyQuiet, yes ); - break; - - default: - unknownOption( c ); - break; - } - } - } - - --argc; - ++argv; - continue; - } - - if ( argc > 1 ) - { - htmlfil = argv[1]; -#if (!defined(NDEBUG) && defined(_MSC_VER)) - SPRTF("Tidying '%s'\n", htmlfil); -#endif // DEBUG outout - if ( tidyOptGetBool(tdoc, TidyEmacs) ) - tidyOptSetValue( tdoc, TidyEmacsFile, htmlfil ); - status = tidyParseFile( tdoc, htmlfil ); - } - else - { - htmlfil = "stdin"; - status = tidyParseStdin( tdoc ); - } - - if ( status >= 0 ) - status = tidyCleanAndRepair( tdoc ); - - if ( status >= 0 ) { - status = tidyRunDiagnostics( tdoc ); - if ( !tidyOptGetBool(tdoc, TidyQuiet) ) { - /* NOT quiet, show DOCTYPE, if not already shown */ - if (!tidyOptGetBool(tdoc, TidyShowInfo)) { - tidyOptSetBool( tdoc, TidyShowInfo, yes ); - tidyReportDoctype( tdoc ); /* FIX20140913: like warnings, errors, ALWAYS report DOCTYPE */ - tidyOptSetBool( tdoc, TidyShowInfo, no ); - } - } - - } - if ( status > 1 ) /* If errors, do we want to force output? */ - status = ( tidyOptGetBool(tdoc, TidyForceOutput) ? status : -1 ); - - if ( status >= 0 && tidyOptGetBool(tdoc, TidyShowMarkup) ) - { - if ( tidyOptGetBool(tdoc, TidyWriteBack) && argc > 1 ) - status = tidySaveFile( tdoc, htmlfil ); - else - { - ctmbstr outfil = tidyOptGetValue( tdoc, TidyOutFile ); - if ( outfil ) { - status = tidySaveFile( tdoc, outfil ); - } else { -#if !defined(NDEBUG) && defined(_MSC_VER) - static char tmp_buf[264]; - sprintf(tmp_buf,"%s.html",get_log_file()); - status = tidySaveFile( tdoc, tmp_buf ); - SPRTF("Saved tidied content to '%s'\n",tmp_buf); -#else - status = tidySaveStdout( tdoc ); -#endif - } - } - } - - contentErrors += tidyErrorCount( tdoc ); - contentWarnings += tidyWarningCount( tdoc ); - accessWarnings += tidyAccessWarningCount( tdoc ); - - --argc; - ++argv; - - if ( argc <= 1 ) - break; - } /* read command line loop */ - - if (!tidyOptGetBool(tdoc, TidyQuiet) && - errout == stderr && !contentErrors) - fprintf(errout, "\n"); - - if (contentErrors + contentWarnings > 0 && - !tidyOptGetBool(tdoc, TidyQuiet)) - tidyErrorSummary(tdoc); - - if (!tidyOptGetBool(tdoc, TidyQuiet)) - tidyGeneralInfo(tdoc); - - /* called to free hash tables etc. */ - tidyRelease( tdoc ); - - /* return status can be used by scripts */ - if ( contentErrors > 0 ) - return 2; - - if ( contentWarnings > 0 ) - return 1; - - /* 0 signifies all is ok */ - return 0; + else + { + uint c; + ctmbstr s = argv[1]; + + while ( (c = *++s) != '\0' ) + { + switch ( c ) + { + case 'i': + tidyOptSetInt( tdoc, TidyIndentContent, TidyAutoState ); + if ( tidyOptGetInt(tdoc, TidyIndentSpaces) == 0 ) + tidyOptResetToDefault( tdoc, TidyIndentSpaces ); + break; + + /* Usurp -o for output file. Anyone hiding end tags? + case 'o': + tidyOptSetBool( tdoc, TidyHideEndTags, yes ); + break; + */ + + case 'u': + tidyOptSetBool( tdoc, TidyUpperCaseTags, yes ); + break; + + case 'c': + tidyOptSetBool( tdoc, TidyMakeClean, yes ); + break; + + case 'g': + tidyOptSetBool( tdoc, TidyGDocClean, yes ); + break; + + case 'b': + tidyOptSetBool( tdoc, TidyMakeBare, yes ); + break; + + case 'n': + tidyOptSetBool( tdoc, TidyNumEntities, yes ); + break; + + case 'm': + tidyOptSetBool( tdoc, TidyWriteBack, yes ); + break; + + case 'e': + tidyOptSetBool( tdoc, TidyShowMarkup, no ); + break; + + case 'q': + tidyOptSetBool( tdoc, TidyQuiet, yes ); + break; + + default: + unknownOption( c ); + break; + } + } + } + + --argc; + ++argv; + continue; + } + + if ( argc > 1 ) + { + htmlfil = argv[1]; +#if (!defined(NDEBUG) && defined(_MSC_VER)) + SPRTF("Tidying '%s'\n", htmlfil); +#endif // DEBUG outout + if ( tidyOptGetBool(tdoc, TidyEmacs) ) + tidyOptSetValue( tdoc, TidyEmacsFile, htmlfil ); + status = tidyParseFile( tdoc, htmlfil ); + } + else + { + htmlfil = "stdin"; + status = tidyParseStdin( tdoc ); + } + + if ( status >= 0 ) + status = tidyCleanAndRepair( tdoc ); + + if ( status >= 0 ) { + status = tidyRunDiagnostics( tdoc ); + if ( !tidyOptGetBool(tdoc, TidyQuiet) ) { + /* NOT quiet, show DOCTYPE, if not already shown */ + if (!tidyOptGetBool(tdoc, TidyShowInfo)) { + tidyOptSetBool( tdoc, TidyShowInfo, yes ); + tidyReportDoctype( tdoc ); /* FIX20140913: like warnings, errors, ALWAYS report DOCTYPE */ + tidyOptSetBool( tdoc, TidyShowInfo, no ); + } + } + + } + if ( status > 1 ) /* If errors, do we want to force output? */ + status = ( tidyOptGetBool(tdoc, TidyForceOutput) ? status : -1 ); + + if ( status >= 0 && tidyOptGetBool(tdoc, TidyShowMarkup) ) + { + if ( tidyOptGetBool(tdoc, TidyWriteBack) && argc > 1 ) + status = tidySaveFile( tdoc, htmlfil ); + else + { + ctmbstr outfil = tidyOptGetValue( tdoc, TidyOutFile ); + if ( outfil ) { + status = tidySaveFile( tdoc, outfil ); + } else { +#if !defined(NDEBUG) && defined(_MSC_VER) + static char tmp_buf[264]; + sprintf(tmp_buf,"%s.html",get_log_file()); + status = tidySaveFile( tdoc, tmp_buf ); + SPRTF("Saved tidied content to '%s'\n",tmp_buf); +#else + status = tidySaveStdout( tdoc ); +#endif + } + } + } + + contentErrors += tidyErrorCount( tdoc ); + contentWarnings += tidyWarningCount( tdoc ); + accessWarnings += tidyAccessWarningCount( tdoc ); + + --argc; + ++argv; + + if ( argc <= 1 ) + break; + } /* read command line loop */ + + + if (!tidyOptGetBool(tdoc, TidyQuiet) && + errout == stderr && !contentErrors) + fprintf(errout, "\n"); + + if (contentErrors + contentWarnings > 0 && + !tidyOptGetBool(tdoc, TidyQuiet)) + tidyErrorSummary(tdoc); + + if (!tidyOptGetBool(tdoc, TidyQuiet)) + tidyGeneralInfo(tdoc); + + /* called to free hash tables etc. */ + tidyRelease( tdoc ); + + /* return status can be used by scripts */ + if ( contentErrors > 0 ) + return 2; + + if ( contentWarnings > 0 ) + return 1; + + /* 0 signifies all is ok */ + return 0; } /* diff --git a/include/tidy.h b/include/tidy.h index 8a30d9f..f20e12d 100755 --- a/include/tidy.h +++ b/include/tidy.h @@ -645,6 +645,9 @@ typedef Bool (TIDY_CALL *TidyReportFilter)( TidyDoc tdoc, TidyReportLevel lvl, typedef Bool (TIDY_CALL *TidyReportFilter2)( TidyDoc tdoc, TidyReportLevel lvl, uint line, uint col, ctmbstr mssg, va_list args ); +typedef Bool (TIDY_CALL *TidyReportFilter3)( TidyDoc tdoc, TidyReportLevel lvl, + uint line, uint col, ctmbstr code, va_list args ); + /** Give Tidy a filter callback to use */ TIDY_EXPORT Bool TIDY_CALL tidySetReportFilter( TidyDoc tdoc, TidyReportFilter filtCallback ); @@ -652,6 +655,9 @@ TIDY_EXPORT Bool TIDY_CALL tidySetReportFilter( TidyDoc tdoc, TIDY_EXPORT Bool TIDY_CALL tidySetReportFilter2( TidyDoc tdoc, TidyReportFilter2 filtCallback ); +TIDY_EXPORT Bool TIDY_CALL tidySetReportFilter3( TidyDoc tdoc, + TidyReportFilter3 filtCallback ); + /** Set error sink to named file */ TIDY_EXPORT FILE* TIDY_CALL tidySetErrorFile( TidyDoc tdoc, ctmbstr errfilnam ); /** Set error sink to given buffer */ diff --git a/src/access.h b/src/access.h index ed18bcc..5536437 100644 --- a/src/access.h +++ b/src/access.h @@ -118,6 +118,10 @@ struct _TidyAccessImpl These accessErrorCodes are used throughout libtidy, and also have associated localized strings to describe them. + + IMPORTANT: to maintain compatability with TidyMessageFilter3, if you add + or remove keys from this enum, ALSO add/remove the corresponding key + in language.c:tidyErrorFilterKeysStruct[]! */ typedef enum { diff --git a/src/language.c b/src/language.c index 19fa8e1..a93c7cf 100644 --- a/src/language.c +++ b/src/language.c @@ -229,6 +229,271 @@ static const tidyLocaleMapItem localeMappings[] = { }; +/** + * Provides the mapping for LibTidy users to map between an opaque key + * and an error message value. See `tidyErrorFilterKeys[]`, below. + */ +typedef struct tidyErrorFilterKeyItem { + ctmbstr key; + int value; +} tidyErrorFilterKeyItem; + + +/** + * LibTidy users may want to use `TidyReportFilter3` to enable their own + * localization lookup features. Because Tidy's errors codes are enums the + * specific values can change over time. This table will ensure that LibTidy + * users always have a static value available for use. + */ +static const tidyErrorFilterKeyItem tidyErrorFilterKeysStruct[] = { + { "CODES_TIDY_ERROR_FIRST", CODES_TIDY_ERROR_FIRST }, + { "MISSING_SEMICOLON", MISSING_SEMICOLON }, + { "MISSING_SEMICOLON_NCR", MISSING_SEMICOLON_NCR }, + { "UNKNOWN_ENTITY", UNKNOWN_ENTITY }, + { "UNESCAPED_AMPERSAND", UNESCAPED_AMPERSAND }, + { "APOS_UNDEFINED", APOS_UNDEFINED }, + { "MISSING_ENDTAG_FOR", MISSING_ENDTAG_FOR }, + { "MISSING_ENDTAG_BEFORE", MISSING_ENDTAG_BEFORE }, + { "DISCARDING_UNEXPECTED", DISCARDING_UNEXPECTED }, + { "NESTED_EMPHASIS", NESTED_EMPHASIS }, + { "NON_MATCHING_ENDTAG", NON_MATCHING_ENDTAG }, + { "TAG_NOT_ALLOWED_IN", TAG_NOT_ALLOWED_IN }, + { "MISSING_STARTTAG", MISSING_STARTTAG }, + { "UNEXPECTED_ENDTAG", UNEXPECTED_ENDTAG }, + { "USING_BR_INPLACE_OF", USING_BR_INPLACE_OF }, + { "INSERTING_TAG", INSERTING_TAG }, + { "SUSPECTED_MISSING_QUOTE", SUSPECTED_MISSING_QUOTE }, + { "MISSING_TITLE_ELEMENT", MISSING_TITLE_ELEMENT }, + { "DUPLICATE_FRAMESET", DUPLICATE_FRAMESET }, + { "CANT_BE_NESTED", CANT_BE_NESTED }, + { "OBSOLETE_ELEMENT", OBSOLETE_ELEMENT }, + { "PROPRIETARY_ELEMENT", PROPRIETARY_ELEMENT }, + { "UNKNOWN_ELEMENT", UNKNOWN_ELEMENT }, + { "TRIM_EMPTY_ELEMENT", TRIM_EMPTY_ELEMENT }, + { "COERCE_TO_ENDTAG", COERCE_TO_ENDTAG }, + { "ILLEGAL_NESTING", ILLEGAL_NESTING }, + { "NOFRAMES_CONTENT", NOFRAMES_CONTENT }, + { "CONTENT_AFTER_BODY", CONTENT_AFTER_BODY }, + { "INCONSISTENT_VERSION", INCONSISTENT_VERSION }, + { "MALFORMED_COMMENT", MALFORMED_COMMENT }, + { "BAD_COMMENT_CHARS", BAD_COMMENT_CHARS }, + { "BAD_XML_COMMENT", BAD_XML_COMMENT }, + { "BAD_CDATA_CONTENT", BAD_CDATA_CONTENT }, + { "INCONSISTENT_NAMESPACE", INCONSISTENT_NAMESPACE }, + { "DOCTYPE_AFTER_TAGS", DOCTYPE_AFTER_TAGS }, + { "MALFORMED_DOCTYPE", MALFORMED_DOCTYPE }, + { "UNEXPECTED_END_OF_FILE", UNEXPECTED_END_OF_FILE }, + { "DTYPE_NOT_UPPER_CASE", DTYPE_NOT_UPPER_CASE }, + { "TOO_MANY_ELEMENTS", TOO_MANY_ELEMENTS }, + { "UNESCAPED_ELEMENT", UNESCAPED_ELEMENT }, + { "NESTED_QUOTATION", NESTED_QUOTATION }, + { "ELEMENT_NOT_EMPTY", ELEMENT_NOT_EMPTY }, + { "ENCODING_IO_CONFLICT", ENCODING_IO_CONFLICT }, + { "MIXED_CONTENT_IN_BLOCK", MIXED_CONTENT_IN_BLOCK }, + { "MISSING_DOCTYPE", MISSING_DOCTYPE }, + { "SPACE_PRECEDING_XMLDECL", SPACE_PRECEDING_XMLDECL }, + { "TOO_MANY_ELEMENTS_IN", TOO_MANY_ELEMENTS_IN }, + { "UNEXPECTED_ENDTAG_IN", UNEXPECTED_ENDTAG_IN }, + { "REPLACING_ELEMENT", REPLACING_ELEMENT }, + { "REPLACING_UNEX_ELEMENT", REPLACING_UNEX_ELEMENT }, + { "COERCE_TO_ENDTAG_WARN", COERCE_TO_ENDTAG_WARN }, + { "UNKNOWN_ATTRIBUTE", UNKNOWN_ATTRIBUTE }, + { "INSERTING_ATTRIBUTE", INSERTING_ATTRIBUTE }, + { "INSERTING_AUTO_ATTRIBUTE", INSERTING_AUTO_ATTRIBUTE }, + { "MISSING_ATTR_VALUE", MISSING_ATTR_VALUE }, + { "BAD_ATTRIBUTE_VALUE", BAD_ATTRIBUTE_VALUE }, + { "UNEXPECTED_GT", UNEXPECTED_GT }, + { "PROPRIETARY_ATTRIBUTE", PROPRIETARY_ATTRIBUTE }, + { "PROPRIETARY_ATTR_VALUE", PROPRIETARY_ATTR_VALUE }, + { "REPEATED_ATTRIBUTE", REPEATED_ATTRIBUTE }, + { "MISSING_IMAGEMAP", MISSING_IMAGEMAP }, + { "XML_ATTRIBUTE_VALUE", XML_ATTRIBUTE_VALUE }, + { "UNEXPECTED_QUOTEMARK", UNEXPECTED_QUOTEMARK }, + { "MISSING_QUOTEMARK", MISSING_QUOTEMARK }, + { "ID_NAME_MISMATCH", ID_NAME_MISMATCH }, + { "BACKSLASH_IN_URI", BACKSLASH_IN_URI }, + { "FIXED_BACKSLASH", FIXED_BACKSLASH }, + { "ILLEGAL_URI_REFERENCE", ILLEGAL_URI_REFERENCE }, + { "ESCAPED_ILLEGAL_URI", ESCAPED_ILLEGAL_URI }, + { "NEWLINE_IN_URI", NEWLINE_IN_URI }, + { "ANCHOR_NOT_UNIQUE", ANCHOR_NOT_UNIQUE }, + { "JOINING_ATTRIBUTE", JOINING_ATTRIBUTE }, + { "UNEXPECTED_EQUALSIGN", UNEXPECTED_EQUALSIGN }, + { "ATTR_VALUE_NOT_LCASE", ATTR_VALUE_NOT_LCASE }, + { "XML_ID_SYNTAX", XML_ID_SYNTAX }, + { "INVALID_ATTRIBUTE", INVALID_ATTRIBUTE }, + { "BAD_ATTRIBUTE_VALUE_REPLACED", BAD_ATTRIBUTE_VALUE_REPLACED }, + { "INVALID_XML_ID", INVALID_XML_ID }, + { "UNEXPECTED_END_OF_FILE_ATTR", UNEXPECTED_END_OF_FILE_ATTR }, + { "MISSING_ATTRIBUTE", MISSING_ATTRIBUTE }, + { "WHITE_IN_URI", WHITE_IN_URI }, + { "REMOVED_HTML5", REMOVED_HTML5 }, + { "BAD_BODY_HTML5", BAD_BODY_HTML5 }, + { "BAD_ALIGN_HTML5", BAD_ALIGN_HTML5 }, + { "BAD_SUMMARY_HTML5", BAD_SUMMARY_HTML5 }, + { "PREVIOUS_LOCATION", PREVIOUS_LOCATION }, + { "VENDOR_SPECIFIC_CHARS", VENDOR_SPECIFIC_CHARS }, + { "INVALID_SGML_CHARS", INVALID_SGML_CHARS }, + { "INVALID_UTF8", INVALID_UTF8 }, + { "INVALID_UTF16", INVALID_UTF16 }, + { "ENCODING_MISMATCH", ENCODING_MISMATCH }, + { "INVALID_URI", INVALID_URI }, + { "INVALID_NCR", INVALID_NCR }, + { "CODES_TIDY_ERROR_LAST", CODES_TIDY_ERROR_LAST }, +#if SUPPORT_ACCESSIBILITY_CHECKS + { "FIRST_ACCESS_ERR", FIRST_ACCESS_ERR }, + { "IMG_MISSING_ALT", IMG_MISSING_ALT }, + { "IMG_ALT_SUSPICIOUS_FILENAME", IMG_ALT_SUSPICIOUS_FILENAME }, + { "IMG_ALT_SUSPICIOUS_FILE_SIZE", IMG_ALT_SUSPICIOUS_FILE_SIZE }, + { "IMG_ALT_SUSPICIOUS_PLACEHOLDER", IMG_ALT_SUSPICIOUS_PLACEHOLDER }, + { "IMG_ALT_SUSPICIOUS_TOO_LONG", IMG_ALT_SUSPICIOUS_TOO_LONG }, + { "IMG_MISSING_ALT_BULLET", IMG_MISSING_ALT_BULLET }, + { "IMG_MISSING_ALT_H_RULE", IMG_MISSING_ALT_H_RULE }, + { "IMG_MISSING_LONGDESC_DLINK", IMG_MISSING_LONGDESC_DLINK }, + { "IMG_MISSING_DLINK", IMG_MISSING_DLINK }, + { "IMG_MISSING_LONGDESC", IMG_MISSING_LONGDESC }, + { "LONGDESC_NOT_REQUIRED", LONGDESC_NOT_REQUIRED }, + { "IMG_BUTTON_MISSING_ALT", IMG_BUTTON_MISSING_ALT }, + { "APPLET_MISSING_ALT", APPLET_MISSING_ALT }, + { "OBJECT_MISSING_ALT", OBJECT_MISSING_ALT }, + { "AUDIO_MISSING_TEXT_WAV", AUDIO_MISSING_TEXT_WAV }, + { "AUDIO_MISSING_TEXT_AU", AUDIO_MISSING_TEXT_AU }, + { "AUDIO_MISSING_TEXT_AIFF", AUDIO_MISSING_TEXT_AIFF }, + { "AUDIO_MISSING_TEXT_SND", AUDIO_MISSING_TEXT_SND }, + { "AUDIO_MISSING_TEXT_RA", AUDIO_MISSING_TEXT_RA }, + { "AUDIO_MISSING_TEXT_RM", AUDIO_MISSING_TEXT_RM }, + { "FRAME_MISSING_LONGDESC", FRAME_MISSING_LONGDESC }, + { "AREA_MISSING_ALT", AREA_MISSING_ALT }, + { "SCRIPT_MISSING_NOSCRIPT", SCRIPT_MISSING_NOSCRIPT }, + { "ASCII_REQUIRES_DESCRIPTION", ASCII_REQUIRES_DESCRIPTION }, + { "IMG_MAP_SERVER_REQUIRES_TEXT_LINKS", IMG_MAP_SERVER_REQUIRES_TEXT_LINKS }, + { "MULTIMEDIA_REQUIRES_TEXT", MULTIMEDIA_REQUIRES_TEXT }, + { "IMG_MAP_CLIENT_MISSING_TEXT_LINKS", IMG_MAP_CLIENT_MISSING_TEXT_LINKS }, + { "INFORMATION_NOT_CONVEYED_IMAGE", INFORMATION_NOT_CONVEYED_IMAGE }, + { "INFORMATION_NOT_CONVEYED_APPLET", INFORMATION_NOT_CONVEYED_APPLET }, + { "INFORMATION_NOT_CONVEYED_OBJECT", INFORMATION_NOT_CONVEYED_OBJECT }, + { "INFORMATION_NOT_CONVEYED_SCRIPT", INFORMATION_NOT_CONVEYED_SCRIPT }, + { "INFORMATION_NOT_CONVEYED_INPUT", INFORMATION_NOT_CONVEYED_INPUT }, + { "COLOR_CONTRAST_TEXT", COLOR_CONTRAST_TEXT }, + { "COLOR_CONTRAST_LINK", COLOR_CONTRAST_LINK }, + { "COLOR_CONTRAST_ACTIVE_LINK", COLOR_CONTRAST_ACTIVE_LINK }, + { "COLOR_CONTRAST_VISITED_LINK", COLOR_CONTRAST_VISITED_LINK }, + { "DOCTYPE_MISSING", DOCTYPE_MISSING }, + { "STYLE_SHEET_CONTROL_PRESENTATION", STYLE_SHEET_CONTROL_PRESENTATION }, + { "HEADERS_IMPROPERLY_NESTED", HEADERS_IMPROPERLY_NESTED }, + { "POTENTIAL_HEADER_BOLD", POTENTIAL_HEADER_BOLD }, + { "POTENTIAL_HEADER_ITALICS", POTENTIAL_HEADER_ITALICS }, + { "POTENTIAL_HEADER_UNDERLINE", POTENTIAL_HEADER_UNDERLINE }, + { "HEADER_USED_FORMAT_TEXT", HEADER_USED_FORMAT_TEXT }, + { "LIST_USAGE_INVALID_UL", LIST_USAGE_INVALID_UL }, + { "LIST_USAGE_INVALID_OL", LIST_USAGE_INVALID_OL }, + { "LIST_USAGE_INVALID_LI", LIST_USAGE_INVALID_LI }, + { "INDICATE_CHANGES_IN_LANGUAGE", INDICATE_CHANGES_IN_LANGUAGE }, + { "LANGUAGE_NOT_IDENTIFIED", LANGUAGE_NOT_IDENTIFIED }, + { "LANGUAGE_INVALID", LANGUAGE_INVALID }, + { "DATA_TABLE_MISSING_HEADERS", DATA_TABLE_MISSING_HEADERS }, + { "DATA_TABLE_MISSING_HEADERS_COLUMN", DATA_TABLE_MISSING_HEADERS_COLUMN }, + { "DATA_TABLE_MISSING_HEADERS_ROW", DATA_TABLE_MISSING_HEADERS_ROW }, + { "DATA_TABLE_REQUIRE_MARKUP_COLUMN_HEADERS", DATA_TABLE_REQUIRE_MARKUP_COLUMN_HEADERS }, + { "DATA_TABLE_REQUIRE_MARKUP_ROW_HEADERS", DATA_TABLE_REQUIRE_MARKUP_ROW_HEADERS }, + { "LAYOUT_TABLES_LINEARIZE_PROPERLY", LAYOUT_TABLES_LINEARIZE_PROPERLY }, + { "LAYOUT_TABLE_INVALID_MARKUP", LAYOUT_TABLE_INVALID_MARKUP }, + { "TABLE_MISSING_SUMMARY", TABLE_MISSING_SUMMARY }, + { "TABLE_SUMMARY_INVALID_NULL", TABLE_SUMMARY_INVALID_NULL }, + { "TABLE_SUMMARY_INVALID_SPACES", TABLE_SUMMARY_INVALID_SPACES }, + { "TABLE_SUMMARY_INVALID_PLACEHOLDER", TABLE_SUMMARY_INVALID_PLACEHOLDER }, + { "TABLE_MISSING_CAPTION", TABLE_MISSING_CAPTION }, + { "TABLE_MAY_REQUIRE_HEADER_ABBR", TABLE_MAY_REQUIRE_HEADER_ABBR }, + { "TABLE_MAY_REQUIRE_HEADER_ABBR_NULL", TABLE_MAY_REQUIRE_HEADER_ABBR_NULL }, + { "TABLE_MAY_REQUIRE_HEADER_ABBR_SPACES", TABLE_MAY_REQUIRE_HEADER_ABBR_SPACES }, + { "STYLESHEETS_REQUIRE_TESTING_LINK", STYLESHEETS_REQUIRE_TESTING_LINK }, + { "STYLESHEETS_REQUIRE_TESTING_STYLE_ELEMENT", STYLESHEETS_REQUIRE_TESTING_STYLE_ELEMENT }, + { "STYLESHEETS_REQUIRE_TESTING_STYLE_ATTR", STYLESHEETS_REQUIRE_TESTING_STYLE_ATTR }, + { "FRAME_SRC_INVALID", FRAME_SRC_INVALID }, + { "TEXT_EQUIVALENTS_REQUIRE_UPDATING_APPLET", TEXT_EQUIVALENTS_REQUIRE_UPDATING_APPLET }, + { "TEXT_EQUIVALENTS_REQUIRE_UPDATING_SCRIPT", TEXT_EQUIVALENTS_REQUIRE_UPDATING_SCRIPT }, + { "TEXT_EQUIVALENTS_REQUIRE_UPDATING_OBJECT", TEXT_EQUIVALENTS_REQUIRE_UPDATING_OBJECT }, + { "PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_SCRIPT", PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_SCRIPT }, + { "PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_OBJECT", PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_OBJECT }, + { "PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_EMBED", PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_EMBED }, + { "PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_APPLET", PROGRAMMATIC_OBJECTS_REQUIRE_TESTING_APPLET }, + { "FRAME_MISSING_NOFRAMES", FRAME_MISSING_NOFRAMES }, + { "NOFRAMES_INVALID_NO_VALUE", NOFRAMES_INVALID_NO_VALUE }, + { "NOFRAMES_INVALID_CONTENT", NOFRAMES_INVALID_CONTENT }, + { "NOFRAMES_INVALID_LINK", NOFRAMES_INVALID_LINK }, + { "REMOVE_FLICKER_SCRIPT", REMOVE_FLICKER_SCRIPT }, + { "REMOVE_FLICKER_OBJECT", REMOVE_FLICKER_OBJECT }, + { "REMOVE_FLICKER_EMBED", REMOVE_FLICKER_EMBED }, + { "REMOVE_FLICKER_APPLET", REMOVE_FLICKER_APPLET }, + { "REMOVE_FLICKER_ANIMATED_GIF", REMOVE_FLICKER_ANIMATED_GIF }, + { "REMOVE_BLINK_MARQUEE", REMOVE_BLINK_MARQUEE }, + { "REMOVE_AUTO_REFRESH", REMOVE_AUTO_REFRESH }, + { "REMOVE_AUTO_REDIRECT", REMOVE_AUTO_REDIRECT }, + { "ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_SCRIPT", ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_SCRIPT }, + { "ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_OBJECT", ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_OBJECT }, + { "ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_APPLET", ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_APPLET }, + { "ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_EMBED", ENSURE_PROGRAMMATIC_OBJECTS_ACCESSIBLE_EMBED }, + { "IMAGE_MAP_SERVER_SIDE_REQUIRES_CONVERSION", IMAGE_MAP_SERVER_SIDE_REQUIRES_CONVERSION }, + { "SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_DOWN", SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_DOWN }, + { "SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_UP", SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_UP }, + { "SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_CLICK", SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_CLICK }, + { "SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_OVER", SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_OVER }, + { "SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_OUT", SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_OUT }, + { "SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_MOVE", SCRIPT_NOT_KEYBOARD_ACCESSIBLE_ON_MOUSE_MOVE }, + { "NEW_WINDOWS_REQUIRE_WARNING_NEW", NEW_WINDOWS_REQUIRE_WARNING_NEW }, + { "NEW_WINDOWS_REQUIRE_WARNING_BLANK", NEW_WINDOWS_REQUIRE_WARNING_BLANK }, + { "LABEL_NEEDS_REPOSITIONING_BEFORE_INPUT", LABEL_NEEDS_REPOSITIONING_BEFORE_INPUT }, + { "LABEL_NEEDS_REPOSITIONING_AFTER_INPUT", LABEL_NEEDS_REPOSITIONING_AFTER_INPUT }, + { "FORM_CONTROL_REQUIRES_DEFAULT_TEXT", FORM_CONTROL_REQUIRES_DEFAULT_TEXT }, + { "FORM_CONTROL_DEFAULT_TEXT_INVALID_NULL", FORM_CONTROL_DEFAULT_TEXT_INVALID_NULL }, + { "FORM_CONTROL_DEFAULT_TEXT_INVALID_SPACES", FORM_CONTROL_DEFAULT_TEXT_INVALID_SPACES }, + { "REPLACE_DEPRECATED_HTML_APPLET", REPLACE_DEPRECATED_HTML_APPLET }, + { "REPLACE_DEPRECATED_HTML_BASEFONT", REPLACE_DEPRECATED_HTML_BASEFONT }, + { "REPLACE_DEPRECATED_HTML_CENTER", REPLACE_DEPRECATED_HTML_CENTER }, + { "REPLACE_DEPRECATED_HTML_DIR", REPLACE_DEPRECATED_HTML_DIR }, + { "REPLACE_DEPRECATED_HTML_FONT", REPLACE_DEPRECATED_HTML_FONT }, + { "REPLACE_DEPRECATED_HTML_ISINDEX", REPLACE_DEPRECATED_HTML_ISINDEX }, + { "REPLACE_DEPRECATED_HTML_MENU", REPLACE_DEPRECATED_HTML_MENU }, + { "REPLACE_DEPRECATED_HTML_S", REPLACE_DEPRECATED_HTML_S }, + { "REPLACE_DEPRECATED_HTML_STRIKE", REPLACE_DEPRECATED_HTML_STRIKE }, + { "REPLACE_DEPRECATED_HTML_U", REPLACE_DEPRECATED_HTML_U }, + { "FRAME_MISSING_TITLE", FRAME_MISSING_TITLE }, + { "FRAME_TITLE_INVALID_NULL", FRAME_TITLE_INVALID_NULL }, + { "FRAME_TITLE_INVALID_SPACES", FRAME_TITLE_INVALID_SPACES }, + { "ASSOCIATE_LABELS_EXPLICITLY", ASSOCIATE_LABELS_EXPLICITLY }, + { "ASSOCIATE_LABELS_EXPLICITLY_FOR", ASSOCIATE_LABELS_EXPLICITLY_FOR }, + { "ASSOCIATE_LABELS_EXPLICITLY_ID", ASSOCIATE_LABELS_EXPLICITLY_ID }, + { "LINK_TEXT_NOT_MEANINGFUL", LINK_TEXT_NOT_MEANINGFUL }, + { "LINK_TEXT_MISSING", LINK_TEXT_MISSING }, + { "LINK_TEXT_TOO_LONG", LINK_TEXT_TOO_LONG }, + { "LINK_TEXT_NOT_MEANINGFUL_CLICK_HERE", LINK_TEXT_NOT_MEANINGFUL_CLICK_HERE }, + { "LINK_TEXT_NOT_MEANINGFUL_MORE", LINK_TEXT_NOT_MEANINGFUL_MORE }, + { "LINK_TEXT_NOT_MEANINGFUL_FOLLOW_THIS", LINK_TEXT_NOT_MEANINGFUL_FOLLOW_THIS }, + { "METADATA_MISSING", METADATA_MISSING }, + { "METADATA_MISSING_LINK", METADATA_MISSING_LINK }, + { "METADATA_MISSING_REDIRECT_AUTOREFRESH", METADATA_MISSING_REDIRECT_AUTOREFRESH }, + { "SKIPOVER_ASCII_ART", SKIPOVER_ASCII_ART }, + { "LAST_ACCESS_ERR", LAST_ACCESS_ERR }, +#endif + { NULL, 0 }, +}; + + +/** + * Given an error code, return the string associated with it. + */ +ctmbstr tidyErrorCodeAsString(uint code) +{ + uint i = 0; + while (tidyErrorFilterKeysStruct[i].key) { + if ( tidyErrorFilterKeysStruct[i].value == code ) + return tidyErrorFilterKeysStruct[i].key; + i++; + } + return "UNDEFINED"; +} + + /** * The real string lookup function. */ diff --git a/src/language.h b/src/language.h index b832ae4..4430971 100644 --- a/src/language.h +++ b/src/language.h @@ -17,7 +17,6 @@ #include "tidyplatform.h" - /** @name Exposed Data Structures */ /** @{ */ @@ -56,7 +55,6 @@ typedef struct languageDefinition { } languageDefinition; - /** * The function getNextWindowsLanguage() returns pointers to this type; * it gives LibTidy implementors the ability to determine how Windows @@ -75,11 +73,11 @@ typedef struct tidyLocaleMapItem { * comprehensive list of enums for which we provides strings * is as follows: * - `tidyMessageTypes` in this file, start == 4096. - * - `accessErrorCodes` from `access.h`, start == 1000. * - `tidyErrorCodes` from `message.h`, start == 200. + * - `accessErrorCodes` from `access.h`, start == CODES_TIDY_ERROR_LAST+1. * - `tidyMessagesMisc` from `message.h`, start == 2048. * - `TidyOptionId` from `tidyEnum.h`, start == 0 (important!). - * - `TidyReportLevelKeys` from `tidyEnum.h`, start == 500. + * - `TidyReportLevelKeys` from `tidyEnum.h`, start == 600. * - ... * You should never count on the value of a label being * constant. Accordingly feel free to arrange new enum @@ -188,6 +186,18 @@ typedef enum } tidyMessageTypes; +/** + * LibTidy users may want to use `TidyReportFilter3` to enable their own + * localization lookup features. Because Tidy's errors codes are enums the + * specific values can change over time. This function returns a string + * representing the enum value name that can be used as a lookup key + * independent of changing string values (TidyReportFiler2 is vulnerable + * to changing strings). `TidyReportFilter3` will return this general + * string as the error message indicator. + */ +ctmbstr tidyErrorCodeAsString(uint code); + + /** @} */ /** @name Localization Related Functions */ /** @{ */ diff --git a/src/message.c b/src/message.c index ef77265..af43e96 100755 --- a/src/message.c +++ b/src/message.c @@ -247,6 +247,14 @@ static void messagePos( TidyDocImpl* doc, TidyReportLevel level, uint code, TidyDoc tdoc = tidyImplToDoc( doc ); go = go | doc->mssgFilt2( tdoc, level, line, col, tidyDefaultString(code), args_copy ); } + if ( doc->mssgFilt3 ) + { + /* mssgFilt3 is intended to allow LibTidy users to localize + messages via their own means by providing a key string and + the parameters to fill it. */ + TidyDoc tdoc = tidyImplToDoc( doc ); + go = go | doc->mssgFilt3( tdoc, level, line, col, tidyErrorCodeAsString(code), args_copy ); + } } if ( go ) diff --git a/src/message.h b/src/message.h index a69d075..55f1b01 100644 --- a/src/message.h +++ b/src/message.h @@ -63,6 +63,10 @@ void TY_(ReportFatal)(TidyDocImpl* doc, Node* element, Node* node, uint code); /** * These tidyErrorCodes are used throughout libtidy, and also * have associated localized strings to describe them. + * + * IMPORTANT: to maintain compatability with TidyMessageFilter3, if you add + * or remove keys from this enum, ALSO add/remove the corresponding key + * in language.c:tidyErrorFilterKeysStruct[]! */ typedef enum { /* This MUST be present and first. */ diff --git a/src/tidy-int.h b/src/tidy-int.h index 51bcf3b..b2f6661 100755 --- a/src/tidy-int.h +++ b/src/tidy-int.h @@ -58,6 +58,7 @@ struct _TidyDocImpl StreamOut* errout; TidyReportFilter mssgFilt; TidyReportFilter2 mssgFilt2; + TidyReportFilter3 mssgFilt3; TidyOptCallback pOptCallback; TidyPPProgress progressCallback; diff --git a/src/tidylib.c b/src/tidylib.c index d8f1350..64bf678 100755 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -672,6 +672,22 @@ Bool TIDY_CALL tidySetReportFilter2( TidyDoc tdoc, TidyReportFilter2 filt return no; } +/* TidyReportFilter3 functions similar to TidyReportFilter, but provides the + * string version of the internal enum name so that LibTidy users can use +** the string as a lookup key for providing their own error localizations. +** See the string definitions in language.h +*/ +Bool TIDY_CALL tidySetReportFilter3( TidyDoc tdoc, TidyReportFilter3 filt ) +{ + TidyDocImpl* impl = tidyDocToImpl( tdoc ); + if ( impl ) + { + impl->mssgFilt3 = filt; + return yes; + } + return no; +} + #if 0 /* Not yet */ int tidySetContentOutputSink( TidyDoc tdoc, TidyOutputSink* outp ) {