David Rose 22 vuotta sitten
vanhempi
sitoutus
7e14f2577d
1 muutettua tiedostoa jossa 15 lisäystä ja 7 poistoa
  1. 15 7
      panda/src/downloadertools/check_md5.cxx

+ 15 - 7
panda/src/downloadertools/check_md5.cxx

@@ -32,7 +32,7 @@ usage() {
   cerr << 
   cerr << 
     "\n"
     "\n"
     "Usage:\n\n"
     "Usage:\n\n"
-    "check_md5 [-d] [-i \"input string\"] [file1 file2 ...]\n"
+    "check_md5 [-q] [-d] [-i \"input string\"] [file1 file2 ...]\n"
     "check_md5 -h\n\n";
     "check_md5 -h\n\n";
 }
 }
 
 
@@ -45,12 +45,14 @@ help() {
 
 
     "An MD5 hash is a 128-bit value.  The output is presented as a 32-digit\n"
     "An MD5 hash is a 128-bit value.  The output is presented as a 32-digit\n"
     "hexadecimal string by default, but with -d, it is presented as four\n"
     "hexadecimal string by default, but with -d, it is presented as four\n"
-    "big-endian unsigned 32-bit decimal integers.\n\n";
+    "big-endian unsigned 32-bit decimal integers.  Normally the filename\n"
+    "of each file is printed along with the hash; -q suppresses this.\n\n";
 }
 }
 
 
 void
 void
-output_hash(const string &filename, const HashVal &hash, bool output_decimal) {
-  if (!filename.empty()) {
+output_hash(const string &filename, const HashVal &hash, 
+            bool output_decimal, bool suppress_filename) {
+  if (!suppress_filename && !filename.empty()) {
     cout << filename << " ";
     cout << filename << " ";
   }
   }
   if (output_decimal) {
   if (output_decimal) {
@@ -66,11 +68,12 @@ int
 main(int argc, char *argv[]) {
 main(int argc, char *argv[]) {
   extern char *optarg;
   extern char *optarg;
   extern int optind;
   extern int optind;
-  const char *optstr = "i:dh";
+  const char *optstr = "i:dqh";
 
 
   bool got_input_string = false;
   bool got_input_string = false;
   string input_string;
   string input_string;
   bool output_decimal = false;
   bool output_decimal = false;
+  bool suppress_filename = false;
 
 
   int flag = getopt(argc, argv, optstr);
   int flag = getopt(argc, argv, optstr);
 
 
@@ -85,6 +88,10 @@ main(int argc, char *argv[]) {
       output_decimal = true;
       output_decimal = true;
       break;
       break;
 
 
+    case 'q':
+      suppress_filename = true;
+      break;
+
     case 'h':
     case 'h':
       help();
       help();
       exit(1);
       exit(1);
@@ -106,7 +113,7 @@ main(int argc, char *argv[]) {
   if (got_input_string) {
   if (got_input_string) {
     HashVal hash;
     HashVal hash;
     hash.hash_string(input_string);
     hash.hash_string(input_string);
-    output_hash("", hash, output_decimal);
+    output_hash("", hash, output_decimal, true);
   }
   }
 
 
   bool okflag = true;
   bool okflag = true;
@@ -123,7 +130,8 @@ main(int argc, char *argv[]) {
         cerr << "Unable to read " << source_file << "\n";
         cerr << "Unable to read " << source_file << "\n";
         okflag = false;
         okflag = false;
       } else {
       } else {
-        output_hash(source_file.get_basename(), hash, output_decimal);
+        output_hash(source_file.get_basename(), hash, 
+                    output_decimal, suppress_filename);
       }
       }
     }
     }
   }
   }