meowsum.git

commit 02344d55a1dd07b66f33e1f30dfa743278c68369

Author: Adam <git@apiote.tk>

add help to options

 meowsum.1.scd | 7 +++++--
 meowsum.c | 17 +++++++++++------


diff --git a/meowsum.1.scd b/meowsum.1.scd
index 812747ae9a988b2ea90ba2e4217d7cc4c5bfd464..8512c03cc13ef3a1eb9590f66ad79e7cae7abf74 100644
--- a/meowsum.1.scd
+++ b/meowsum.1.scd
@@ -6,9 +6,11 @@ meowsum — print or check Meow hash checksums
 
 # SYNOPSIS
 
-meowsum [-ceq] [FILE]...
+meowsum -h
 
-meowsum [-s size] [FILE]...
+meowsum [-ceq] FILE...
+
+meowsum [-s size] FILE...
 
 # DESCRIPTION
 
@@ -20,6 +22,7 @@ When FILE is -, meowsum reads standard input.
 
 # OPTIONS
 
+\-h           show this help and exit++
 \-c           read sums from the FILEs and check them++
 \-s size      set hash size; size can be 32, 64, 128 bits;++
 	        the default is 128




diff --git a/meowsum.c b/meowsum.c
index 7be65dfe3a1e68ae6810d0b5df5809109b24d28a..3c69bd7477be179a16b1e7d8178dc25532f1caaf 100644
--- a/meowsum.c
+++ b/meowsum.c
@@ -24,6 +24,7 @@   printf("Print or check Meow hash checksums.\n");
   printf("\n");
   printf("When FILE is -, read standard input.\n");
   printf("\n");
+  printf("  -h           show this help and exit\n");
   printf("  -c           read sums from the FILEs and check them\n");
   printf("  -s size      set hash size; size can be 32, 64, 128 bits;\n");
   printf("               the default is 128\n");
@@ -34,7 +35,7 @@   printf("  -e           fail for missing files\n");
 }
 
 void parse_args(int argc, char *argv[], bool *quiet, bool *strict_error,
-                int *hash_size, int *first_file_index, int *mode) {
+                int *hash_size, int *first_file_index, int *mode, bool *help) {
   bool expecting_num = false;
 
   for (int i = 1; i < argc; ++i) {
@@ -71,6 +72,10 @@           *strict_error = true;
           break;
         case 's':
           expecting_num = true;
+          break;
+        case 'h':
+          *help = true;
+          break;
         }
       }
     }
@@ -379,15 +384,15 @@     return 1;
   }
 
   parse_args(argc, argv, &quiet, &strict_error, &hash_size, &first_file_index,
-             &mode);
+             &mode, &help);
 
-  if (hash_size != 32 && hash_size != 64 && hash_size != 128) {
-    fprintf(stderr, "unknown hash size %d\n", hash_size);
+  if (first_file_index == -1 || help) {
+    print_usage();
     return 1;
   }
 
-  if (first_file_index == -1) {
-    print_usage();
+  if (hash_size != 32 && hash_size != 64 && hash_size != 128) {
+    fprintf(stderr, "unknown hash size %d\n", hash_size);
     return 1;
   }