OSDN Git Service

Some improvements for ignore errors mode + README updates.
authorLoRd_MuldeR <mulder2@gmx.de>
Mon, 22 Jan 2018 20:58:42 +0000 (21:58 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Mon, 22 Jan 2018 20:58:42 +0000 (21:58 +0100)
README.md
src/main++.cpp
src/main.c

index 31d0ac2..4e0edc4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -97,10 +97,14 @@ MHash-384 supports the following options:
   *Note:* This is incompatible with the `-u` (`--upper`) and `-c` (`--curly`) options!
 
 * **`-b`**, **`--bench`**  
-  Compute performance statistics (e.g. bytes processed per second) and print them to the *stderr* at the end of the process.
+  Compute performance statistics (bytes processed per second) and print them to the *stderr* at the end of the process.
+
+* **`-i`**, **`--ignore`**  
+  Ignore errors. Proceeds with the *next* file when an error is encountered. Default behavior stops immediately on errors.
+  *Note:* This option only has a noteworthy effect, if *multiple* input files have been given!
 
 * **`-v`**, **`--version`**  
-  Print library version to the *stdout* and exit program.
+  Print library version to the *stdout* and exit program. Format is: `mhash-384 version X.Y.Z (built MMM DD YYYY)`
 
 * **`-t`**, **`--test`**  
   Run *built-in self-test* and exit program. Computes hashes from test vectors and compares results to reference hashes.
@@ -108,17 +112,39 @@ MHash-384 supports the following options:
 * **`-h`**, **`--help`**  
   Print help screen (man page) and exit program.
 
+## Output Format
+
+On completion, the computed digest (hash value) will be written to the standard output (*stdout*).
+
+The digest will be printed in lower-case hexadecimal notation, by default. Options `-u` and `-c` can influence the format.
+
+If *multiple* files have been given, the hash value of each files is printed in a separate line, followed by the file name.
+
+With the `-r` option specified, hash values will be written to standard output (*stdout*) as "raw" bytes &ndash; 48 bytes per hash.
+
+## Exit Code
+
+On success, *zero* is returned. On error or user interruption, a *non-zero* error code is returned.
+
 ## Examples
 
-Compute MHash-384 hash of a local file:
+Compute MHash-384 hash of a single local file:
+
+       mhash_384 "C:\Images\debian-8.3.0-amd64-DVD-1.iso"
+
+Compute MHash-384 hash of *two* files:
+
+       mhash_384 "C:\Images\debian-8.3.0-amd64-DVD-1.iso" "C:\Images\debian-8.3.0-i386-DVD-1.iso"
+
+Compute MHash-384 hash of *multiple* files, using wildcard expansion ([globbing](https://en.wikipedia.org/wiki/Glob_(programming))):
 
-       mhash_384 C:\Images\debian-8.3.0-amd64-DVD-1.iso"
+       mhash_384 "C:\Images\*.iso"
 
-Compute MHash-384 hash of a local file, with more verbose status outputs:
+Compute MHash-384 hash of a file, with more verbose status outputs:
 
-       mhash_384 -p -b C:\Images\debian-8.3.0-amd64-DVD-1.iso"
+       mhash_384 -p -b "C:\Images\debian-8.3.0-amd64-DVD-1.iso"
 
-Compute MHash-384 from random bytes, passing data directly from [`dd`](https://en.wikipedia.org/wiki/Dd_%28Unix%29) via pipe:
+Compute MHash-384 from random bytes, passing data directly from [**`dd`**](https://en.wikipedia.org/wiki/Dd_%28Unix%29) via [pipeline](https://en.wikipedia.org/wiki/Pipeline_(Unix)):
 
        dd if=/dev/urandom bs=100 count=1 | mhash_384
 
index 7e12a1d..4c2daf1 100644 (file)
@@ -35,6 +35,9 @@
 /*Constants*/
 #define BUFF_SIZE 4096
 
+/*Utils*/
+#define SHOW_ERRORS(X) (!((X)->ignore_errors && multi_file))
+
 static int process_file(const int multi_file, const param_t *const param, uint64_t *const bytes_total, CHAR *const file_name)
 {
        FILE *source;
@@ -46,7 +49,7 @@ 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)))
        {
-               if (!param->ignore_errors)
+               if (SHOW_ERRORS(param))
                {
                        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));
@@ -61,7 +64,7 @@ static int process_file(const int multi_file, const param_t *const param, uint64
        /*open source file*/
        if (!(source = file_name ? FOPEN(file_name, T("rb")) : stdin))
        {
-               if (!param->ignore_errors)
+               if (SHOW_ERRORS(param))
                {
                        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));
@@ -105,10 +108,10 @@ static int process_file(const int multi_file, const param_t *const param, uint64
        /*check file error status*/
        if ((!g_interrupted) && ferror(source))
        {
-               if (!param->ignore_errors)
+               if (SHOW_ERRORS(param))
                {
                        print_logo();
-                       FPUTS(T("File read error has occurred!\n"), stderr);
+                       FPUTS(T("File read error has occurred, aborting!\n"), stderr);
                }
                else
                {
index 1bc49b5..8680e2c 100644 (file)
@@ -35,6 +35,9 @@
 /*Constants*/
 #define BUFF_SIZE 4096
 
+/*Utils*/
+#define SHOW_ERRORS(X) (!((X)->ignore_errors && multi_file))
+
 static int process_file(const int multi_file, const param_t *const param, uint64_t *const bytes_total, CHAR *const file_name)
 {
        FILE *source;
@@ -47,7 +50,7 @@ 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)))
        {
-               if (!param->ignore_errors)
+               if (SHOW_ERRORS(param))
                {
                        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));
@@ -62,7 +65,7 @@ static int process_file(const int multi_file, const param_t *const param, uint64
        /*open source file*/
        if (!(source = file_name ? FOPEN(file_name, T("rb")) : stdin))
        {
-               if (!param->ignore_errors)
+               if (SHOW_ERRORS(param))
                {
                        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));
@@ -106,7 +109,7 @@ static int process_file(const int multi_file, const param_t *const param, uint64
        /*check file error status*/
        if ((!g_interrupted) && ferror(source))
        {
-               if (!param->ignore_errors)
+               if (SHOW_ERRORS(param))
                {
                        print_logo();
                        FPUTS(T("File read error has occurred, aborting!\n"), stderr);