4 |
#include <string> |
#include <string> |
5 |
#include <vector> |
#include <vector> |
6 |
|
|
7 |
|
|
8 |
#include <boost/algorithm/string.hpp> |
#include <boost/algorithm/string.hpp> |
9 |
#include <boost/filesystem.hpp> |
#include <boost/filesystem.hpp> |
10 |
|
#include <boost/program_options.hpp> |
11 |
|
|
12 |
|
namespace po = boost::program_options; |
13 |
|
|
14 |
using namespace std; |
using namespace std; |
15 |
|
|
31 |
|
|
32 |
|
|
33 |
int main(int argc, char** argv) { |
int main(int argc, char** argv) { |
34 |
if (argc != 2) { |
|
35 |
cout << "Usage: splitter <file>" << endl; |
po::options_description desc("Mysql dump file splitter:\nAllowed options"); |
36 |
|
desc.add_options() |
37 |
|
("help", "produce help message") |
38 |
|
("data", "ignore ceate tablestatements") |
39 |
|
("input-file", po::value< string >(), "input file") |
40 |
|
; |
41 |
|
|
42 |
|
po::positional_options_description p; |
43 |
|
p.add("input-file", -1); |
44 |
|
|
45 |
|
|
46 |
|
po::variables_map vm; |
47 |
|
po::store( po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); |
48 |
|
po::notify(vm); |
49 |
|
|
50 |
|
if (vm.count("help")) { |
51 |
|
cout << desc << "\n"; |
52 |
|
return 1; |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
if ( vm.count("input-file") == 0) { |
58 |
|
cout << desc << endl; |
59 |
return 1; |
return 1; |
60 |
} |
} |
61 |
|
|
62 |
|
|
63 |
char linebuf[BUFSIZE]; |
char linebuf[BUFSIZE]; |
64 |
|
|
65 |
ifstream in(argv[1]); |
string inputfile = vm["input-file"].as< string >(); |
66 |
|
if (! boost::filesystem::exists(inputfile) ) { |
67 |
|
cout << "No file named " << inputfile << endl; |
68 |
|
return 1; |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
ifstream in( inputfile.c_str() ); |
73 |
ofstream out; |
ofstream out; |
74 |
|
|
75 |
ostringstream header; |
ostringstream header; |