#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.
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
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 {
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){
/***********************************************************************/
-BatchEngine::~BatchEngine(){
- }
+BatchEngine::~BatchEngine(){ }
/***********************************************************************/
//This Function allows the user to run a batchfile containing several commands on Dotur
if (inputBatchFile.eof()) { input = "quit()"; }
else { input = getline(inputBatchFile); }
-
-
if (input[0] != '#') {
mothurOutEndLine();
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.");
globaldata->argv = path;
-
-
}
catch(exception& e) {
errorOut(e, "ScriptEngine", "ScriptEngine");
/***********************************************************************/
-ScriptEngine::~ScriptEngine(){
- }
+ScriptEngine::~ScriptEngine(){ }
/***********************************************************************/
//This Function allows the user to run a batchfile containing several commands on mothur
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.");