]> git.donarmstrong.com Git - mothur.git/blobdiff - engine.cpp
added list parameter to get.seqs and remove.seqs and added readline library for inter...
[mothur.git] / engine.cpp
index 95c0ff03f0f05145a9435b8deb06e20bd72fdc8f..811236003b5089171536c7e075b10b506baf670a 100644 (file)
 
 #include "engine.hpp"
 
+
 /***********************************************************************/
 
 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,15 +37,13 @@ bool InteractEngine::getInput(){
                string options = "";
                int quitCommandCalled = 0;
                
-                               
                while(quitCommandCalled != 1){
                        
                        mothurOutEndLine();
-                       mothurOut("mothur > ");
-                       getline(cin, input);
-                       if (cin.eof()) { input = "quit()"; }
                        
-                       mothurOutJustToLog(input);
+                       input = getCommand();                   
+                       
+                       mothurOutJustToLog("mothur > " + input);
                        mothurOutEndLine();
                        
                        //allow user to omit the () on the quit command
@@ -55,13 +51,13 @@ bool InteractEngine::getInput(){
                        
                        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 +72,32 @@ bool InteractEngine::getInput(){
                exit(1);
        }
 }
-
+/***********************************************************************/
+string Engine::getCommand()  {
+       try {
+               char* nextCommand = NULL;
+               
+               nextCommand = readline("mothur > ");
+               if(nextCommand != NULL) {  add_history(nextCommand);  }
+                                               
+               return nextCommand;
+       }
+       catch(exception& e) {
+               errorOut(e, "Engine", "getCommand");
+               exit(1);
+       }
+}
+/***********************************************************************/
+void Engine::terminateCommand(int dummy)  {
+       try {
+               mothurOut("Stopping command."); mothurOutEndLine();
+               cFactory->getCommand();  //terminates command
+       }
+       catch(exception& e) {
+               errorOut(e, "Engine", "terminateCommand");
+               exit(1);
+       }
+}
 /***********************************************************************/
 //This function opens the batchfile to be used by BatchEngine::getInput.
 BatchEngine::BatchEngine(string path, string batchFileName){
@@ -95,8 +116,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 +141,6 @@ bool BatchEngine::getInput(){
                        if (inputBatchFile.eof()) { input = "quit()"; }
                        else { input = getline(inputBatchFile); }
                        
-                       
-                       
                        if (input[0] != '#') {
                                
                                mothurOutEndLine();
@@ -140,8 +158,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 +191,6 @@ ScriptEngine::ScriptEngine(string path, string commandString){
 
                globaldata->argv = path;
                
-               
-       
        }
        catch(exception& e) {
                errorOut(e, "ScriptEngine", "ScriptEngine");
@@ -185,8 +200,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 +237,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.");