-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (70 loc) · 1.82 KB
/
main.cpp
File metadata and controls
83 lines (70 loc) · 1.82 KB
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
83
#include "main.hpp"
int main(int argc, char **argv)
{
po::variables_map vm;
try {
vm = op(argc, argv);
}
catch( no_file_name_exception& c)
{
std::cout << c.imdoingitwrong() << std::endl;
return 1;
}
std::string filename = vm["input-file"].
as <std::vector <std::string> >().front();
std::string output;
if(vm.count("output-file"))
{
output = vm["output-file"].
as <std::vector <std::string> >().front();
}
mobireader m(filename);
mobi2epub e(m);
try
{
if(!output.empty())
e.save_to_directory(output);
else
e.save_to_directory();
}
catch(epub::user_wants_out_exception)
{
return 1;
}
e.directory_to_epub();
//return 0; //obsolete in c++, oh shi.
}
po::variables_map op(int &ac, char **av)
{
po::variables_map vm;
po::options_description desc("mobitoepub input file [output file] [options]");
desc.add_options()
("help,h", "produce help message")
("input-file,i", po::value< std::vector <std::string> >(), "input file")
("output-file,o", po::value< std::vector <std::string> >(), "output file");
;
po::positional_options_description p;
p.add("input-file", 1);
p.add("output-file", 1);
po::store(po::command_line_parser(ac, av).
options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count("help")) {
throw no_file_name_exception(desc);//FIXME
}
if(vm.count("input-file"))
{
std::vector<std::string> ifile = vm["input-file"].as<std::vector <std::string> >();
if (ifile.size() == 1)
return vm;
else
{
throw no_file_name_exception(desc);
}
}
else
{
throw no_file_name_exception(desc);
}
return vm;
}