Skip to content

Commit 84b3e80

Browse files
committed
change the processing of init files
- add a new "-no-config" command line option to not read any initialization file - refactor init file processing so that only one file is read The search order is: 1. command line "-config xxx" or "-no-config" options 2. environment variable HTML_TIDY=xxx 3. ~/.tidyrc 4. /etc/tidy.conf
1 parent 86b52dc commit 84b3e80

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

console/tidy.c

+47-38
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@ int main( int argc, char** argv )
20752075
ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL;
20762076
TidyDoc tdoc = NULL;
20772077
int status = 0;
2078+
int configSpecified = 0;
20782079

20792080
uint contentErrors = 0;
20802081
uint contentWarnings = 0;
@@ -2104,44 +2105,6 @@ int main( int argc, char** argv )
21042105
SetConsoleOutputCP(CP_UTF8);
21052106
#endif
21062107

2107-
/*
2108-
* Look for default configuration files using any of
2109-
* the following possibilities:
2110-
* - TIDY_CONFIG_FILE - from tidyplatform.h, typically /etc/tidy.conf
2111-
* - HTML_TIDY - environment variable
2112-
* - TIDY_USER_CONFIG_FILE - from tidyplatform.h, typically ~/tidy.conf
2113-
*/
2114-
2115-
#ifdef TIDY_CONFIG_FILE
2116-
if ( tidyFileExists( tdoc, TIDY_CONFIG_FILE) )
2117-
{
2118-
status = tidyLoadConfig( tdoc, TIDY_CONFIG_FILE );
2119-
if ( status != 0 ) {
2120-
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status);
2121-
fprintf(errout, "\n");
2122-
}
2123-
}
2124-
#endif /* TIDY_CONFIG_FILE */
2125-
2126-
if ( (cfgfil = getenv("HTML_TIDY")) != NULL )
2127-
{
2128-
status = tidyLoadConfig( tdoc, cfgfil );
2129-
if ( status != 0 ) {
2130-
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status);
2131-
fprintf(errout, "\n");
2132-
}
2133-
}
2134-
#ifdef TIDY_USER_CONFIG_FILE
2135-
else if ( tidyFileExists( tdoc, TIDY_USER_CONFIG_FILE) )
2136-
{
2137-
status = tidyLoadConfig( tdoc, TIDY_USER_CONFIG_FILE );
2138-
if ( status != 0 ) {
2139-
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status);
2140-
fprintf(errout, "\n");
2141-
}
2142-
}
2143-
#endif /* TIDY_USER_CONFIG_FILE */
2144-
21452108

21462109
/*
21472110
* Read command line
@@ -2332,6 +2295,7 @@ int main( int argc, char** argv )
23322295
{
23332296
ctmbstr post;
23342297

2298+
configSpecified = 1;
23352299
tidyLoadConfig( tdoc, argv[2] );
23362300

23372301
/* Set new error output stream if setting changed */
@@ -2347,6 +2311,11 @@ int main( int argc, char** argv )
23472311
}
23482312
}
23492313

2314+
else if ( strcasecmp(arg, "no-config") == 0 )
2315+
{
2316+
configSpecified = 1;
2317+
}
2318+
23502319
else if ( strcasecmp(arg, "output") == 0 ||
23512320
strcasecmp(arg, "-output-file") == 0 ||
23522321
strcasecmp(arg, "o") == 0 )
@@ -2485,6 +2454,46 @@ int main( int argc, char** argv )
24852454
continue;
24862455
}
24872456

2457+
if ( ! configSpecified )
2458+
{
2459+
/*
2460+
* Configuration file not specified on the command line so
2461+
* look for a configuration file in the order of
2462+
* - HTML_TIDY - environment variable
2463+
* - TIDY_USER_CONFIG_FILE - from tidyplatform.h, default: ~/.tidyrc
2464+
* - TIDY_CONFIG_FILE - from tidyplatform.h, default: /etc/tidy.conf
2465+
*/
2466+
2467+
if ( (cfgfil = getenv("HTML_TIDY")) != NULL )
2468+
{
2469+
status = tidyLoadConfig( tdoc, cfgfil );
2470+
if ( status != 0 ) {
2471+
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status);
2472+
fprintf(errout, "\n");
2473+
}
2474+
}
2475+
#ifdef TIDY_USER_CONFIG_FILE
2476+
else if ( tidyFileExists( tdoc, TIDY_USER_CONFIG_FILE) )
2477+
{
2478+
status = tidyLoadConfig( tdoc, TIDY_USER_CONFIG_FILE );
2479+
if ( status != 0 ) {
2480+
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status);
2481+
fprintf(errout, "\n");
2482+
}
2483+
}
2484+
#endif /* TIDY_USER_CONFIG_FILE */
2485+
#ifdef TIDY_CONFIG_FILE
2486+
else if ( tidyFileExists( tdoc, TIDY_CONFIG_FILE) )
2487+
{
2488+
status = tidyLoadConfig( tdoc, TIDY_CONFIG_FILE );
2489+
if ( status != 0 ) {
2490+
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status);
2491+
fprintf(errout, "\n");
2492+
}
2493+
}
2494+
#endif /* TIDY_CONFIG_FILE */
2495+
} /* endif ( ! configSpecified ) */
2496+
24882497

24892498
if ( argc > 1 )
24902499
{

0 commit comments

Comments
 (0)