From 4c3aa7bb0a7fa3610439f718b9507ea8239dcc7a Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Mon, 21 Oct 2002 06:29:41 +0000 Subject: [PATCH] optionally remove brackets from output --- panda/src/downloadertools/check_md5.cxx | 36 ++++++++++++++++++++++--- panda/src/express/hashVal.I | 14 +++++++++- panda/src/express/hashVal.h | 3 +++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/panda/src/downloadertools/check_md5.cxx b/panda/src/downloadertools/check_md5.cxx index d720978868..b92871c85c 100644 --- a/panda/src/downloadertools/check_md5.cxx +++ b/panda/src/downloadertools/check_md5.cxx @@ -1,5 +1,5 @@ // Filename: check_md5.cxx -// Created by: +// Created by: // //////////////////////////////////////////////////////////////////// // @@ -18,18 +18,48 @@ #include #include +#include +#include int main(int argc, char *argv[]) { + const char *usagestr="Usage: check_md5 [-dbfmt_output] "; if (argc < 2) { - cerr << "Usage: check_md5 " << endl; + cerr << usagestr << endl; 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; md5_a_file(source_file, hash); + + if(bRemoveBrackets) { + hash.set_output_brackets(false); + } + cout << hash << endl; return 1; diff --git a/panda/src/express/hashVal.I b/panda/src/express/hashVal.I index 394a334b27..f18724c51b 100644 --- a/panda/src/express/hashVal.I +++ b/panda/src/express/hashVal.I @@ -25,6 +25,7 @@ INLINE HashVal:: HashVal(void) { hv[0] = hv[1] = hv[2] = hv[3] = 0; + _bUseBrackets = true; } //////////////////////////////////////////////////////////////////// @@ -71,5 +72,16 @@ set_value(int val, uint hashval) { //////////////////////////////////////////////////////////////////// INLINE void HashVal:: 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; +} + + diff --git a/panda/src/express/hashVal.h b/panda/src/express/hashVal.h index e583ae9ab0..433e80b0eb 100644 --- a/panda/src/express/hashVal.h +++ b/panda/src/express/hashVal.h @@ -35,6 +35,9 @@ PUBLISHED: INLINE void set_value(int val, uint hash); INLINE void output(ostream &out) const; uint hv[4]; +public: + INLINE void set_output_brackets(bool bUseBrackets); + bool _bUseBrackets; }; INLINE ostream &operator << (ostream &out, const HashVal &hv) {