--- misc/mysql_splitter/splitter.cpp 2011/04/07 21:26:36 1281 +++ misc/mysql_splitter/splitter.cpp 2011/04/10 20:37:28 1282 @@ -4,8 +4,12 @@ #include #include + #include #include +#include + +namespace po = boost::program_options; using namespace std; @@ -27,14 +31,45 @@ int main(int argc, char** argv) { - if (argc != 2) { - cout << "Usage: splitter " << endl; + + po::options_description desc("Mysql dump file splitter:\nAllowed options"); + desc.add_options() + ("help", "produce help message") + ("data", "ignore ceate tablestatements") + ("input-file", po::value< string >(), "input file") + ; + + po::positional_options_description p; + p.add("input-file", -1); + + + po::variables_map vm; + po::store( po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); + po::notify(vm); + + if (vm.count("help")) { + cout << desc << "\n"; + return 1; + } + + + + if ( vm.count("input-file") == 0) { + cout << desc << endl; return 1; } + char linebuf[BUFSIZE]; - ifstream in(argv[1]); + string inputfile = vm["input-file"].as< string >(); + if (! boost::filesystem::exists(inputfile) ) { + cout << "No file named " << inputfile << endl; + return 1; + } + + + ifstream in( inputfile.c_str() ); ofstream out; ostringstream header;