2
tidy.c - HTML TidyLib command line driver
4
Copyright (c) 1998-2005 World Wide Web Consortium
5
(Massachusetts Institute of Technology, European Research
6
Consortium for Informatics and Mathematics, Keio University).
12
$Date: 2005/04/14 14:51:01 $
18
static FILE* errout = NULL; /* set to stderr */
19
/* static FILE* txtout = NULL; */ /* set to stdout */
21
static Bool samefile( ctmbstr filename1, ctmbstr filename2 )
23
#if FILENAMES_CASE_SENSITIVE
24
return ( strcmp( filename1, filename2 ) == 0 );
26
return ( strcasecmp( filename1, filename2 ) == 0 );
30
static const char *cutToWhiteSpace(const char *s, uint offset, char *sbuf)
37
else if (strlen(s) <= offset)
47
while(j && s[j] != ' ')
63
static void print2Columns( const char* fmt, uint l1, uint l2,
64
const char *c1, const char *c2 )
66
const char *pc1=c1, *pc2=c2;
67
char *c1buf = malloc(l1+1);
68
char *c2buf = malloc(l2+1);
72
pc1 = cutToWhiteSpace(pc1, l1, c1buf);
73
pc2 = cutToWhiteSpace(pc2, l2, c2buf);
75
c1buf[0]!='\0'?c1buf:"",
76
c2buf[0]!='\0'?c2buf:"");
82
static void print3Columns( const char* fmt, uint l1, uint l2, uint l3,
83
const char *c1, const char *c2, const char *c3 )
85
const char *pc1=c1, *pc2=c2, *pc3=c3;
86
char *c1buf = malloc(l1+1);
87
char *c2buf = malloc(l2+1);
88
char *c3buf = malloc(l3+1);
92
pc1 = cutToWhiteSpace(pc1, l1, c1buf);
93
pc2 = cutToWhiteSpace(pc2, l2, c2buf);
94
pc3 = cutToWhiteSpace(pc3, l3, c3buf);
96
c1buf[0]!='\0'?c1buf:"",
97
c2buf[0]!='\0'?c2buf:"",
98
c3buf[0]!='\0'?c3buf:"");
99
} while (pc1 || pc2 || pc3);
105
static const char helpfmt[] = " %-19.19s %-58.58s\n";
106
static const char helpul[]
107
= "-----------------------------------------------------------------";
108
static const char fmt[] = "%-27.27s %-9.9s %-40.40s\n";
109
static const char valfmt[] = "%-27.27s %-9.9s %-1.1s%-39.39s\n";
110
static const char ul[]
111
= "=================================================================";
116
CmdOptCatFIRST = CmdOptFileManip,
123
static const struct {
126
} cmdopt_catname[] = {
127
{ "file-manip", "File manipulation" },
128
{ "process-directives", "Processing directives" },
129
{ "char-encoding", "Character encodings" },
130
{ "misc", "Miscellaneous" }
134
ctmbstr name1; /**< Name */
135
ctmbstr desc; /**< Description */
136
ctmbstr eqconfig; /**< Equivalent configuration option */
137
CmdOptCategory cat; /**< Category */
138
ctmbstr name2; /**< Name */
139
ctmbstr name3; /**< Name */
142
static const CmdOptDesc cmdopt_defs[] = {
144
"write output to the specified <file>",
145
"output-file: <file>", CmdOptFileManip, "-o <file>" },
147
"set configuration options from the specified <file>",
148
NULL, CmdOptFileManip },
150
"write errors to the specified <file>",
151
"error-file: <file>", CmdOptFileManip, "-f <file>" },
153
"modify the original input files",
154
"write-back: yes", CmdOptFileManip, "-m" },
156
"indent element content",
157
"indent: auto", CmdOptProcDir, "-i" },
159
"wrap text at the specified <column> (default is 68)",
160
"wrap: <column>", CmdOptProcDir, "-w <column>" },
162
"force tags to upper case (default is lower case)",
163
"uppercase-tags: yes", CmdOptProcDir, "-u" },
165
"replace FONT, NOBR and CENTER tags by CSS",
166
"clean: yes", CmdOptProcDir, "-c" },
168
"strip out smart quotes and em dashes, etc.",
169
"bare: yes", CmdOptProcDir, "-b" },
171
"output numeric rather than named entities",
172
"numeric-entities: yes", CmdOptProcDir, "-n" },
175
"markup: no", CmdOptProcDir, "-e" },
177
"suppress nonessential output",
178
"quiet: yes", CmdOptProcDir, "-q" },
180
"omit optional end tags",
181
"hide-endtags: yes", CmdOptProcDir },
183
"specify the input is well formed XML",
184
"input-xml: yes", CmdOptProcDir },
186
"convert HTML to well formed XHTML",
187
"output-xhtml: yes", CmdOptProcDir, "-asxhtml" },
189
"force XHTML to well formed HTML",
190
"output-html: yes", CmdOptProcDir },
191
#if SUPPORT_ACCESSIBILITY_CHECKS
193
"do additional accessibility checks (<level> = 1, 2, 3)",
194
"accessibility-check: <level>", CmdOptProcDir },
197
"output values above 127 without conversion to entities",
198
NULL, CmdOptCharEnc },
200
"use ISO-8859-1 for input, US-ASCII for output",
201
NULL, CmdOptCharEnc },
203
"use ISO-8859-15 for input, US-ASCII for output",
204
NULL, CmdOptCharEnc },
206
"use ISO-8859-1 for both input and output",
207
NULL, CmdOptCharEnc },
208
#ifndef NO_NATIVE_ISO2022_SUPPORT
210
"use ISO-2022 for both input and output",
211
NULL, CmdOptCharEnc },
214
"use UTF-8 for both input and output",
215
NULL, CmdOptCharEnc },
217
"use MacRoman for input, US-ASCII for output",
218
NULL, CmdOptCharEnc },
220
"use Windows-1252 for input, US-ASCII for output",
221
NULL, CmdOptCharEnc },
223
"use IBM-858 (CP850+Euro) for input, US-ASCII for output",
224
NULL, CmdOptCharEnc },
225
#if SUPPORT_UTF16_ENCODINGS
227
"use UTF-16LE for both input and output",
228
NULL, CmdOptCharEnc },
230
"use UTF-16BE for both input and output",
231
NULL, CmdOptCharEnc },
233
"use UTF-16 for both input and output",
234
NULL, CmdOptCharEnc },
236
#if SUPPORT_ASIAN_ENCODINGS /* #431953 - RJ */
238
"use Big5 for both input and output",
239
NULL, CmdOptCharEnc },
241
"use Shift_JIS for both input and output",
242
NULL, CmdOptCharEnc },
243
{ "-language <lang>",
244
"set the two-letter language code <lang> (for future use)",
245
"language: <lang>", CmdOptCharEnc },
248
"show the version of Tidy",
249
NULL, CmdOptMisc, "-v" },
251
"list the command line options",
252
NULL, CmdOptMisc, "-h", "-?" },
254
"list the command line options in XML format",
257
"list all configuration options",
260
"list all configuration options in XML format",
263
"list the current configuration settings",
265
{ NULL, NULL, NULL, CmdOptMisc }
268
static tmbstr get_option_names( const CmdOptDesc* pos )
271
uint len = strlen(pos->name1);
273
len += 2+strlen(pos->name2);
275
len += 2+strlen(pos->name3);
277
name = malloc(len+1);
278
strcpy(name, pos->name1);
282
strcat(name, pos->name2);
287
strcat(name, pos->name3);
292
static tmbstr get_escaped_name( ctmbstr name )
298
for(c=name; *c!='\0'; ++c)
313
escpName = malloc(len+1);
317
for(c=name; *c!='\0'; ++c)
321
strcat(escpName, "<");
324
strcat(escpName, ">");
327
strcat(escpName, """);
331
strcat(escpName, aux);
338
static void print_help_option( void )
340
CmdOptCategory cat = CmdOptCatFIRST;
341
const CmdOptDesc* pos = cmdopt_defs;
343
for( cat=CmdOptCatFIRST; cat!=CmdOptCatLAST; ++cat)
345
size_t len = strlen(cmdopt_catname[cat].name);
346
printf("%s\n", cmdopt_catname[cat].name );
347
printf("%*.*s\n", len, len, helpul );
348
for( pos=cmdopt_defs; pos->name1; ++pos)
353
name = get_option_names( pos );
354
print2Columns( helpfmt, 19, 58, name, pos->desc );
361
static void print_xml_help_option_element( ctmbstr element, ctmbstr name )
366
printf(" <%s>%s</%s>\n", element, escpName = get_escaped_name(name),
371
static void print_xml_help_option( void )
373
const CmdOptDesc* pos = cmdopt_defs;
375
for( pos=cmdopt_defs; pos->name1; ++pos)
377
printf(" <option class=\"%s\">\n", cmdopt_catname[pos->cat].mnemonic );
378
print_xml_help_option_element("name", pos->name1);
379
print_xml_help_option_element("name", pos->name2);
380
print_xml_help_option_element("name", pos->name3);
381
print_xml_help_option_element("description", pos->desc);
383
print_xml_help_option_element("eqconfig", pos->eqconfig);
385
printf(" <eqconfig />\n");
386
printf(" </option>\n");
390
static void xml_help( void )
392
printf( "<?xml version=\"1.0\"?>\n"
393
"<cmdline version=\"%s\">\n", tidyReleaseDate());
394
print_xml_help_option();
395
printf( "</cmdline>\n" );
398
static void help( ctmbstr prog )
400
printf( "%s [option...] [file...] [option...] [file...]\n", prog );
401
printf( "Utility to clean up and pretty print HTML/XHTML/XML\n");
402
printf( "see http://tidy.sourceforge.net/\n");
406
printf( "Options for HTML Tidy for %s released on %s:\n",
407
PLATFORM_NAME, tidyReleaseDate() );
409
printf( "Options for HTML Tidy released on %s:\n", tidyReleaseDate() );
415
printf( "Use --blah blarg for any configuration option \"blah\" with argument \"blarg\"\n");
418
printf( "Input/Output default to stdin/stdout respectively\n");
419
printf( "Single letter options apart from -f may be combined\n");
420
printf( "as in: tidy -f errs.txt -imu foo.html\n");
421
printf( "For further info on HTML see http://www.w3.org/MarkUp\n");
425
static Bool isAutoBool( TidyOption topt )
430
if ( tidyOptGetType( topt ) != TidyInteger)
433
pos = tidyOptGetPickList( topt );
436
def = tidyOptGetNextPick( topt, &pos );
437
if (0==strcmp(def,"yes"))
444
ctmbstr ConfigCategoryName( TidyConfigCategory id )
450
case TidyDiagnostics:
451
return "diagnostics";
452
case TidyPrettyPrint:
456
case TidyMiscellaneous:
463
/* Description of an option */
465
ctmbstr name; /**< Name */
466
ctmbstr cat; /**< Category */
467
ctmbstr type; /**< "String, ... */
468
ctmbstr vals; /**< Potential values. If NULL, use an external function */
469
ctmbstr def; /**< default */
470
tmbchar tempdefs[80]; /**< storage for default such as integer */
471
Bool haveVals; /**< if yes, vals is valid */
474
typedef void (*OptionFunc)( TidyDoc, TidyOption, OptionDesc * );
477
/* Create description "d" related to "opt" */
479
void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d )
481
TidyOptionId optId = tidyOptGetId( topt );
482
TidyOptionType optTyp = tidyOptGetType( topt );
484
d->name = tidyOptGetName( topt );
485
d->cat = ConfigCategoryName( tidyOptGetCategory( topt ) );
490
/* Handle special cases first.
494
case TidyDuplicateAttrs:
496
case TidyAccessibilityCheckLevel:
501
"<em>Platform dependent</em>"
502
:tidyOptGetCurrPick( tdoc, optId );
510
sdef = tidyOptGetCurrPick( tdoc, TidyDoctypeMode );
511
if ( !sdef || *sdef == '*' )
512
sdef = tidyOptGetValue( tdoc, TidyDoctype );
521
d->type = "Tag names";
522
d->vals = "tagX, tagY, ...";
526
case TidyCharEncoding:
527
case TidyInCharEncoding:
528
case TidyOutCharEncoding:
529
d->type = "Encoding";
530
d->def = tidyOptGetEncName( tdoc, optId );
536
/* General case will handle remaining */
542
d->vals = "y/n, yes/no, t/f, true/false, 1/0";
543
d->def = tidyOptGetCurrPick( tdoc, optId );
547
if (isAutoBool(topt))
549
d->type = "AutoBool";
550
d->vals = "auto, y/n, yes/no, t/f, true/false, 1/0";
551
d->def = tidyOptGetCurrPick( tdoc, optId );
557
if ( optId == TidyWrapLen )
558
d->vals = "0 (no wrapping), 1, 2, ...";
560
d->vals = "0, 1, 2, ...";
562
idef = tidyOptGetInt( tdoc, optId );
563
sprintf(d->tempdefs, "%u", idef);
564
d->def = d->tempdefs;
572
d->def = tidyOptGetValue( tdoc, optId );
578
/* Array holding all options. Contains a trailing sentinel. */
580
TidyOption topt[N_TIDY_OPTIONS];
584
int cmpOpt(const void* e1_, const void *e2_)
586
const TidyOption* e1 = e1_;
587
const TidyOption* e2 = e2_;
588
return strcmp(tidyOptGetName(*e1), tidyOptGetName(*e2));
592
void getSortedOption( TidyDoc tdoc, AllOption_t *tOption )
594
TidyIterator pos = tidyGetOptionList( tdoc );
599
TidyOption topt = tidyGetNextOption( tdoc, &pos );
600
tOption->topt[i] = topt;
603
tOption->topt[i] = NULL; /* sentinel */
606
/* Do not sort the sentinel: hence `-1' */
607
sizeof(tOption->topt)/sizeof(tOption->topt[0])-1,
608
sizeof(tOption->topt[0]),
612
static void ForEachSortedOption( TidyDoc tdoc, OptionFunc OptionPrint )
615
const TidyOption *topt;
617
getSortedOption( tdoc, &tOption );
618
for( topt = tOption.topt; *topt; ++topt)
622
GetOption( tdoc, *topt, &d );
623
(*OptionPrint)( tdoc, *topt, &d );
627
static void ForEachOption( TidyDoc tdoc, OptionFunc OptionPrint )
629
TidyIterator pos = tidyGetOptionList( tdoc );
633
TidyOption topt = tidyGetNextOption( tdoc, &pos );
636
GetOption( tdoc, topt, &d );
637
(*OptionPrint)( tdoc, topt, &d );
642
void PrintAllowedValuesFromPick( TidyOption topt )
644
TidyIterator pos = tidyOptGetPickList( topt );
653
def = tidyOptGetNextPick( topt, &pos );
659
void PrintAllowedValues( TidyOption topt, const OptionDesc *d )
662
printf( "%s", d->vals );
664
PrintAllowedValuesFromPick( topt );
668
void printXMLDescription( TidyDoc tdoc, TidyOption topt )
670
ctmbstr doc = tidyOptGetDoc( tdoc, topt );
673
printf(" <description>%s</description>\n", doc);
676
printf(" <description />\n");
677
fprintf(stderr, "Warning: option `%s' is not documented.\n",
678
tidyOptGetName( topt ));
683
void printXMLCrossRef( TidyDoc tdoc, TidyOption topt )
685
TidyOption optLinked;
686
TidyIterator pos = tidyOptGetDocLinksList(tdoc, topt);
689
optLinked = tidyOptGetNextDocLinks(tdoc, &pos );
690
printf(" <seealso>%s</seealso>\n",tidyOptGetName(optLinked));
695
void printXMLOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d )
697
if ( tidyOptIsReadOnly(topt) )
700
printf( " <option class=\"%s\">\n", d->cat );
701
printf (" <name>%s</name>\n",d->name);
702
printf (" <type>%s</type>\n",d->type);
704
printf(" <default>%s</default>\n",d->def);
706
printf(" <default />\n");
709
printf(" <example>");
710
PrintAllowedValues( topt, d );
711
printf("</example>\n");
715
printf(" <example />\n");
717
printXMLDescription( tdoc, topt );
718
printXMLCrossRef( tdoc, topt );
719
printf( " </option>\n" );
722
static void XMLoptionhelp( TidyDoc tdoc )
724
printf( "<?xml version=\"1.0\"?>\n"
725
"<config version=\"%s\">\n", tidyReleaseDate());
726
ForEachOption( tdoc, printXMLOption );
727
printf( "</config>\n" );
731
tmbstr GetAllowedValuesFromPick( TidyOption topt )
739
pos = tidyOptGetPickList( topt );
747
def = tidyOptGetNextPick( topt, &pos );
752
pos = tidyOptGetPickList( topt );
760
def = tidyOptGetNextPick( topt, &pos );
767
tmbstr GetAllowedValues( TidyOption topt, const OptionDesc *d )
771
tmbstr val = malloc(1+strlen(d->vals));
772
strcpy(val, d->vals);
776
return GetAllowedValuesFromPick( topt );
780
void printOption( TidyDoc ARG_UNUSED(tdoc), TidyOption topt,
783
if ( tidyOptIsReadOnly(topt) )
786
if ( *d->name || *d->type )
788
ctmbstr pval = d->vals;
794
else if (pval == NULL)
796
val = GetAllowedValues( topt, d);
799
print3Columns( fmt, 27, 9, 40, d->name, d->type, pval );
805
static void optionhelp( TidyDoc tdoc )
807
printf( "\nHTML Tidy Configuration Settings\n\n" );
808
printf( "Within a file, use the form:\n\n" );
809
printf( "wrap: 72\n" );
810
printf( "indent: no\n\n" );
811
printf( "When specified on the command line, use the form:\n\n" );
812
printf( "--wrap 72 --indent no\n\n");
814
printf( fmt, "Name", "Type", "Allowable values" );
815
printf( fmt, ul, ul, ul );
817
ForEachSortedOption( tdoc, printOption );
821
void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt,
824
TidyOptionId optId = tidyOptGetId( topt );
825
ctmbstr ro = tidyOptIsReadOnly( topt ) ? "*" : "" ;
834
TidyIterator pos = tidyOptGetDeclTagList( tdoc );
837
d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos);
841
printf( valfmt, d->name, d->type, ro, d->def );
843
printf( fmt, d->name, d->type, d->def );
851
d->def = tidyOptGetCurrPick( tdoc, optId );
855
/* fix for http://tidy.sf.net/bug/873921 */
856
if ( *d->name || *d->type || (d->def && *d->def) )
861
printf( valfmt, d->name, d->type, ro, d->def );
863
printf( fmt, d->name, d->type, d->def );
867
static void optionvalues( TidyDoc tdoc )
869
printf( "\nConfiguration File Settings:\n\n" );
870
printf( fmt, "Name", "Type", "Current Value" );
871
printf( fmt, ul, ul, ul );
873
ForEachSortedOption( tdoc, printOptionValues );
875
printf( "\n\nValues marked with an *asterisk are calculated \n"
876
"internally by HTML Tidy\n\n" );
879
static void version( void )
882
printf( "HTML Tidy for %s released on %s\n",
883
PLATFORM_NAME, tidyReleaseDate() );
885
printf( "HTML Tidy released on %s\n", tidyReleaseDate() );
889
static void unknownOption( uint c )
891
fprintf( errout, "HTML Tidy: unknown option: %c\n", (char)c );
894
int main( int argc, char** argv )
896
ctmbstr prog = argv[0];
897
ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL;
898
TidyDoc tdoc = tidyCreate();
901
uint contentErrors = 0;
902
uint contentWarnings = 0;
903
uint accessWarnings = 0;
905
errout = stderr; /* initialize to stderr */
909
if ( tidyFileExists(CONFIG_FILE) )
911
status = tidyLoadConfig( tdoc, CONFIG_FILE );
913
fprintf(errout, "Loading config file \"%s\" failed, err = %d\n", CONFIG_FILE, status);
915
#endif /* CONFIG_FILE */
917
/* look for env var "HTML_TIDY" */
918
/* then for ~/.tidyrc (on platforms defining $HOME) */
920
if ( cfgfil = getenv("HTML_TIDY") )
922
status = tidyLoadConfig( tdoc, cfgfil );
924
fprintf(errout, "Loading config file \"%s\" failed, err = %d\n", cfgfil, status);
926
#ifdef USER_CONFIG_FILE
927
else if ( tidyFileExists(USER_CONFIG_FILE) )
929
status = tidyLoadConfig( tdoc, USER_CONFIG_FILE );
931
fprintf(errout, "Loading config file \"%s\" failed, err = %d\n", USER_CONFIG_FILE, status);
933
#endif /* USER_CONFIG_FILE */
935
/* read command line */
938
if (argc > 1 && argv[1][0] == '-')
940
/* support -foo and --foo */
941
ctmbstr arg = argv[1] + 1;
943
if ( strcasecmp(arg, "xml") == 0)
944
tidyOptSetBool( tdoc, TidyXmlTags, yes );
946
else if ( strcasecmp(arg, "asxml") == 0 ||
947
strcasecmp(arg, "asxhtml") == 0 )
949
tidyOptSetBool( tdoc, TidyXhtmlOut, yes );
951
else if ( strcasecmp(arg, "ashtml") == 0 )
952
tidyOptSetBool( tdoc, TidyHtmlOut, yes );
954
else if ( strcasecmp(arg, "indent") == 0 )
956
tidyOptSetInt( tdoc, TidyIndentContent, TidyAutoState );
957
if ( tidyOptGetInt(tdoc, TidyIndentSpaces) == 0 )
958
tidyOptResetToDefault( tdoc, TidyIndentSpaces );
960
else if ( strcasecmp(arg, "omit") == 0 )
961
tidyOptSetBool( tdoc, TidyHideEndTags, yes );
963
else if ( strcasecmp(arg, "upper") == 0 )
964
tidyOptSetBool( tdoc, TidyUpperCaseTags, yes );
966
else if ( strcasecmp(arg, "clean") == 0 )
967
tidyOptSetBool( tdoc, TidyMakeClean, yes );
969
else if ( strcasecmp(arg, "bare") == 0 )
970
tidyOptSetBool( tdoc, TidyMakeBare, yes );
972
else if ( strcasecmp(arg, "raw") == 0 ||
973
strcasecmp(arg, "ascii") == 0 ||
974
strcasecmp(arg, "latin0") == 0 ||
975
strcasecmp(arg, "latin1") == 0 ||
976
strcasecmp(arg, "utf8") == 0 ||
977
#ifndef NO_NATIVE_ISO2022_SUPPORT
978
strcasecmp(arg, "iso2022") == 0 ||
980
#if SUPPORT_UTF16_ENCODINGS
981
strcasecmp(arg, "utf16le") == 0 ||
982
strcasecmp(arg, "utf16be") == 0 ||
983
strcasecmp(arg, "utf16") == 0 ||
985
#if SUPPORT_ASIAN_ENCODINGS
986
strcasecmp(arg, "shiftjis") == 0 ||
987
strcasecmp(arg, "big5") == 0 ||
989
strcasecmp(arg, "mac") == 0 ||
990
strcasecmp(arg, "win1252") == 0 ||
991
strcasecmp(arg, "ibm858") == 0 )
993
tidySetCharEncoding( tdoc, arg );
995
else if ( strcasecmp(arg, "numeric") == 0 )
996
tidyOptSetBool( tdoc, TidyNumEntities, yes );
998
else if ( strcasecmp(arg, "modify") == 0 ||
999
strcasecmp(arg, "change") == 0 || /* obsolete */
1000
strcasecmp(arg, "update") == 0 ) /* obsolete */
1002
tidyOptSetBool( tdoc, TidyWriteBack, yes );
1004
else if ( strcasecmp(arg, "errors") == 0 )
1005
tidyOptSetBool( tdoc, TidyShowMarkup, no );
1007
else if ( strcasecmp(arg, "quiet") == 0 )
1008
tidyOptSetBool( tdoc, TidyQuiet, yes );
1010
else if ( strcasecmp(arg, "help") == 0 ||
1011
strcasecmp(arg, "h") == 0 || *arg == '?' )
1014
tidyRelease( tdoc );
1015
return 0; /* success */
1017
else if ( strcasecmp(arg, "xml-help") == 0)
1020
tidyRelease( tdoc );
1021
return 0; /* success */
1023
else if ( strcasecmp(arg, "help-config") == 0 )
1026
tidyRelease( tdoc );
1027
return 0; /* success */
1029
else if ( strcasecmp(arg, "xml-config") == 0 )
1031
XMLoptionhelp( tdoc );
1032
tidyRelease( tdoc );
1033
return 0; /* success */
1035
else if ( strcasecmp(arg, "show-config") == 0 )
1037
optionvalues( tdoc );
1038
tidyRelease( tdoc );
1039
return 0; /* success */
1041
else if ( strcasecmp(arg, "config") == 0 )
1047
tidyLoadConfig( tdoc, argv[2] );
1049
/* Set new error output stream if setting changed */
1050
post = tidyOptGetValue( tdoc, TidyErrFile );
1051
if ( post && (!errfil || !samefile(errfil, post)) )
1054
errout = tidySetErrorFile( tdoc, post );
1062
#if SUPPORT_ASIAN_ENCODINGS
1063
else if ( strcasecmp(arg, "language") == 0 ||
1064
strcasecmp(arg, "lang") == 0 )
1068
tidyOptSetValue( tdoc, TidyLanguage, argv[2] );
1075
else if ( strcasecmp(arg, "output") == 0 ||
1076
strcasecmp(arg, "-output-file") == 0 ||
1077
strcasecmp(arg, "o") == 0 )
1081
tidyOptSetValue( tdoc, TidyOutFile, argv[2] );
1086
else if ( strcasecmp(arg, "file") == 0 ||
1087
strcasecmp(arg, "-file") == 0 ||
1088
strcasecmp(arg, "f") == 0 )
1093
errout = tidySetErrorFile( tdoc, errfil );
1098
else if ( strcasecmp(arg, "wrap") == 0 ||
1099
strcasecmp(arg, "-wrap") == 0 ||
1100
strcasecmp(arg, "w") == 0 )
1105
sscanf( argv[2], "%u", &wraplen );
1106
tidyOptSetInt( tdoc, TidyWrapLen, wraplen );
1111
else if ( strcasecmp(arg, "version") == 0 ||
1112
strcasecmp(arg, "-version") == 0 ||
1113
strcasecmp(arg, "v") == 0 )
1116
tidyRelease( tdoc );
1117
return 0; /* success */
1120
else if ( strncmp(argv[1], "--", 2 ) == 0)
1122
if ( tidyOptParseValue(tdoc, argv[1]+2, argv[2]) )
1124
/* Set new error output stream if setting changed */
1125
ctmbstr post = tidyOptGetValue( tdoc, TidyErrFile );
1126
if ( post && (!errfil || !samefile(errfil, post)) )
1129
errout = tidySetErrorFile( tdoc, post );
1137
#if SUPPORT_ACCESSIBILITY_CHECKS
1138
else if ( strcasecmp(arg, "access") == 0 )
1143
sscanf( argv[2], "%u", &acclvl );
1144
tidyOptSetInt( tdoc, TidyAccessibilityCheckLevel, acclvl );
1154
ctmbstr s = argv[1];
1161
tidyOptSetInt( tdoc, TidyIndentContent, TidyAutoState );
1162
if ( tidyOptGetInt(tdoc, TidyIndentSpaces) == 0 )
1163
tidyOptResetToDefault( tdoc, TidyIndentSpaces );
1166
/* Usurp -o for output file. Anyone hiding end tags?
1168
tidyOptSetBool( tdoc, TidyHideEndTags, yes );
1173
tidyOptSetBool( tdoc, TidyUpperCaseTags, yes );
1177
tidyOptSetBool( tdoc, TidyMakeClean, yes );
1181
tidyOptSetBool( tdoc, TidyMakeBare, yes );
1185
tidyOptSetBool( tdoc, TidyNumEntities, yes );
1189
tidyOptSetBool( tdoc, TidyWriteBack, yes );
1193
tidyOptSetBool( tdoc, TidyShowMarkup, no );
1197
tidyOptSetBool( tdoc, TidyQuiet, yes );
1215
if ( tidyOptGetBool(tdoc, TidyEmacs) )
1216
tidyOptSetValue( tdoc, TidyEmacsFile, htmlfil );
1217
status = tidyParseFile( tdoc, htmlfil );
1222
status = tidyParseStdin( tdoc );
1226
status = tidyCleanAndRepair( tdoc );
1229
status = tidyRunDiagnostics( tdoc );
1231
if ( status > 1 ) /* If errors, do we want to force output? */
1232
status = ( tidyOptGetBool(tdoc, TidyForceOutput) ? status : -1 );
1234
if ( status >= 0 && tidyOptGetBool(tdoc, TidyShowMarkup) )
1236
if ( tidyOptGetBool(tdoc, TidyWriteBack) && argc > 1 )
1237
status = tidySaveFile( tdoc, htmlfil );
1240
ctmbstr outfil = tidyOptGetValue( tdoc, TidyOutFile );
1242
status = tidySaveFile( tdoc, outfil );
1244
status = tidySaveStdout( tdoc );
1248
contentErrors += tidyErrorCount( tdoc );
1249
contentWarnings += tidyWarningCount( tdoc );
1250
accessWarnings += tidyAccessWarningCount( tdoc );
1259
if (!tidyOptGetBool(tdoc, TidyQuiet) &&
1260
errout == stderr && !contentErrors)
1261
fprintf(errout, "\n");
1263
if (contentErrors + contentWarnings > 0 &&
1264
!tidyOptGetBool(tdoc, TidyQuiet))
1265
tidyErrorSummary(tdoc);
1267
if (!tidyOptGetBool(tdoc, TidyQuiet))
1268
tidyGeneralInfo(tdoc);
1270
/* called to free hash tables etc. */
1271
tidyRelease( tdoc );
1273
/* return status can be used by scripts */
1274
if ( contentErrors > 0 )
1277
if ( contentWarnings > 0 )
1280
/* 0 signifies all is ok */
1287
* indent-tabs-mode: nil
1289
* eval: (c-set-offset 'substatement-open 0)