/[projects]/misc/mysql_splitter/splitter.cpp
ViewVC logotype

Diff of /misc/mysql_splitter/splitter.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1283 by torben, Sun Apr 10 21:15:14 2011 UTC revision 1458 by torben, Wed May 11 10:14:11 2011 UTC
# Line 19  string remove_comments(string in) { Line 19  string remove_comments(string in) {
19          bool isComment = false;          bool isComment = false;
20          ostringstream out;          ostringstream out;
21          for (int i=0; i<in.length() -1; i++) {          for (int i=0; i<in.length() -1; i++) {
22                  if (in.at(i) == '/' && in.at(i+1) == '*')                    if (in.at(i) == '/' && in.at(i+1) == '*')
23                          isComment = true;                          isComment = true;
24                    
25                  if (in.at(i) == '*' && in.at(i+1) == '/') {                  if (in.at(i) == '*' && in.at(i+1) == '/') {
26                          i++;                          i++;
27                          isComment = false;                          isComment = false;
# Line 35  string remove_comments(string in) { Line 35  string remove_comments(string in) {
35          return out.str();          return out.str();
36  }  }
37    
38  string getLastWord(string input) {  string get_db_name(string input) {
39          input = remove_comments(input);          input = remove_comments(input);
40    
41          boost::erase_all(input,"`");          boost::erase_all(input,"`");
42            boost::erase_all(input, ";");
43          boost::trim(input);          boost::trim(input);
44    
45          vector<string> words;          vector<string> words;
46          words = boost::split(words, input, boost::is_any_of(" ") );          words = boost::split(words, input, boost::is_any_of(" ") );
47    
48          string last = words.back();          string last = words.back();
   
         boost::erase_all(last, ";");  
49          boost::trim(last);          boost::trim(last);
50    
   
51          return last;          return last;
52  }  }
53    
# Line 90  int main(int argc, char** argv) { Line 89  int main(int argc, char** argv) {
89                  cout << "No file named " << inputfile << endl;                  cout << "No file named " << inputfile << endl;
90                  return 1;                  return 1;
91          }          }
92            
93    
94          ifstream in( inputfile.c_str() );          ifstream in( inputfile.c_str() );
95          ofstream out;          ofstream out;
# Line 100  int main(int argc, char** argv) { Line 99  int main(int argc, char** argv) {
99          if (!in.is_open() ) {          if (!in.is_open() ) {
100                  cout << "Could not open " << argv[1] << endl;                  cout << "Could not open " << argv[1] << endl;
101                  return 2;                  return 2;
102          }          }
103    
104            time_t start = time(NULL);
105    
106          while ( in.good() ) {          while ( in.good() ) {
107                  in.getline(linebuf, BUFSIZE);                  in.getline(linebuf, BUFSIZE);
# Line 116  int main(int argc, char** argv) { Line 117  int main(int argc, char** argv) {
117                          }                          }
118    
119                          boost::trim(line);                          boost::trim(line);
120                          string dbname = getLastWord(line);                          string dbname = get_db_name(line);
121                          cout << ">" << dbname << endl;                          cout << ">" << dbname << endl;
122    
123    
# Line 153  int main(int argc, char** argv) { Line 154  int main(int argc, char** argv) {
154    
155    
156          if(out.is_open())          if(out.is_open())
157                  out.close();                  out.close();
158    
159        time_t end = time(NULL);
160    
161        cout << "Elapsed " << (end-start) << " seconds" << endl;
162    
163    
164          in.close();          in.close();

Legend:
Removed from v.1283  
changed lines
  Added in v.1458

  ViewVC Help
Powered by ViewVC 1.1.20