ht_checksum.cc

Go to the documentation of this file.
00001 
00022 #include "Common/Compat.h"
00023 
00024 #include <iostream>
00025 
00026 #include "Checksum.h"
00027 #include "FileUtils.h"
00028 
00029 using namespace Hypertable;
00030 using namespace std;
00031 
00032 namespace {
00033 
00034   const char *usage_str =
00035     "\n" \
00036     "usage: java org.hypertable.Common.Checksum <algorithm> <file>\n" \
00037     "\n" \
00038     "This program runs the checksum algorithm, <algorithm>, over the bytes\n" \
00039     "of the input file <file> and displays the resulting checksum as a\n" \
00040     "signed integer.\n" \
00041     "\n" \
00042     "Supported Algorithms:\n" \
00043     "\n" \
00044     "  fletcher32\n" \
00045     "\n";
00046 
00047 }
00048 
00052 int main(int argc, char **argv) {
00053 
00054   if (argc != 3) {
00055     cout << usage_str << endl;
00056     exit(1);
00057   }
00058 
00059   if (!strcmp(argv[1], "fletcher32")) {
00060     off_t len;
00061     char *data = FileUtils::file_to_buffer(argv[2], &len);
00062     int32_t checksum = fletcher32(data, len);
00063     cout << checksum << endl;
00064   }
00065   else {
00066     cout << usage_str << endl;
00067     exit(1);
00068   }
00069 
00070   return 0;
00071 }