-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhm_insert.cc
66 lines (55 loc) · 1.67 KB
/
hm_insert.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* HmSearch hash library - insert tool
*
* Copyright 2014 Commons Machinery http://commonsmachinery.se/
* Distributed under an MIT license, please see LICENSE in the top dir.
*/
#include <stdio.h>
#include <iostream>
#include <memory>
#include "hmsearch.h"
int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "Usage: %s path [hexhash...]\n", argv[0]);
return 1;
}
const char *path = argv[1];
std::string error_msg;
std::auto_ptr<HmSearch> db(HmSearch::open(path, HmSearch::READWRITE, &error_msg));
if (!db.get()) {
fprintf(stderr, "%s: error opening %s: %s\n", argv[0], path, error_msg.c_str());
return 1;
}
if (argc > 2) {
// Insert hashes from command line
for (int i = 2; i < argc; i++) {
const char *hexhash = argv[i];
if (!db->insert(HmSearch::parse_hexhash(hexhash), &error_msg)) {
fprintf(stderr, "%s: cannot insert hash: %s (%s)\n",
argv[0], error_msg.c_str(), hexhash);
}
}
}
else {
// Read hashes from stdin
std::string hexhash;
while (std::cin >> hexhash) {
if (!db->insert(HmSearch::parse_hexhash(hexhash), &error_msg)) {
fprintf(stderr, "%s: cannot insert hash: %s (%s)\n",
argv[0], error_msg.c_str(), hexhash.c_str());
}
}
}
if (!db->close(&error_msg)) {
fprintf(stderr, "%s: error closing database: %s\n",
argv[0], error_msg.c_str());
return 1;
}
return 0;
}
/*
Local Variables:
c-file-style: "stroustrup"
indent-tabs-mode:nil
End:
*/