]> git.donarmstrong.com Git - mothur.git/blobdiff - engine.cpp
added warning about merging with something above cutoff to cluster. working on chimeras
[mothur.git] / engine.cpp
index 95c0ff03f0f05145a9435b8deb06e20bd72fdc8f..18e1a595c06343a521d9bcd6458b95db4d863db7 100644 (file)
 
 #include "engine.hpp"
 
+/***********************************************************************/
+Engine::Engine(){
+       try {
+               cFactory = CommandFactory::getInstance();
+       }
+       catch(exception& e) {
+               errorOut(e, "Engine", "Engine");
+               exit(1);
+       }
+}
+
 /***********************************************************************/
 
 InteractEngine::InteractEngine(string path){
 
        globaldata = GlobalData::getInstance();
        globaldata->argv = path;
-       
-       
 }
 
 /***********************************************************************/
 
-InteractEngine::~InteractEngine(){
-       }
+InteractEngine::~InteractEngine(){}
 
 /***********************************************************************/
 //This function allows the user to input commands one line at a time until they quit.
@@ -39,29 +47,24 @@ bool InteractEngine::getInput(){
                string options = "";
                int quitCommandCalled = 0;
                
-                               
                while(quitCommandCalled != 1){
-                       
+
                        mothurOutEndLine();
-                       mothurOut("mothur > ");
-                       getline(cin, input);
-                       if (cin.eof()) { input = "quit()"; }
                        
-                       mothurOutJustToLog(input);
-                       mothurOutEndLine();
+                       input = getCommand();                   
                        
                        //allow user to omit the () on the quit command
                        if (input == "quit") { input = "quit()"; }
                        
                        CommandOptionParser parser(input);
                        commandName = parser.getCommandString();
+       
                        options = parser.getOptionString();
                        
                        if (commandName != "") {
                        
                                //executes valid command
-                               CommandFactory cFactory;
-                               Command* command = cFactory.getCommand(commandName, options);
+                               Command* command = cFactory->getCommand(commandName, options);
                                quitCommandCalled = command->execute();
                                
                        }else {
@@ -76,7 +79,45 @@ bool InteractEngine::getInput(){
                exit(1);
        }
 }
-
+/***********************************************************************/
+string Engine::getCommand()  {
+       try {
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       #ifdef USE_READLINE
+                               char* nextCommand = NULL;
+                               nextCommand = readline("mothur > ");
+                               
+                               if(nextCommand != NULL) {  add_history(nextCommand);  } 
+                               else{ //^D causes null string and we want it to quit mothur
+                                       nextCommand = "quit"; 
+                                       cout << nextCommand << endl;
+                               }       
+                               
+                               mothurOutJustToLog("mothur > " + toString(nextCommand));
+                               return nextCommand;
+                       #else
+                               string nextCommand = "";
+                               mothurOut("mothur > ");
+                               getline(cin, nextCommand);
+                               mothurOutJustToLog("mothur > " + toString(nextCommand));
+                               return nextCommand;
+                       #endif
+               #else
+                       string nextCommand = "";
+                       mothurOut("mothur > ");
+                       getline(cin, nextCommand);
+                       mothurOutJustToLog("mothur > " + toString(nextCommand));
+                       return nextCommand;
+               #endif
+               
+               mothurOutEndLine();
+                                               
+       }
+       catch(exception& e) {
+               errorOut(e, "Engine", "getCommand");
+               exit(1);
+       }
+}
 /***********************************************************************/
 //This function opens the batchfile to be used by BatchEngine::getInput.
 BatchEngine::BatchEngine(string path, string batchFileName){
@@ -95,8 +136,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){
 
 /***********************************************************************/
 
-BatchEngine::~BatchEngine(){
-       }
+BatchEngine::~BatchEngine(){   }
 
 /***********************************************************************/
 //This Function allows the user to run a batchfile containing several commands on Dotur
@@ -121,8 +161,6 @@ bool BatchEngine::getInput(){
                        if (inputBatchFile.eof()) { input = "quit()"; }
                        else { input = getline(inputBatchFile); }
                        
-                       
-                       
                        if (input[0] != '#') {
                                
                                mothurOutEndLine();
@@ -140,8 +178,7 @@ bool BatchEngine::getInput(){
                                if (commandName != "") {
 
                                        //executes valid command
-                                       CommandFactory cFactory;
-                                       Command* command = cFactory.getCommand(commandName, options);
+                                       Command* command = cFactory->getCommand(commandName, options);
                                        quitCommandCalled = command->execute();
                                }else {         
                                        mothurOut("Invalid."); 
@@ -174,8 +211,6 @@ ScriptEngine::ScriptEngine(string path, string commandString){
 
                globaldata->argv = path;
                
-               
-       
        }
        catch(exception& e) {
                errorOut(e, "ScriptEngine", "ScriptEngine");
@@ -185,8 +220,7 @@ ScriptEngine::ScriptEngine(string path, string commandString){
 
 /***********************************************************************/
 
-ScriptEngine::~ScriptEngine(){
-       }
+ScriptEngine::~ScriptEngine(){         }
 
 /***********************************************************************/
 //This Function allows the user to run a batchfile containing several commands on mothur
@@ -223,8 +257,7 @@ bool ScriptEngine::getInput(){
                        if (commandName != "") {
 
                                //executes valid command
-                               CommandFactory cFactory;
-                               Command* command = cFactory.getCommand(commandName, options);
+                               Command* command = cFactory->getCommand(commandName, options);
                                quitCommandCalled = command->execute();
                        }else {         
                                mothurOut("Invalid.");