]> git.donarmstrong.com Git - mothur.git/blobdiff - mothur.h
chimeracode
[mothur.git] / mothur.h
index 8065dd4cc74284f11dbca4808eb2c8893a74b7c8..5f8a2fe75b41d57e345d50cb63606921c866ff67 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -433,8 +433,8 @@ inline string getPathName(string longName){
  
        string rootPathName = longName;
        
-       if(longName.find_last_of('/') != longName.npos){
-               int pos = longName.find_last_of('/')+1;
+       if(longName.find_last_of("/\\") != longName.npos){
+               int pos = longName.find_last_of("/\\")+1;
                rootPathName = longName.substr(0, pos);
        }
        
@@ -487,7 +487,7 @@ inline bool isBlank(string fileName){
 /***********************************************************************/
 
 inline string getFullPathName(string fileName){
-       
+       try{
        string path = hasPath(fileName);
        string newFileName;
        int pos;
@@ -503,11 +503,13 @@ inline string getFullPathName(string fileName){
                        if (path.rfind("./") == -1) { return fileName; } //already complete name
                        else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name
                        
-                       char* cwdpath;
+                       char* cwdpath = new char[1024];
+
                        size_t size;
                        cwdpath=getcwd(cwdpath,size);
-                       cwd = cwdpath;
                
+                       cwd = cwdpath;
+                       
                        //rip off first '/'
                        string simpleCWD;
                        if (cwd.length() > 0) { simpleCWD = cwd.substr(1); }
@@ -521,9 +523,10 @@ inline string getFullPathName(string fileName){
                        }
                        //get last one              // ex. ../../../filename = /user/work/desktop/filename
                        dirs.push_back(simpleCWD);  //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
-                               
+                       
+               
                        int index = dirs.size()-1;
-                               
+               
                        while((pos = path.rfind("./")) != -1) { //while you don't have a complete path
                                if (path[(pos-1)] == '.') { //you want your parent directory ../
                                        path = path.substr(0, pos-1);
@@ -583,6 +586,12 @@ inline string getFullPathName(string fileName){
                        
                #endif
        }
+       }
+       catch(exception& e) {
+               errorOut(e, "getFullPathName", "getFullPathName");
+               exit(1);
+       }
+       
        
 }
 /***********************************************************************/
@@ -591,26 +600,22 @@ inline int openInputFile(string fileName, ifstream& fileHandle, string m){
        
        //get full path name
        string completeFileName = getFullPathName(fileName);
-       //string completeFileName = fileName;
 
        fileHandle.open(completeFileName.c_str());
        if(!fileHandle) {
-               mothurOut("Error: Could not open " + completeFileName);  mothurOutEndLine();
                return 1;
-       }
-       else {
+       }else {
                //check for blank file
                gobble(fileHandle);
                return 0;
-       }
-       
+       }       
 }
 /***********************************************************************/
 
 inline int openInputFile(string fileName, ifstream& fileHandle){
        //get full path name
        string completeFileName = getFullPathName(fileName);
-       
+
        fileHandle.open(completeFileName.c_str());
        if(!fileHandle) {
                mothurOut("Error: Could not open " + completeFileName);  mothurOutEndLine();
@@ -625,6 +630,28 @@ inline int openInputFile(string fileName, ifstream& fileHandle){
        }
        
 }
+/***********************************************************************/
+
+inline int renameFile(string oldName, string newName){
+       
+       ifstream inTest;
+       int exist = openInputFile(newName, inTest, "");
+       
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)          
+       if (exist == 0) { //you could open it so you want to delete it
+               inTest.close();
+               string command = "rm " + newName;
+               system(command.c_str());
+       }
+                       
+       string command = "mv " + oldName + " " + newName;
+       system(command.c_str());
+#else
+       remove(newName.c_str());
+       int renameOk = rename(oldName.c_str(), newName.c_str());
+#endif
+       return 0;
+}
 
 /***********************************************************************/
 
@@ -804,6 +831,21 @@ inline bool inUsersGroups(string groupname, vector<string> Groups) {
                exit(1);
        }
 }
+/**************************************************************************************************/
+//returns true if any of the strings in first vector are in second vector
+inline bool inUsersGroups(vector<string> groupnames, vector<string> Groups) {
+       try {
+               
+               for (int i = 0; i < groupnames.size(); i++) {
+                       if (inUsersGroups(groupnames[i], Groups)) { return true; }
+               }
+               return false;
+       }
+       catch(exception& e) {
+               errorOut(e, "mothur", "inUsersGroups");
+               exit(1);
+       }
+}
 
 /**************************************************************************************************/