bbtkUtilities.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkUtilities.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2009/10/05 22:44:48 $
00006   Version:   $Revision: 1.14 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00032 #include "bbtkUtilities.h"
00033 #include "bbtkMessageManager.h"
00034 
00035 #if defined(MACOSX) // assume this is OSX 
00036 # include <sys/param.h>
00037 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line 
00038 # include <string.h>
00039 # ifndef PATH_MAX
00040 #  define PATH_MAX MAXPATHLEN
00041 # endif
00042 #endif // MACOSX
00043 
00044 #ifndef PATH_MAX // If not defined yet : do it 
00045 #  define PATH_MAX 2048
00046 #endif 
00047 
00048 namespace bbtk
00049 {
00050 
00051 
00052 
00053             // ======================================================================
00054     // See : http://www.techbytes.ca/techbyte103.html for more O.S.
00055     bool Utilities::FileExists(std::string strFilename) 
00056     {
00057       struct stat stFileInfo;
00058      bool blnReturn;
00059      int intStat;
00060      
00061      // Attempt to get the file attributes
00062      intStat = stat(strFilename.c_str(),&stFileInfo);
00063      if(intStat == 0) 
00064        {
00065          // We were able to get the file attributes
00066          // so the file obviously exists.
00067          blnReturn = true;
00068        } 
00069      else 
00070        {
00071          // We were not able to get the file attributes.
00072          // This may mean that we don't have permission to
00073          // access the folder which contains this file. If you
00074          // need to do that level of checking, lookup the
00075          // return values of stat which will give you
00076          // more details on why stat failed.
00077          blnReturn = false;
00078        }
00079      
00080      return(blnReturn);
00081     }
00082     
00083     
00084     // =====================================================================
00085     
00086     std::string Utilities::ExtractPackageName(const std::string  &name, 
00087                                           std::string& path)
00088     {
00089       std::string pkgname;
00090       path = "";
00091       
00092       std::string::size_type slash_position = name.find_last_of("/\\");
00093       if (slash_position != std::string::npos) 
00094         {
00095           pkgname = name.substr(slash_position+1,std::string::npos);
00096           path = name.substr(0,slash_position);
00097           //    std::cout << "F:P='"<<path<<"'"<<std::endl;//+1,std::string::npos);
00098         }
00099       else 
00100         {
00101           pkgname = name;
00102         }
00103       
00104       // remove {.so | dll} if any
00105       std::string::size_type dot_position = pkgname.find_last_of('.');      
00106       if (dot_position != std::string::npos){
00107         pkgname = pkgname.substr(0,dot_position);
00108       }      
00109 #if defined(__GNUC__)
00110       
00111       // GCC mechanism
00112       // shared lib name = libbb<name>.so
00113       
00114       // remove {libbb} if any
00115       if (memcmp ( pkgname.c_str(), "libbb", 5) == 0) {
00116         pkgname =  pkgname.substr(5, pkgname.length());
00117       }
00118       /*
00121       */
00122 #elif defined(_WIN32)
00123       
00124       // WIN 32 mechanism
00125       // shared lib name = <name>.dll
00126       
00127       // EED Problem loading package call bbtkTools
00128       //     // remove {bb} if any
00129       if (memcmp (pkgname.c_str(), "bb", 2) == 0) {
00130         pkgname =  pkgname.substr(2, pkgname.length());  
00131       }
00132       
00133       /*
00136      */
00137 #else
00138       bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
00139 #endif      
00140       return pkgname;
00141     }
00142     
00143     //=====================================================================
00144     std::string Utilities::ExtractScriptName(const std::string &name,
00145                                          std::string& path)
00146     {
00147       std::string pkgname;
00148       
00149       std::string::size_type slash_position = name.find_last_of("/\\");
00150       if (slash_position != std::string::npos) {
00151         pkgname =name.substr(slash_position+1,std::string::npos);
00152         path = name.substr(0,slash_position);      
00153       } else {
00154         pkgname = name;
00155       }
00156       // remove {.bbs } if any
00157       std::string::size_type dot_position = pkgname.find_last_of('.');
00158       if (dot_position != std::string::npos){
00159         pkgname = pkgname.substr(0,dot_position);
00160       }
00161       return pkgname;
00162     }
00163     
00164     // ========================================================================
00165 
00166     std::string Utilities::ExpandLibName(const std::string &name, bool verbose)
00167     {
00168       // -----   Think of expanding path name ( ./ ../ ../../ )
00169       
00170       char buf[2048]; // for getcwd
00171       char * currentDir = getcwd(buf, 2048);
00172       std::string cwd(currentDir);
00173       std::string libname(name);
00174       std::string fileSeparator;
00175       fileSeparator = ConfigurationFile::GetInstance().Get_file_separator();
00176       // tooHigh : true is user supplies a library pathname with too many "../"
00177       bool tooHigh = false;
00178       
00179       //std::cout << "------------------cwd ["  << cwd << "] name [" << name << "]" << std::endl;
00180       
00181       if ( name[0] == '/' ||  name[1] == ':' ) // Linux or Windows absolute name
00182         {
00183           return(libname);
00184         }
00185       else if  ( name =="." )
00186         {
00187           libname = cwd  + fileSeparator;
00188           return(libname);
00189         }
00190       else if  (name[0] == '.' && (name[1] == '/' || name[1] == '\\') )
00191         {
00192           libname = cwd  + fileSeparator + name.substr(2, name.length());
00193           return(libname);
00194         }
00195       else if ( name[0] == '.' &&  name[1] == '.' /*  && (name[2] == '/' || name[2] == '\\') */ ) 
00196         {
00197           if ( IsAtRoot(cwd) )  // hope it gets / (for Linux),  C: D: (for Windows)
00198       {  
00199      // if we are already at / or c: --> hopeless  
00200          if (verbose)
00201            std::cout << "   File path [" <<  name << "] doesn't exist" << std::endl;
00202          tooHigh = true;
00203       }
00204       else
00205       {
00206          // iterate on ../ and go up from the current working dir!
00207          std::string a(name); 
00208          bool alreadyProcessRoot = false;
00209 
00210           //if (a[a.size()-1] != fileSeparator[0])
00211           //   a.append(fileSeparator);
00212 //std::cout << "------------------a ["  << a << "]" << std::endl;
00213 
00214          for(;;)  // wild loop !
00215          {
00216             std::string::size_type slash_position = cwd.find_last_of(fileSeparator);
00217             if (slash_position != std::string::npos) {
00218              if (slash_position == 0)
00219                 slash_position = 1;
00220               cwd = cwd.substr(0,slash_position/*+1*/);
00221 //std::cout << "------------------cwd ["  << cwd << "]" << std::endl;
00222             //  if (a == "..") {
00223             //    a = "";
00224             //    break;
00225             //   }
00226             //   else
00227                  a = a.substr(3, /*name.length()*/ a.length());  // remove ../
00228 //std::cout << "------------------a ["  << a << "]" << std::endl;  
00229               if (a == "" || alreadyProcessRoot)
00230               {
00231                 if (verbose)
00232                   std::cout << "   File path : [" <<  name << "] doesn't exist" << std::endl;
00233                 tooHigh = true;
00234                 break;
00235               }
00236              // std::string b = cwd + a;
00237               libname =  cwd;
00238               char c = cwd[cwd.size()-1];
00239               if (c != '/' && c != '\\' )
00240                 libname += fileSeparator;
00241               libname += a;
00242 
00243               if ( a[0] != '.' ) // if . (probabely ../), loop again
00244                 break;
00245 
00246               if (IsAtRoot(cwd))
00247                 alreadyProcessRoot = true;
00248             }
00249          } // end iterating on ../
00250       }
00251 //std::cout << "------------------out of loop]" << std::endl;        
00252       if (tooHigh)
00253          libname="";
00254       return (libname);
00255 
00256     }  // -----   End of expanding path name   ( ./ ../ ../../ )
00257 
00258     std::cout <<"* ERROR in ExpandLibName : should never get here!" << std::endl;
00259     // To avoid warning
00260     return(""); // Will never get here!
00261   }
00262 
00263 // ===================================================================================
00264 
00265   std::string Utilities::MakeLibnameFromPath(std::string path, std::string pkgname)
00266   {
00267     std::string libname = path;
00268         if(path.size()>0){
00269                 char c = path[path.size()-1];    
00270 #if defined(__GNUC__)
00271        if (c != '/')
00272           libname += "/libbb";
00273        else
00274           libname += "libbb";
00275        libname += pkgname;
00276 #if defined(MACOSX)
00277           libname += ".dylib";
00278 #else
00279           libname += ".so";
00280 #endif  
00281           
00282 #elif defined(_WIN32)
00283        if (c != '\\') 
00284           libname += "\\bb";
00285        else
00286           libname += "bb";
00287        libname += pkgname;
00288        libname += ".dll";
00289 #endif
00290         }
00291     
00292     return libname;    
00293   }
00294 
00295 // ===================================================================================
00296 
00297   std::string Utilities::MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt)
00298   {
00299     std::string libname = path;
00300         if(path.size()>0){
00301                 char c = path[path.size()-1];
00302                 if (c != '/' && c != '\\')
00303                 {
00304                    libname +=  ConfigurationFile::GetInstance().Get_file_separator ();
00305                 }
00306                 libname += pkgname;
00307                 if (addExt)
00308                 {
00309                    int l = libname.size();
00310                    if (l>4)
00311                    {
00312                           if (libname.substr(l-4, 4) != ".bbs")
00313                           {
00314                                    libname = libname + ".bbs";
00315                           }
00316                    }
00317                 }
00318         }
00319     
00320     return libname;
00321   }
00322   // =======================================================================
00323 
00324   // =======================================================================
00326   std::string Utilities::GetUserSettingsDir()
00327   {
00328 #if defined(__GNUC__)
00329     std::string str_home(getenv("HOME"));
00330 #elif defined(_WIN32)
00331     std::string str_home(getenv("USERPROFILE"));
00332 #endif
00333     std::string fullname = str_home + "/.bbtk";
00334     MakeValidFileName(fullname);
00335     return fullname;
00336   }
00337   
00338 
00339   // =======================================================================
00342   std::string Utilities::MakeUserSettingsFullFileName(const std::string& name)
00343   {
00344 #if defined(__GNUC__)
00345     std::string str_home(getenv("HOME"));
00346 #elif defined(_WIN32)
00347     std::string str_home(getenv("USERPROFILE"));
00348 #endif
00349     std::string fullname = str_home + "/.bbtk/" + name;
00350     MakeValidFileName(fullname);
00351     return fullname;
00352   }
00353   // =======================================================================
00354   
00355 
00356   // =======================================================================
00357   void Utilities::CreateDirectoryIfNeeded( std::string const &dirName)
00358   {
00359     if (FileExists(dirName)) return;
00360     std::string cmd("mkdir \"");
00361     cmd += dirName;
00362     cmd += "\"";
00363     system(cmd.c_str());
00364   }  
00365   // =======================================================================
00366   
00367   
00368   //========================================================================
00369   bool Utilities::IsAtRoot(std::string cwd)
00370   {
00371     if ( cwd == "/"              // hope it gets /     (for Linux)
00372          || (cwd.size() <= 3 && cwd[1] == ':') ) // hope it gets C: D: (for Windows)
00373       return (true);
00374     else
00375       return(false);
00376   }
00377   // ======================================================================
00378 
00379   // ======================================================================
00380   bool Utilities::IsDirectory(std::string const &dirName)
00381   {
00382     struct stat fs;
00383     
00384     if ( stat(dirName.c_str(), &fs) == 0 )
00385       {
00386 #if _WIN32
00387         return ((fs.st_mode & _S_IFDIR) != 0);
00388 #else
00389         return S_ISDIR(fs.st_mode);
00390 #endif
00391       }
00392     else
00393       {
00394         return false;
00395       }
00396   }
00397   // =======================================================================
00398     
00399   // =======================================================================
00400   void Utilities::SplitAroundFirstDot( const std::string& in,
00401                                        std::string& left,
00402                                        std::string& right)
00403   {
00404     std::string delimiter = ".";
00405     std::string::size_type pos = in.find_first_of(delimiter);
00406     if (std::string::npos != pos) 
00407       {
00408         left = in.substr(0,pos);
00409         right = in.substr(pos+1,in.size());
00410         
00411       }
00412     else
00413       {
00414         left ="";
00415         right = "";
00416         bbtkGlobalError("Token '"<<in<<"' : expected 'a.b' format but no dot found");
00417       }
00418   }
00419   //=======================================================================
00420 
00421   //=======================================================================
00422   void Utilities::SplitString ( const std::string& str, 
00423                                 const std::string& delimiters, 
00424                                 std::vector<std::string>& tokens)
00425   {
00426     // Skip delimiters at beginning.
00427     std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00428     // Find first delimiter.
00429     std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
00430     
00431     while (std::string::npos != pos || std::string::npos != lastPos)
00432       {
00433         // Found a token, add it to the vector.
00434         tokens.push_back(str.substr(lastPos, pos - lastPos));
00435         // Skip delimiters.  Note the "not_of"
00436         lastPos = str.find_first_not_of(delimiters, pos);
00437         // Find next delimiter
00438         pos = str.find_first_of(delimiters, lastPos);
00439       }
00440     
00441   }
00442   //=======================================================================
00443   
00444   
00445   // ======================================================================
00446   std::string Utilities::get_file_name(const std::string& s) 
00447   { 
00448     std::string::size_type slash_position = s.find_last_of("/\\");
00449     if (slash_position != std::string::npos) 
00450       {
00451         return  s.substr(slash_position+1,std::string::npos);   
00452       }
00453     else 
00454       {
00455         return s;
00456       }
00457   }
00458   //=======================================================================
00459  
00460 
00461   // ========================================================================
00468   int Utilities::Explore(std::string const &dirpath, bool recursive, std::vector<std::string> &Filenames)
00469   {
00470     int numberOfFiles = 0;
00471     std::string fileName;
00472       
00473       std::string dirName = dirpath;
00474       
00475 #ifdef _MSC_VER
00476       WIN32_FIND_DATA fileData;
00477    HANDLE hFile = FindFirstFile((dirName+"\\*").c_str(), &fileData);
00478 
00479    for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
00480        b = FindNextFile(hFile, &fileData))
00481    {
00482       fileName = fileData.cFileName;
00483       if ( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
00484       {
00485          // Need to check for . and .. to avoid infinite loop
00486          if ( fileName != "." && fileName != ".." && recursive )
00487          {
00488             numberOfFiles += Explore(dirName+ "\\"+fileName,recursive,Filenames);
00489          }
00490       }
00491       else
00492       {
00493          Filenames.push_back(dirName+"\\"+fileName);
00494          numberOfFiles++;
00495       }
00496    }
00497    DWORD dwError = GetLastError();
00498    if (hFile != INVALID_HANDLE_VALUE) 
00499       FindClose(hFile);
00500    if (dwError != ERROR_NO_MORE_FILES) 
00501    {
00502       LPVOID lpMsgBuf;
00503       FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
00504                     FORMAT_MESSAGE_FROM_SYSTEM|
00505                     FORMAT_MESSAGE_IGNORE_INSERTS,
00506                     NULL,GetLastError(),
00507                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00508                     (LPTSTR) &lpMsgBuf,0,NULL);
00509 
00510      // ErrorMacro("FindNextFile error. Error is " << (char *)lpMsgBuf
00511      //             <<" for the directory : "<<dirName);
00512       
00513       return 0;
00514    }
00515 
00516 #else
00517   // Real POSIX implementation: scandir is a BSD extension only, and doesn't 
00518   // work on debian for example
00519 //std::cout <<"in Explor dirname[" << dirName << "]" << std::endl; 
00520    DIR* dir = opendir(dirName.c_str());
00521    if (!dir)
00522    {
00523       return 0;
00524    }
00525 //std::cout <<"Open OK" << std::endl; 
00526    // According to POSIX, the dirent structure contains a field char d_name[]
00527    // of unspecified size, with at most NAME_MAX characters preceeding the
00528    // terminating null character. Use of other fields will harm the  porta-
00529    // bility of your programs.
00530 
00531    struct stat buf;
00532    dirent *d;
00533    for (d = readdir(dir); d; d = readdir(dir))
00534    {
00535       fileName = dirName + "/" + d->d_name;
00536 //std::cout <<"in Explor filename[" << fileName << "]" << std::endl;      
00537       if( stat(fileName.c_str(), &buf) != 0 )
00538       {
00539          //ErrorMacro( strerror(errno) );
00540       }
00541       if ( S_ISREG(buf.st_mode) )    //is it a regular file?
00542       {
00543          Filenames.push_back( fileName );
00544          numberOfFiles++;
00545       }
00546       else if ( S_ISDIR(buf.st_mode) ) //directory?
00547       {
00548          if ( d->d_name[0] != '.' && recursive ) //we also skip hidden files
00549          {
00550             numberOfFiles += Explore( fileName, recursive, Filenames);
00551          }
00552       }
00553       else
00554       {
00555          //ErrorMacro( "Unexpected error" );
00556          return -1;
00557       }
00558    }
00559    if( closedir(dir) != 0 )
00560    {
00561      // ErrorMacro( strerror(errno) );
00562    }
00563 #endif
00564 
00565   return numberOfFiles;
00566 
00567 }
00568   //=======================================================================
00569  
00570 
00571     //=======================================================================
00572     // Replaces substrings "\\n" by a real carriage return "\n"
00573     void Utilities::SubsBackslashN ( std::string& s )
00574     {
00575       std::string ss("\\n");
00576       std::string::size_type pos = 0;
00577       pos = s.find(ss,0);
00578       const char* cr = "\n";
00579       while ( pos != std::string::npos )
00580         {
00581           s.replace(pos,2,cr,1);
00582           pos = s.find(ss, pos-1);
00583         }
00584     }
00585     //=======================================================================
00586 
00587 
00588    //=======================================================================
00589 
00590   bool Utilities::loosematch(std::string stdLine,std::string stdOptions) 
00591   {
00592     bool result=false;
00593     std::vector<std::string> tokens;
00594     SplitString ( stdOptions,"|", tokens);
00595     int i,size=tokens.size();  
00596     for (i=0; i<size; i++)
00597       {           
00598 #ifdef WIN32
00599         if ( strcmpi(stdLine.c_str(),tokens[i].c_str())==0) 
00600           { 
00601             result=true; 
00602           }               
00603 #else
00604         if ( strcasecmp(stdLine.c_str(),tokens[i].c_str())==0) 
00605           { 
00606             result=true; 
00607           }               
00608 #endif
00609         
00610       }
00611     return result;
00612   }
00613   //=========================================================================  
00614   
00615   //=========================================================================  
00616   // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083
00617   //
00618   int get_app_path (char *pname, size_t pathsize)
00619   {
00620 #ifdef LINUX
00621     /* Oddly, the readlink(2) man page says no NULL is appended. */
00622     /* So you have to do it yourself, based on the return value: */
00623     pathsize --; /* Preserve a space to add the trailing NULL */
00624     long result = readlink("/proc/self/exe", pname, pathsize);
00625     if (result > 0)
00626       {
00627         pname[result] = 0; /* add the #@!%ing NULL */
00628         
00629         if ((access(pname, 0) == 0))
00630           return 0; /* file exists, return OK */
00631         /*else name doesn't seem to exist, return FAIL (falls
00632           through) */
00633       }
00634 #endif /* LINUX */
00635     
00636 #ifdef WIN32
00637     long result = GetModuleFileName(NULL, pname, pathsize);
00638     if (result > 0)
00639       {
00640         /* fix up the dir slashes... */
00641         int len = strlen(pname);
00642         int idx;
00643         for (idx = 0; idx < len; idx++)
00644           {
00645             if (pname[idx] == '\\') pname[idx] = '/';
00646           }
00647         
00648         for (idx = len-1; idx >=0 ; idx--)
00649           {
00650             if (pname[idx] == '/')
00651               { 
00652                 pname[idx+1] = '\0';
00653                 idx = -1;
00654               }
00655           }
00656         
00657         if ((access(pname, 0) == 0))
00658           return 0; /* file exists, return OK */
00659         /*else name doesn't seem to exist, return FAIL (falls
00660           through) */
00661       }
00662 #endif /* WIN32 */
00663     
00664 #ifdef SOLARIS
00665     char *p = getexecname();
00666     if (p)
00667       {
00668         /* According to the Sun manpages, getexecname will
00669            "normally" return an */
00670         /* absolute path - BUT might not... AND that IF it is not,
00671            pre-pending */
00672         /* getcwd() will "usually" be the correct thing... Urgh!
00673          */
00674         
00675         /* check pathname is absolute (begins with a / ???) */
00676         if (p[0] == '/') /* assume this means we have an
00677                             absolute path */
00678           {
00679             strncpy(pname, p, pathsize);
00680             if ((access(pname, 0) == 0))
00681               return 0; /* file exists, return OK */
00682           }
00683         else /* if not, prepend getcwd() then check if file
00684                 exists */
00685           {
00686             getcwd(pname, pathsize);
00687             long result = strlen(pname);
00688             strncat(pname, "/", (pathsize - result));
00689             result ++;
00690             strncat(pname, p, (pathsize - result));
00691             
00692             if ((access(pname, 0) == 0))
00693               return 0; /* file exists, return OK */
00694             /*else name doesn't seem to exist, return FAIL
00695               (falls through) */
00696           }
00697       }
00698 #endif /* SOLARIS */
00699     
00700 #ifdef MACOSX /* assume this is OSX */
00701     /*
00702       from http://www.hmug.org/man/3/NSModule.html
00703       
00704       extern int _NSGetExecutablePath(char *buf, unsigned long
00705       *bufsize);
00706       
00707       _NSGetExecutablePath  copies  the  path  of the executable
00708       into the buffer and returns 0 if the path was successfully
00709       copied  in the provided buffer. If the buffer is not large
00710       enough, -1 is returned and the  expected  buffer  size  is
00711       copied  in  *bufsize.  Note that _NSGetExecutablePath will
00712       return "a path" to the executable not a "real path" to the
00713       executable.  That  is  the path may be a symbolic link and
00714       not the real file. And with  deep  directories  the  total
00715       bufsize needed could be more than MAXPATHLEN.
00716     */
00717     int status = -1;
00718     char *given_path = (char*)malloc(MAXPATHLEN * 2);
00719     if (!given_path) return status;
00720     
00721     uint32_t npathsize = MAXPATHLEN * 2;
00722     long result = _NSGetExecutablePath(given_path, &npathsize);
00723     if (result == 0)
00724       { /* OK, we got something - now try and resolve the real path...
00725          */
00726         if (realpath(given_path, pname) != NULL)
00727           {
00728             if ((access(pname, 0) == 0))
00729               status = 0; /* file exists, return OK */
00730           }
00731       }
00732     free (given_path);
00733     return status;
00734 #endif /* MACOSX */
00735     
00736     return -1; /* Path Lookup Failed */
00737   } 
00738   //=========================================================================
00739         
00740 
00741         
00742   //=========================================================================
00743   std::string Utilities::GetExecutablePath()
00744   {
00745     char name[PATH_MAX];
00746     int err = get_app_path(name, PATH_MAX);
00747     if (err) 
00748       {
00749         bbtkGlobalError("Could not determine current executable path ?");  
00750       }
00751     
00752     // remove the exe name
00753     char *slash;                
00754     slash = strrchr(name, VALID_FILE_SEPARATOR_CHAR);
00755     if (slash)
00756       {
00757         *slash = 0;
00758       }
00759     return name;
00760   }
00761   //=========================================================================
00762 
00763 
00764 
00765 }

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1