From: LoRd_MuldeR Date: Sun, 21 Jan 2018 19:18:08 +0000 (+0100) Subject: Added new option -i (--ignore) to ignore file errors and proceed with next file. X-Git-Tag: 1.2.1~11 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=66038891d4f2d775d13ecb9ef3c56b62a3825187;p=mhash384%2Fmhash384.git Added new option -i (--ignore) to ignore file errors and proceed with next file. --- diff --git a/src/main++.cpp b/src/main++.cpp index ee02305..26c2821 100644 --- a/src/main++.cpp +++ b/src/main++.cpp @@ -46,16 +46,22 @@ static int process_file(const int multi_file, const param_t *const param, uint64 /*check if file is accessible*/ if (file_name && (!is_file_readable(file_name))) { - print_logo(); - FPRINTF(stderr, T("Given input file is not readable:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + if (!param->ignore_errors) + { + print_logo(); + FPRINTF(stderr, T("Given input file is not readable:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + } return 0; } /*open source file*/ if (!(source = file_name ? FOPEN(file_name, T("rb")) : stdin)) { - print_logo(); - FPRINTF(stderr, T("Failed to open input file:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + if (!param->ignore_errors) + { + print_logo(); + FPRINTF(stderr, T("Failed to open input file:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + } return 0; } @@ -90,8 +96,11 @@ static int process_file(const int multi_file, const param_t *const param, uint64 /*check file error status*/ if ((!g_interrupted) && ferror(source)) { - print_logo(); - FPUTS(T("File read error has occurred!\n"), stderr); + if (!param->ignore_errors) + { + print_logo(); + FPUTS(T("File read error has occurred!\n"), stderr); + } fclose(source); return 0; } @@ -212,7 +221,10 @@ int MAIN(int argc, CHAR *argv[]) if (!process_file(multi_file, ¶m, &bytes_total, argv[file_id++])) { retval = EXIT_FAILURE; - break; + if (!param.ignore_errors) + { + break; /*fail!*/ + } } } } diff --git a/src/main.c b/src/main.c index 6e946fb..38e125d 100644 --- a/src/main.c +++ b/src/main.c @@ -47,16 +47,22 @@ static int process_file(const int multi_file, const param_t *const param, uint64 /*check if file is accessible*/ if (file_name && (!is_file_readable(file_name))) { - print_logo(); - FPRINTF(stderr, T("Given input file is not readable:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + if (!param->ignore_errors) + { + print_logo(); + FPRINTF(stderr, T("Given input file is not readable:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + } return 0; } /*open source file*/ if (!(source = file_name ? FOPEN(file_name, T("rb")) : stdin)) { - print_logo(); - FPRINTF(stderr, T("Failed to open input file:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + if (!param->ignore_errors) + { + print_logo(); + FPRINTF(stderr, T("Failed to open input file:\n%s\n\n%s\n\n"), file_name ? file_name : T(""), STRERROR(errno)); + } return 0; } @@ -91,8 +97,11 @@ static int process_file(const int multi_file, const param_t *const param, uint64 /*check file error status*/ if ((!g_interrupted) && ferror(source)) { - print_logo(); - FPUTS(T("File read error has occurred!\n"), stderr); + if (!param->ignore_errors) + { + print_logo(); + FPUTS(T("File read error has occurred!\n"), stderr); + } fclose(source); return 0; } @@ -213,7 +222,10 @@ int MAIN(int argc, CHAR *argv[]) if (!process_file(multi_file, ¶m, &bytes_total, argv[file_id++])) { retval = EXIT_FAILURE; - break; + if (!param.ignore_errors) + { + break; /*fail!*/ + } } } } diff --git a/src/utilities.h b/src/utilities.h index 65e0d3b..a726901 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -66,6 +66,7 @@ typedef struct param_t int use_upper_case; int curly_brackets; int raw_output; + int ignore_errors; } param_t; @@ -127,6 +128,7 @@ static void print_help(void) FPUTS(T(" -c, --curly print digest using C-style curly brackets\n"), stderr); FPUTS(T(" -r, --raw output \"raw\" bytes (no \"hex\" encoding)\n"), stderr); FPUTS(T(" -b, --bench compute and print throughput\n"), stderr); + FPUTS(T(" -i, --ignore ignore errors and proceed with ntext file\n"), stderr); FPUTS(T(" -v, --version print the version string and exit\n"), stderr); FPUTS(T(" -t, --test execute self-test and exit\n"), stderr); FPUTS(T(" -h, --help print this help screen and exit\n\n"), stderr); @@ -145,6 +147,11 @@ static int parse_option(param_t *param, const CHAR *const argv, const int is_lon param->enable_bench = 1; return 1; } + if (IS_OPTION(argv, is_long, T('i'), T("ignore"))) + { + param->ignore_errors = 1; + return 1; + } if (IS_OPTION(argv, is_long, T('p'), T("progress"))) { param->show_progress = 1;