Browse Source

optionally remove brackets from output

cxgeorge 23 years ago
parent
commit
4c3aa7bb0a

+ 33 - 3
panda/src/downloadertools/check_md5.cxx

@@ -1,5 +1,5 @@
 // Filename: check_md5.cxx
 // Filename: check_md5.cxx
-// Created by:  
+// Created by:
 //
 //
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //
 //
@@ -18,18 +18,48 @@
 
 
 #include <crypto_utils.h>
 #include <crypto_utils.h>
 #include <hashVal.h>
 #include <hashVal.h>
+#include <errno.h>
+#include <string.h>
 
 
 int
 int
 main(int argc, char *argv[]) {
 main(int argc, char *argv[]) {
+  const char *usagestr="Usage: check_md5 [-dbfmt_output] <file>";
   if (argc < 2) {
   if (argc < 2) {
-    cerr << "Usage: check_md5 <file>" << endl;
+    cerr << usagestr << endl;
     return 0;
     return 0;
   }
   }
 
 
-  Filename source_file = argv[1];
+  bool bRemoveBrackets = (strcmp("-dbfmt_output",argv[1])==0);
+
+  Filename source_file;
+
+  if(bRemoveBrackets) {
+    if(argc<3) {
+        cerr << usagestr << endl;
+        return 0;
+    }
+    source_file = argv[2];
+  } else {
+    source_file = argv[1];
+  }
+
+  #ifdef WIN32_VC
+      if(_access(source_file.c_str(), 0) == -1) {  // does this exist on unix?
+          if(errno==ENOENT) {
+              cerr << usagestr << endl;
+              cerr << source_file << " not found!\n";
+              return -1;
+          }
+      }
+  #endif
 
 
   HashVal hash;
   HashVal hash;
   md5_a_file(source_file, hash);
   md5_a_file(source_file, hash);
+
+  if(bRemoveBrackets) {
+      hash.set_output_brackets(false);
+  }
+
   cout << hash << endl;
   cout << hash << endl;
 
 
   return 1;
   return 1;

+ 13 - 1
panda/src/express/hashVal.I

@@ -25,6 +25,7 @@
 INLINE HashVal::
 INLINE HashVal::
 HashVal(void) {
 HashVal(void) {
   hv[0] = hv[1] = hv[2] = hv[3] = 0;
   hv[0] = hv[1] = hv[2] = hv[3] = 0;
+  _bUseBrackets = true;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -71,5 +72,16 @@ set_value(int val, uint hashval) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void HashVal::
 INLINE void HashVal::
 output(ostream &out) const {
 output(ostream &out) const {
-  out << "[" << hv[0] << " " << hv[1] << " " << hv[2] << " " << hv[3] << "]";
+  if(_bUseBrackets)
+      out << "[";
+  out << hv[0] << " " << hv[1] << " " << hv[2] << " " << hv[3];
+  if(_bUseBrackets)
+      out << "]";
 }
 }
+
+INLINE void HashVal::
+set_output_brackets(bool bUseBrackets) {
+  _bUseBrackets = bUseBrackets;
+}
+
+

+ 3 - 0
panda/src/express/hashVal.h

@@ -35,6 +35,9 @@ PUBLISHED:
   INLINE void set_value(int val, uint hash);
   INLINE void set_value(int val, uint hash);
   INLINE void output(ostream &out) const;
   INLINE void output(ostream &out) const;
   uint hv[4];
   uint hv[4];
+public:
+  INLINE void set_output_brackets(bool bUseBrackets);
+  bool _bUseBrackets;
 };
 };
 
 
 INLINE ostream &operator << (ostream &out, const HashVal &hv) {
 INLINE ostream &operator << (ostream &out, const HashVal &hv) {