-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
42 lines (33 loc) · 816 Bytes
/
main.cpp
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
#include <iostream>
#include <fstream>
#include "Dictionary.h"
#include "Exception.h"
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cerr << "Missing file name" << std::endl;
return 1;
}
std::ifstream f(argv[1], std::ios::binary);
f.seekg (0, std::ios::end);
int length = f.tellg();
f.seekg (0, std::ios::beg);
char* buffer = new char[length];
f.read(buffer, length);
boost::shared_ptr<Bencoding::Element> dict;
try
{
unsigned offset = 0;
dict = Bencoding::Element::factory(buffer, offset);
}
catch (Bencoding::Exception& e)
{
std::cerr << "Exception thrown: " << e.what() << std::endl;
return 2;
}
delete[] buffer;
f.close();
std::cout << dict << std::endl;
return 0;
}