-
Notifications
You must be signed in to change notification settings - Fork 1
/
infoconv.cpp
71 lines (64 loc) · 1.45 KB
/
infoconv.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
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
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>
namespace pt = boost::property_tree;
static void
usage()
{
std::cerr << "USAGE\n"
" infoconv info2json < config.info > config.json\n"
" infoconv json2info < config.info > config.info\n"
" infoconv info2xml < config.info > config.xml\n"
" infoconv xml2info < config.xml > config.info\n";
}
static void
info2json()
{
pt::ptree tree;
pt::info_parser::read_info(std::cin, tree);
pt::json_parser::write_json(std::cout, tree);
}
static void
json2info()
{
pt::ptree tree;
pt::json_parser::read_json(std::cin, tree);
pt::info_parser::write_info(std::cout, tree);
}
static void
info2xml()
{
pt::ptree tree;
pt::info_parser::read_info(std::cin, tree);
pt::xml_parser::write_xml(std::cout, tree);
}
static void
xml2info()
{
pt::ptree tree;
pt::xml_parser::read_xml(std::cin, tree);
pt::info_parser::write_info(std::cout, tree);
}
int
main(int argc, char** argv)
{
if (argc != 2) {
usage();
return 2;
}
std::string action(argv[1]);
if (action == "info2json") {
info2json();
} else if (action == "json2info") {
json2info();
} else if (action == "info2xml") {
info2xml();
} else if (action == "xml2info") {
xml2info();
} else {
usage();
return 2;
}
}