]> git.donarmstrong.com Git - mothur.git/blobdiff - setdircommand.cpp
fixed segfault in unifrac with subsample. in progress of implementing a version of...
[mothur.git] / setdircommand.cpp
index fc411ae61120ae90c4efb396de928b028432965f..55b752dba4f40e76f11a46d2608e75d43c0de506 100644 (file)
@@ -59,6 +59,7 @@ SetDirectoryCommand::SetDirectoryCommand(string option)  {
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
                        vector<string> myArray = setParameters();
@@ -100,36 +101,21 @@ int SetDirectoryCommand::execute(){
                
                commandFactory = CommandFactory::getInstance();
                
+               m->mothurOut("Mothur's directories:"); m->mothurOutEndLine();
+               
                //redirect output
                if ((output == "clear") || (output == "")) {  output = "";  commandFactory->setOutputDirectory(output);  }
                else if (output == "default") { 
                        string exepath = m->argv;
                        output = exepath.substr(0, (exepath.find_last_of('m')));
                        
-                       m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine();  
+                       m->mothurOut("outputDir=" + output); m->mothurOutEndLine();  
                        commandFactory->setOutputDirectory(output);
                }else {
-                       //add / to name if needed
-                       string lastChar = output.substr(output.length()-1);
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                               if (lastChar != "/") { output += "/"; }
-                       #else
-                               if (lastChar != "\\") { output += "\\"; }       
-                       #endif
-                       
-                       //test to make sure directory exists
-                       output = m->getFullPathName(output);
-                       string outTemp = output + "temp";
-                       ofstream out;
-                       out.open(outTemp.c_str(), ios::trunc);
-                       if(!out) {
-                               m->mothurOut(output + " directory does not exist or is not writable."); m->mothurOutEndLine(); 
-                       }else{
-                               out.close();
-                               remove(outTemp.c_str());
-                               m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine();  
+            if (m->dirCheck(output)) {
+                m->mothurOut("outputDir=" + output); m->mothurOutEndLine();  
                                commandFactory->setOutputDirectory(output);
-                       }
+            }
                }
                
                //redirect input
@@ -138,37 +124,20 @@ int SetDirectoryCommand::execute(){
                        string exepath = m->argv;
                        input = exepath.substr(0, (exepath.find_last_of('m')));
                        
-                       m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine();  
+                       m->mothurOut("inputDir=" + input); m->mothurOutEndLine();  
                        commandFactory->setInputDirectory(input);
                }else {
-                       //add / to name if needed
-                       string lastChar = input.substr(input.length()-1);
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                               if (lastChar != "/") { input += "/"; }
-                       #else
-                               if (lastChar != "\\") { input += "\\"; }        
-                       #endif
-                       
-                       //test to make sure directory exists
-                       input = m->getFullPathName(input);
-                       string inTemp = input + "temp";
-                       ofstream in;
-                       in.open(inTemp.c_str(), ios::trunc);
-                       if(!in) {
-                               m->mothurOut(input + " directory does not exist or is not writable."); m->mothurOutEndLine(); 
-                       }else{
-                               in.close();
-                               remove(inTemp.c_str());
-                               m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine();  
+            if (m->dirCheck(input)) {
+                m->mothurOut("inputDir=" + input); m->mothurOutEndLine();  
                                commandFactory->setInputDirectory(input); 
-                       }
-               }
+            }
+        }
                
                //set default
                if (tempdefault == "clear") {  
                        #ifdef MOTHUR_FILES
                                string temp = MOTHUR_FILES; 
-                               m->mothurOut("Resetting default directory to " + temp); m->mothurOutEndLine();  
+                               m->mothurOut("tempDefault=" + temp); m->mothurOutEndLine();  
                                m->setDefaultPath(temp);
                        #else
                                string temp = ""; 
@@ -180,20 +149,14 @@ int SetDirectoryCommand::execute(){
                        string exepath = m->argv;
                        tempdefault = exepath.substr(0, (exepath.find_last_of('m')));
                        
-                       m->mothurOut("Changing default directory to " + tempdefault); m->mothurOutEndLine();  
+                       m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
                        m->setDefaultPath(tempdefault);
                }else {
-                       //add / to name if needed
-                       string lastChar = tempdefault.substr(tempdefault.length()-1);
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                               if (lastChar != "/") { tempdefault += "/"; }
-                       #else
-                               if (lastChar != "\\") { tempdefault += "\\"; }  
-                       #endif
-                       
-                       m->mothurOut("Changing default directory to " + tempdefault); m->mothurOutEndLine();  
-                       m->setDefaultPath(tempdefault);
-               }
+            if (m->dirCheck(tempdefault)) {
+                m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
+                               m->setDefaultPath(tempdefault); 
+            }
+        }
 
                return 0;
        }