5 * Created by Pat Schloss on 6/14/09.
6 * Copyright 2009 Patrick D. Schloss. All rights reserved.
10 #include "mergefilecommand.h"
12 //**********************************************************************************************************************
14 MergeFileCommand::MergeFileCommand(string option){
18 if(option == "help") {
23 //valid paramters for this command
24 string Array[] = {"input", "output"};
25 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
27 OptionParser parser(option);
28 map<string,string> parameters = parser.getParameters();
30 ValidParameters validParameter;
32 //check to make sure all parameters are valid for command
33 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
34 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
37 string fileList = validParameter.validFile(parameters, "input", false);
38 if(fileList == "not found") { cout << "you must enter two or more file names" << endl; abort=true; }
39 else{ splitAtDash(fileList, fileNames); }
41 numInputFiles = fileNames.size();
43 if(numInputFiles == 0){
44 cout << "you must enter two or more file names and you entered " << fileNames.size() << " file names" << endl;
48 for(int i=0;i<numInputFiles;i++){
49 if(openInputFile(fileNames[i], testFile)){ abort = true; }
54 outputFileName = validParameter.validFile(parameters, "output", false);
55 if (outputFileName == "not found") { cout << "you must enter an output file name" << endl; abort=true; }
60 cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64 cout << "An unknown error has occurred in the MergeFileCommand class function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
69 //**********************************************************************************************************************
71 MergeFileCommand::~MergeFileCommand() { /* do nothing */ }
73 //**********************************************************************************************************************
75 int MergeFileCommand::execute(){
77 if (abort == true) { return 0; }
80 openOutputFile(outputFileName, outputFile);
84 for(int i=0;i<numInputFiles;i++){
85 openInputFile(fileNames[i], inputFile);
87 while(!inputFile.eof()){ c = inputFile.get(); outputFile << c; }
96 cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 cout << "An unknown error has occurred in the BinSeqCommand class function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106 //**********************************************************************************************************************
108 void MergeFileCommand::help(){
110 cout << "The merge.file command..." << endl;
112 catch(exception& e) {
113 cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117 cout << "An unknown error has occurred in the MergeFileCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 //**********************************************************************************************************************