Skip to content

change the processing of init files #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 47 additions & 38 deletions console/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ int main( int argc, char** argv )
ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL;
TidyDoc tdoc = NULL;
int status = 0;
int configSpecified = 0;

uint contentErrors = 0;
uint contentWarnings = 0;
Expand Down Expand Up @@ -2104,44 +2105,6 @@ int main( int argc, char** argv )
SetConsoleOutputCP(CP_UTF8);
#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
*/

#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");
}
}
#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");
}
}
#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");
}
}
#endif /* TIDY_USER_CONFIG_FILE */


/*
* Read command line
Expand Down Expand Up @@ -2332,6 +2295,7 @@ int main( int argc, char** argv )
{
ctmbstr post;

configSpecified = 1;
tidyLoadConfig( tdoc, argv[2] );

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

else if ( strcasecmp(arg, "no-config") == 0 )
{
configSpecified = 1;
}

else if ( strcasecmp(arg, "output") == 0 ||
strcasecmp(arg, "-output-file") == 0 ||
strcasecmp(arg, "o") == 0 )
Expand Down Expand Up @@ -2485,6 +2454,46 @@ int main( int argc, char** argv )
continue;
}

if ( ! configSpecified )
{
/*
* Configuration file not specified on the command line so
* look for a configuration file in the order of
* - HTML_TIDY - environment variable
* - TIDY_USER_CONFIG_FILE - from tidyplatform.h, default: ~/.tidyrc
* - TIDY_CONFIG_FILE - from tidyplatform.h, default: /etc/tidy.conf
*/

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");
}
}
#endif /* TIDY_USER_CONFIG_FILE */
#ifdef TIDY_CONFIG_FILE
else 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 */
} /* endif ( ! configSpecified ) */


if ( argc > 1 )
{
Expand Down