optionally remove brackets from output

This commit is contained in:
cxgeorge 2002-10-21 06:29:41 +00:00
parent 932c89db19
commit 4c3aa7bb0a
3 changed files with 49 additions and 4 deletions

View File

@ -1,5 +1,5 @@
// Filename: check_md5.cxx
// Created by:
// Created by:
//
////////////////////////////////////////////////////////////////////
//
@ -18,18 +18,48 @@
#include <crypto_utils.h>
#include <hashVal.h>
#include <errno.h>
#include <string.h>
int
main(int argc, char *argv[]) {
const char *usagestr="Usage: check_md5 [-dbfmt_output] <file>";
if (argc < 2) {
cerr << "Usage: check_md5 <file>" << 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;

View File

@ -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;
}

View File

@ -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) {