]> git.donarmstrong.com Git - mothur.git/blobdiff - mergefilecommand.cpp
working on megastats
[mothur.git] / mergefilecommand.cpp
index 0a8c0d8cda62808664a83f46c44cebb770e14f4a..098da009eaeacfab076c9ad0f800f626158f4a15 100644 (file)
@@ -11,7 +11,7 @@
 
 //**********************************************************************************************************************
 
-MergeFileCommand::MergeFileCommand(string option){
+MergeFileCommand::MergeFileCommand(string option)  {
        try {
                abort = false;
                
@@ -39,8 +39,8 @@ MergeFileCommand::MergeFileCommand(string option){
                        if (inputDir == "not found"){   inputDir = "";          }
                        
                        string fileList = validParameter.validFile(parameters, "input", false);                 
-                       if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine();  abort=true;  }
-                       else{   splitAtDash(fileList, fileNames);       }
+                       if(fileList == "not found") { m->mothurOut("you must enter two or more file names"); m->mothurOutEndLine();  abort=true;  }
+                       else{   m->splitAtDash(fileList, fileNames);    }
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found")   {       outputDir = "";         }
@@ -49,30 +49,30 @@ MergeFileCommand::MergeFileCommand(string option){
                        numInputFiles = fileNames.size();
                        ifstream testFile;
                        if(numInputFiles == 0){
-                               mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) +  " file names"); mothurOutEndLine();
+                               m->mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) +  " file names"); m->mothurOutEndLine();
                                abort=true;  
                        }
                        else{
                                for(int i=0;i<numInputFiles;i++){
                                        if (inputDir != "") {
-                                               string path = hasPath(fileNames[i]);
+                                               string path = m->hasPath(fileNames[i]);
                                                //if the user has not given a path then, add inputdir. else leave path alone.
                                                if (path == "") {       fileNames[i] = inputDir + fileNames[i];         }
                                        }
                                        
-                                       if(openInputFile(fileNames[i], testFile)){      abort = true;   }
+                                       if(m->openInputFile(fileNames[i], testFile)){   abort = true;   }
                                        testFile.close();
                                }
                        }   
                        
                        outputFileName = validParameter.validFile(parameters, "output", false);                 
-                       if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine();  abort=true;  }
-                       else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); }
+                       if (outputFileName == "not found") { m->mothurOut("you must enter an output file name"); m->mothurOutEndLine();  abort=true;  }
+                       else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); }
                }
                        
        }
        catch(exception& e) {
-               errorOut(e, "MergeFileCommand", "MergeFileCommand");
+               m->errorOut(e, "MergeFileCommand", "MergeFileCommand");
                exit(1);
        }
 }
@@ -88,15 +88,17 @@ int MergeFileCommand::execute(){
                if (abort == true) {    return 0;       }
                
                ofstream outputFile;
-               openOutputFile(outputFileName, outputFile);
+               m->openOutputFile(outputFileName, outputFile);
                
                char c;
                for(int i=0;i<numInputFiles;i++){
                        ifstream inputFile; //declaration must be inside for loop of windows throws an error
                        
-                       openInputFile(fileNames[i], inputFile);
+                       m->openInputFile(fileNames[i], inputFile);
                        
                        while(!inputFile.eof()){        
+                               if (m->control_pressed) { inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0;  }
+                       
                                c = inputFile.get(); 
                                //-1 is eof char
                                if (int(c) != -1) { outputFile << c; }   
@@ -106,10 +108,18 @@ int MergeFileCommand::execute(){
                }
                
                outputFile.close();
+               
+               if (m->control_pressed) { remove(outputFileName.c_str()); return 0;  }
+               
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Name: "); m->mothurOutEndLine();
+               m->mothurOut(outputFileName); m->mothurOutEndLine();    
+               m->mothurOutEndLine();
+
                return 0;
        }
        catch(exception& e) {
-               errorOut(e, "MergeFileCommand", "execute");
+               m->errorOut(e, "MergeFileCommand", "execute");
                exit(1);
        }
 }
@@ -118,10 +128,10 @@ int MergeFileCommand::execute(){
 
 void MergeFileCommand::help(){
        try {
-               mothurOut("The merge.file command..."); mothurOutEndLine();
+               m->mothurOut("The merge.file command..."); m->mothurOutEndLine();
        }
        catch(exception& e) {
-               errorOut(e, "MergeFileCommand", "help");
+               m->errorOut(e, "MergeFileCommand", "help");
                exit(1);
        }
 }