/* * hddmcat : tool that reads in a sequence of HDDM files * and catenates them into a single HDDM stream * * Version 1.2 - Richard Jones, December 2005. * - Updated code to use STL strings and vectors instead of old c-style * pre-allocated arrays and strXXX functions. * - Moved functions into classes grouped by function for better clarity. * * Original version - Richard Jones, February 24 2004. * */ using namespace std; #include #include #include #include #include #include #include #include #include #include void usage() { cerr << "\nUsage:\n" << " hddmcat file1.hddm [file2.hddm] ...\n\n" << endl; } int main(int argC, char* argV[]) { string xFilename; int argInd; for (argInd = 1; argInd < argC; argInd++) { if (argV[argInd][0] != '-') { break; } else { usage(); return 1; } } string hddmFile; istream* ifs; if (argInd == argC) { ifs = &cin; } else if (argInd < argC) { hddmFile = string(argV[argInd++]); ifs = new ifstream(hddmFile.c_str()); } else { usage(); return 1; } if (!ifs->good()) { cerr << "hddmcat: Error opening input stream " << hddmFile << endl; exit(1); } list stringList; stringList.push_back(new string); list::iterator h; h = stringList.begin(); if (std::getline(*ifs,**h)) { if ((*h)->substr(0,5) == "substr(0,5) == "") { break; } stringList.push_back(new string); } const int bufferSize = 65536; char buffer[bufferSize]; int count; while (count = (ifs->read(buffer,bufferSize), ifs->gcount())) { cout.write(buffer,count); } if (ifs != &cin) { ((ifstream*)ifs)->close(); } while (argInd < argC) { ifstream* ifs; hddmFile = argV[argInd++]; ifs = new ifstream(hddmFile.c_str()); if (!ifs->good()) { cerr << "hddmcat: Error opening input stream " << hddmFile << endl; exit(1); } h = stringList.begin(); string line; if (getline(*ifs,line)) { if (line.substr(0,5) == "") { break; } } while (count = (ifs->read(buffer,bufferSize), ifs->gcount())) { cout.write(buffer,count); } delete ifs; } }