--- misc/mysql_splitter/splitter.cpp 2011/05/11 19:19:07 1460 +++ misc/mysql_splitter/splitter.cpp 2011/05/12 15:32:44 1461 @@ -1,9 +1,9 @@ #include -#include #include #include #include +#include #include #include @@ -91,12 +91,14 @@ } - ifstream in( inputfile.c_str() ); - ofstream out; + FILE* in = fopen( inputfile.c_str(), "r" ); + FILE* out = NULL; + //ifstream in( inputfile.c_str() ); + //ofstream out; ostringstream header; - if (!in.is_open() ) { + if ( in == NULL ) { cout << "Could not open " << argv[1] << endl; return 2; } @@ -106,8 +108,8 @@ const char* SEARCH = "CREATE DATABASE"; const int SEARCHLEN = strlen(SEARCH); - while ( in.good() ) { - in.getline(linebuf, BUFSIZE); + while ( feof(in) == 0 && ferror(in) == 0 ) { + fgets(linebuf, BUFSIZE, in); //if (line.substr(0, 15) == "CREATE DATABASE" ) { @@ -115,8 +117,9 @@ if (strncmp(linebuf,SEARCH, SEARCHLEN) == 0) { string line(linebuf); - if (out.is_open() ) { - out.close(); + + if (out != NULL ) { + fclose(out); } boost::trim(line); @@ -131,24 +134,28 @@ bool did_exist = boost::filesystem::exists(filename); - out.open( filename.c_str(), ios::app ); + //out.open( filename.c_str(), ios::app ); + out = fopen(filename.c_str(), "a"); - if (!out.is_open() ) { + if ( out == NULL ) { cout << "could not create outfile " << filename << endl; return 3; } if (!did_exist) { - out << header.str() << endl; //write preamble in new file + fputs(header.str().c_str(), out); + //out << header.str() << endl; //write preamble in new file } } - if (out.is_open() ) { - out << linebuf << endl; + if (out != NULL ) { + fputs(linebuf, out); + fputs("\n", out); + //out << linebuf << endl; } else { header << linebuf << endl; //collect preamble for later use } @@ -156,13 +163,15 @@ } - if(out.is_open()) - out.close(); + if (out != NULL) + fclose(out); + +// if (out.is_open()) +// out.close(); time_t end = time(NULL); cout << "Elapsed " << (end-start) << " seconds" << endl; - - in.close(); + fclose(in); }