From 9edbb0a0558f08ed27d5e85e9eb81997dc9527b2 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Wed, 3 Mar 2021 19:02:54 +0100 Subject: [PATCH 1/4] Is. #921 - Implement error exit -1 --- console/tidy.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/console/tidy.c b/console/tidy.c index 3a3d9ad8e..f5eb22ad0 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -49,6 +49,8 @@ static FILE* errout = NULL; ** @{ */ +/** Fatal error count - like bad option, no files, etc - Exit -1 */ +static uint errorCount = 0; /* Is. #921 */ /* MARK: - Miscellaneous Utilities */ /***************************************************************************//** @@ -2123,6 +2125,7 @@ int main( int argc, char** argv ) if ( status != 0 ) { fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status); fprintf(errout, "\n"); + errorCount++; /* Is. #921 - config file failed */ } } #endif /* TIDY_CONFIG_FILE */ @@ -2133,6 +2136,7 @@ int main( int argc, char** argv ) if ( status != 0 ) { fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status); fprintf(errout, "\n"); + errorCount++; /* Is. #921 - config file failed */ } } #ifdef TIDY_USER_CONFIG_FILE @@ -2142,6 +2146,7 @@ int main( int argc, char** argv ) if ( status != 0 ) { fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status); fprintf(errout, "\n"); + errorCount++; /* Is. #921 - config file failed */ } } #endif /* TIDY_USER_CONFIG_FILE */ @@ -2479,6 +2484,7 @@ int main( int argc, char** argv ) default: unknownOption( tdoc, c ); + errorCount++; /* Is. #921 - option error */ break; } } @@ -2506,6 +2512,8 @@ int main( int argc, char** argv ) if ( tidyOptGetBool(tdoc, TidyEmacs) || tidyOptGetBool(tdoc, TidyShowFilename)) tidySetEmacsFile( tdoc, htmlfil ); status = tidyParseFile( tdoc, htmlfil ); + if (status < 0) /* Is. #921 - input file failed */ + errorCount++; } else { @@ -2547,6 +2555,7 @@ int main( int argc, char** argv ) contentErrors += tidyErrorCount( tdoc ); contentWarnings += tidyWarningCount( tdoc ); accessWarnings += tidyAccessWarningCount( tdoc ); + errorCount += tidyConfigErrorCount( tdoc); /* Is. #921 - config error are fatal */ --argc; ++argv; @@ -2568,8 +2577,16 @@ int main( int argc, char** argv ) /* called to free hash tables etc. */ tidyRelease( tdoc ); - + /* return status can be used by scripts */ + + /* Is. #921 - one, or more fatal errors */ + /* this can be many forms, from file does not exit, to an unknown option, + * or malformed option, etc ... + */ + if (errorCount > 0) + return -1; /* Is. #921 */ + if ( contentErrors > 0 ) return 2; From 2a22b409bee71f404eb7b16af4730a214a6bce43 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Wed, 3 Mar 2021 19:03:49 +0100 Subject: [PATCH 2/4] Is. #921 - Remove duplicate message output --- src/config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index bae56b8ff..3dd22a001 100644 --- a/src/config.c +++ b/src/config.c @@ -1581,7 +1581,10 @@ Bool ParsePickList( TidyDocImpl* doc, const TidyOptionImpl* entry ) return yes; } - TY_(ReportBadArgument)( doc, entry->name ); + /* Is. #921 - this service calls 'GetParsePickListValue', which already emits + * 'ReportBadArgument' if it fails, so eliminate this duplicate call + * TY_(ReportBadArgument)( doc, entry->name ); + */ return no; } From da781953c537ed4f9f49ac390f58079cb933c94c Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Wed, 3 Mar 2021 19:04:55 +0100 Subject: [PATCH 3/4] Is. #921 - Allow 'TidyConfig' msgs, even if quiet --- src/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/message.c b/src/message.c index ee2e6c6f3..aa7f3e8ed 100644 --- a/src/message.c +++ b/src/message.c @@ -169,7 +169,7 @@ static void messageOut( TidyMessageImpl *message ) go = go && message->code != STRING_CONTENT_LOOKS; go = go && message->code != STRING_NO_SYSID; go = go && message->level != TidyDialogueInfo; - go = go && message->level != TidyConfig; + /* go = go && message->level != TidyConfig; Is. #921 - these are errors, not informational! */ go = go && message->level != TidyInfo; go = go && !(message->level >= TidyDialogueSummary && message->code != STRING_NEEDS_INTERVENTION); From b49be817b67c017e2fc4577a766b33f9d990dec3 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Wed, 30 Jun 2021 11:55:08 -0400 Subject: [PATCH 4/4] You can't have negative exit codes. Values 0 through 255 are valid. --- console/tidy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/tidy.c b/console/tidy.c index f5eb22ad0..45d514395 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -2585,7 +2585,7 @@ int main( int argc, char** argv ) * or malformed option, etc ... */ if (errorCount > 0) - return -1; /* Is. #921 */ + return 3; /* Is. #921 */ if ( contentErrors > 0 ) return 2;