#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.
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 {
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){
/***********************************************************************/
-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.");