-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert.cc
executable file
·83 lines (76 loc) · 1.96 KB
/
convert.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "convert_db.h"
#include <getopt.h>
void help(int e){
std::cout<<"Usage: db_converter --src SRC --dest DEST [DBTYPE]"<<std::endl;
std::cout<<"Convert database from BerkeleyDB format to GDBM/LMDB"<<std::endl;
std::cout<<std::endl;
std::cout<<" --src\t\tsource database file in BerkeleyDB format"<<std::endl;
std::cout<<" --dst\t\tfile to be created in GDBM/LMDB format"<<std::endl;
std::cout<<" --lmdb\t\tDBTYPE - specifies output database type to LMDB. LMDB database consists of multiple files. In case of using LMDB output directory must be created and provided as DEST"<<std::endl;
std::cout<<std::endl;
std::cout<<"If DBTYPE is not set, GDBM will be used as default"<<std::endl;
std::cout<<std::endl;
std::cout<<"Report bugs to: <https://github.com/fila43/db_converter>"<<std::endl;
exit(e);
}
int main(int argc, char* argv[]){
std::string src, dst;
src = dst ="";
bool lmdb = false;
option long_options[] = {
{"dest", required_argument, NULL, 'd'},
{"src", required_argument, NULL, 's'},
{"lmdb", no_argument, NULL, 'l'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
int option_index = 0;
while (1) {
const int opt = getopt_long(argc, argv, "d:s:h", long_options, &option_index);
if (opt == - 1)
break;
switch (opt) {
case 'd':
dst = optarg;
break;
case 's':
src = optarg;
break;
case 'l':
lmdb = true;
break;
case 'h':
help(0);
default:
break;
}
}
if (src == "" || dst == "")
help(1);
DB_ * x = new Libdb();
if (!x->connect_database(src)) {
// error is printed in the connect_database function
delete x;
return 1;
}
DB_ *b;
if (lmdb)
b = new LMDB_();
else
b = new GDBM_();
if (!b->create_database(dst)) {
std::cerr<<"Failed to create destination database\n";
delete x;
delete b;
return 1;
}
if (!b->fill_database(x)){
std::cerr<<"database filling failed\n";
delete x;
delete b;
return 1;
}
delete x;
delete b;
return 0;
}