From 84b3e80cbb16e356979b1c55b01552924ada75a0 Mon Sep 17 00:00:00 2001 From: ler762 Date: Mon, 10 Sep 2018 17:39:34 -0400 Subject: [PATCH] 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 --- console/tidy.c | 85 ++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index a7880f6f9..505e0a2ff 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -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; @@ -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 @@ -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 */ @@ -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 ) @@ -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 ) {