+ScriptEngine::~ScriptEngine(){ }
+
+/***********************************************************************/
+//This Function allows the user to run a batchfile containing several commands on mothur
+bool ScriptEngine::getInput(){
+ try {
+
+ string input = "";
+ string commandName = "";
+ string options = "";
+
+
+ //CommandFactory cFactory;
+ int quitCommandCalled = 0;
+
+ while(quitCommandCalled == 0){
+
+ input = getNextCommand(listOfCommands);
+
+ if (input == "") { input = "quit()"; }
+
+ mout->mothurOutEndLine();
+ mout->mothurOut("mothur > " + input);
+ mout->mothurOutEndLine();
+
+ if (mout->control_pressed) { input = "quit()"; }
+
+ //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 != "") {
+ mout->executing = true;
+ #ifdef USE_MPI
+ int pid, numProcesses;
+ MPI_Status status;
+
+ MPI_Comm_rank(MPI_COMM_WORLD, &pid);
+ MPI_Comm_size(MPI_COMM_WORLD, &numProcesses);
+
+cout << pid << " is here " << commandName << endl;
+ if ((cFactory->MPIEnabled(commandName)) || (pid == 0)) {
+ cout << pid << " is in execute" << endl;
+ #endif
+ //executes valid command
+ Command* command = cFactory->getCommand(commandName, options);
+ quitCommandCalled = command->execute();
+ mout->control_pressed = 0;
+ mout->executing = false;
+
+ #ifdef USE_MPI
+ cout << pid << " is done in execute" << endl;
+ }
+ #endif
+ }else {
+ mout->mothurOut("Invalid.");
+ mout->mothurOutEndLine();
+ }
+
+
+ }
+
+ return 1;
+ }
+ catch(exception& e) {
+ mout->errorOut(e, "ScriptEngine", "getInput");
+ exit(1);
+ }
+}
+/***********************************************************************/
+string ScriptEngine::getNextCommand(string& commandString) {
+ try {
+
+ #ifdef USE_MPI
+ MPI_Barrier(MPI_COMM_WORLD);
+ #endif
+
+ string nextcommand = "";
+ int count = 0;
+
+ //go through string until you reach ; or end
+ while (count < commandString.length()) {
+
+ if (commandString[count] == ';') { break; }
+ else { nextcommand += commandString[count]; }
+
+ count++;
+ }
+
+ //if you are not at the end
+ if (count != commandString.length()) { commandString = commandString.substr(count+1, commandString.length()); }
+ else { commandString = ""; }
+
+
+ //get rid of spaces in between commands if any
+ if (commandString.length() > 0) {
+ while (commandString[0] == ' ') {
+ commandString = commandString.substr(1,commandString.length());
+ if (commandString.length() == 0) { break; }
+ }
+ }
+
+ return nextcommand;
+ }
+ catch(exception& e) {
+ mout->errorOut(e, "ScriptEngine", "getNextCommand");
+ exit(1);
+ }
+}
+/***********************************************************************/