OSDN Git Service

Added new option -i (--ignore) to ignore file errors and proceed with next file.
authorLoRd_MuldeR <mulder2@gmx.de>
Sun, 21 Jan 2018 19:18:08 +0000 (20:18 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sun, 21 Jan 2018 19:18:08 +0000 (20:18 +0100)
src/main++.cpp
src/main.c
src/utilities.h

index ee02305..26c2821 100644 (file)
@@ -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("<STDIN>"), 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("<STDIN>"), 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("<STDIN>"), 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("<STDIN>"), 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, &param, &bytes_total, argv[file_id++]))
                        {
                                retval = EXIT_FAILURE;
-                               break;
+                               if (!param.ignore_errors)
+                               {
+                                       break; /*fail!*/
+                               }
                        }
                }
        }
index 6e946fb..38e125d 100644 (file)
@@ -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("<STDIN>"), 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("<STDIN>"), 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("<STDIN>"), 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("<STDIN>"), 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, &param, &bytes_total, argv[file_id++]))
                        {
                                retval = EXIT_FAILURE;
-                               break;
+                               if (!param.ignore_errors)
+                               {
+                                       break; /*fail!*/
+                               }
                        }
                }
        }
index 65e0d3b..a726901 100644 (file)
@@ -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;