X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=engine.cpp;h=54197174e1fa3da14861614734b1dc58314a466a;hb=a4f05f09c250323132a4b9427f41a3ededaec634;hp=ad7a7ad73ad03660976137117b15035d2d2b4757;hpb=4b6e3f7b5543822a2cca4fb076ab6af2ce8ca62d;p=mothur.git diff --git a/engine.cpp b/engine.cpp index ad7a7ad..5419717 100644 --- a/engine.cpp +++ b/engine.cpp @@ -25,19 +25,12 @@ Engine::Engine(){ exit(1); } } - /***********************************************************************/ - -InteractEngine::InteractEngine(string path){ - - globaldata = GlobalData::getInstance(); - - string temppath = path.substr(0, (path.find_last_of('m'))); - - //this will happen if you set the path variable to contain mothur's exe location - if (temppath == "") { - +string Engine::findMothursPath(){ + try { + string envPath = getenv("PATH"); + string mothurPath = ""; //delimiting path char char delim; @@ -52,7 +45,6 @@ InteractEngine::InteractEngine(string path){ mout->splitAtChar(envPath, dirs, delim); //get path related to mothur - string mothurPath = ""; for (int i = 0; i < dirs.size(); i++) { //to lower so we can find it string tempLower = ""; @@ -62,15 +54,53 @@ InteractEngine::InteractEngine(string path){ if (tempLower.find("mothur") != -1) { mothurPath = dirs[i]; break; } } - //add mothur so it looks like what argv would look like - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - mothurPath += "/mothur"; - #else - mothurPath += "\\mothur"; - #endif + if (mothurPath != "") { + //add mothur so it looks like what argv would look like + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + mothurPath += "/mothur"; + #else + mothurPath += "\\mothur"; + #endif + }else { + //okay mothur is not in the path, so the folder mothur is in must be in the path + //lets find out which one + + //get path related to mothur + for (int i = 0; i < dirs.size(); i++) { + + //is this mothurs path? + ifstream in; + string tempIn = dirs[i]; + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + tempIn += "/mothur"; + #else + tempIn += "\\mothur"; + #endif + mout->openInputFile(tempIn, in, ""); + + //if this file exists + if (in) { in.close(); mothurPath = tempIn; break; } + } + } + + return mothurPath; - path = mothurPath; } + catch(exception& e) { + mout->errorOut(e, "Engine", "findMothursPath"); + exit(1); + } +} +/***********************************************************************/ + +InteractEngine::InteractEngine(string path){ + + globaldata = GlobalData::getInstance(); + + string temppath = path.substr(0, (path.find_last_of("othur")-5)); + + //this will happen if you set the path variable to contain mothur's exe location + if (temppath == "") { path = findMothursPath(); } globaldata->argv = path; } @@ -152,6 +182,10 @@ bool InteractEngine::getInput(){ //executes valid command Command* command = cFactory->getCommand(commandName, options); quitCommandCalled = command->execute(); + + //if we aborted command + if (quitCommandCalled == 2) { mout->mothurOut("[ERROR]: did not complete " + commandName + "."); mout->mothurOutEndLine(); } + mout->control_pressed = 0; mout->executing = false; @@ -220,46 +254,11 @@ BatchEngine::BatchEngine(string path, string batchFileName){ openedBatch = mout->openInputFile(batchFileName, inputBatchFile); - string temppath = path.substr(0, (path.find_last_of('m'))); + string temppath = path.substr(0, (path.find_last_of("othur")-5)); //this will happen if you set the path variable to contain mothur's exe location - if (temppath == "") { + if (temppath == "") { path = findMothursPath(); } - string envPath = getenv("PATH"); - - //delimiting path char - char delim; - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - delim = ':'; - #else - delim = ';'; - #endif - - //break apart path variable by ':' - vector dirs; - mout->splitAtChar(envPath, dirs, delim); - - //get path related to mothur - string mothurPath = ""; - for (int i = 0; i < dirs.size(); i++) { - //to lower so we can find it - string tempLower = ""; - for (int j = 0; j < dirs[i].length(); j++) { tempLower += tolower(dirs[i][j]); } - - //is this mothurs path? - if (tempLower.find("mothur") != -1) { mothurPath = dirs[i]; break; } - } - - //add mothur so it looks like what argv would look like - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - mothurPath += "/mothur"; - #else - mothurPath += "\\mothur"; - #endif - - path = mothurPath; - } - globaldata->argv = path; } @@ -291,7 +290,7 @@ bool BatchEngine::getInput(){ //CommandFactory cFactory; int quitCommandCalled = 0; int count = 0; - while(quitCommandCalled == 0){ + while(quitCommandCalled != 1){ #ifdef USE_MPI int pid, processors; @@ -358,6 +357,10 @@ bool BatchEngine::getInput(){ //executes valid command Command* command = cFactory->getCommand(commandName, options); quitCommandCalled = command->execute(); + + //if we aborted command + if (quitCommandCalled == 2) { mout->mothurOut("[ERROR]: did not complete " + commandName + "."); mout->mothurOutEndLine(); } + mout->control_pressed = 0; mout->executing = false; @@ -408,46 +411,11 @@ ScriptEngine::ScriptEngine(string path, string commandString){ //remove quotes listOfCommands = commandString.substr(1, (commandString.length()-1)); - string temppath = path.substr(0, (path.find_last_of('m'))); - + string temppath = path.substr(0, (path.find_last_of("othur")-5)); + //this will happen if you set the path variable to contain mothur's exe location - if (temppath == "") { + if (temppath == "") { path = findMothursPath(); } - string envPath = getenv("PATH"); - - //delimiting path char - char delim; - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - delim = ':'; - #else - delim = ';'; - #endif - - //break apart path variable by ':' - vector dirs; - mout->splitAtChar(envPath, dirs, delim); - - //get path related to mothur - string mothurPath = ""; - for (int i = 0; i < dirs.size(); i++) { - //to lower so we can find it - string tempLower = ""; - for (int j = 0; j < dirs[i].length(); j++) { tempLower += tolower(dirs[i][j]); } - - //is this mothurs path? - if (tempLower.find("mothur") != -1) { mothurPath = dirs[i]; break; } - } - - //add mothur so it looks like what argv would look like - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - mothurPath += "/mothur"; - #else - mothurPath += "\\mothur"; - #endif - - path = mothurPath; - } - globaldata->argv = path; } @@ -474,7 +442,7 @@ bool ScriptEngine::getInput(){ //CommandFactory cFactory; int quitCommandCalled = 0; - while(quitCommandCalled == 0){ + while(quitCommandCalled != 1){ #ifdef USE_MPI int pid, processors; @@ -542,6 +510,10 @@ bool ScriptEngine::getInput(){ //executes valid command Command* command = cFactory->getCommand(commandName, options); quitCommandCalled = command->execute(); + + //if we aborted command + if (quitCommandCalled == 2) { mout->mothurOut("[ERROR]: did not complete " + commandName + "."); mout->mothurOutEndLine(); } + mout->control_pressed = 0; mout->executing = false;