]> git.donarmstrong.com Git - mothur.git/blobdiff - engine.cpp
modified the engine to extract the path of mothur executable if argv does not contain...
[mothur.git] / engine.cpp
index 7bacec5c0e757c7b77d3c8801970c17bd3cc5a4a..fbf986dc6965de7d9d269c31f35e99ed85467a9d 100644 (file)
@@ -31,8 +31,48 @@ Engine::Engine(){
 InteractEngine::InteractEngine(string path){
 
        globaldata = GlobalData::getInstance();
-       globaldata->argv = path;
        
+       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 envPath = getenv("PATH");
+               
+               //delimiting path char
+               char delim;
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       delim = ':';
+               #else
+                       delim = ';';
+               #endif
+               
+               //break apart path variable by ':'
+               vector<string> dirs;
+               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;
 }
 
 /***********************************************************************/
@@ -179,6 +219,47 @@ BatchEngine::BatchEngine(string path, string batchFileName){
                globaldata = GlobalData::getInstance();
        
                openedBatch = openInputFile(batchFileName, inputBatchFile);
+               
+               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 envPath = getenv("PATH");
+                       
+                       //delimiting path char
+                       char delim;
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               delim = ':';
+                       #else
+                               delim = ';';
+                       #endif
+                       
+                       //break apart path variable by ':'
+                       vector<string> dirs;
+                       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;
                                
        }
@@ -326,6 +407,46 @@ 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')));
+       
+               //this will happen if you set the path variable to contain mothur's exe location
+               if (temppath == "") { 
+               
+                       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<string> dirs;
+                       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;