-//std::cout << "------------------cwd [" << cwd << "] name [" << name << "]" << std::endl;
-
- if ( name[0] == '/' || name[1] == ':' ) // Linux or Windows absolute name
- {
- return(libname);
- }
- else if ( name =="." )
- {
- libname = cwd + fileSeparator;
- return(libname);
- }
- else if (name[0] == '.' && (name[1] == '/' || name[1] == '\\') )
- {
- libname = cwd + fileSeparator + name.substr(2, name.length());
- return(libname);
- }
- else if ( name[0] == '.' && name[1] == '.' /* && (name[2] == '/' || name[2] == '\\') */ )
- {
- if ( IsAtRoot(cwd) ) // hope it gets / (for Linux), C: D: (for Windows)
- {
- // if we are already at / or c: --> hopeless
- if (verbose)
- std::cout << " File path [" << name << "] doesn't exist" << std::endl;
- tooHigh = true;
- }
- else
- {
- // iterate on ../ and go up from the current working dir!
- std::string a(name);
- bool alreadyProcessRoot = false;
-
- //if (a[a.size()-1] != fileSeparator[0])
- // a.append(fileSeparator);
-//std::cout << "------------------a [" << a << "]" << std::endl;
-
- for(;;) // wild loop !
- {
- std::string::size_type slash_position = cwd.find_last_of(fileSeparator);
- if (slash_position != std::string::npos) {
- if (slash_position == 0)
- slash_position = 1;
- cwd = cwd.substr(0,slash_position/*+1*/);
-//std::cout << "------------------cwd [" << cwd << "]" << std::endl;
- // if (a == "..") {
- // a = "";
- // break;
- // }
- // else
- a = a.substr(3, /*name.length()*/ a.length()); // remove ../
-//std::cout << "------------------a [" << a << "]" << std::endl;
- if (a == "" || alreadyProcessRoot)
- {
- if (verbose)
- std::cout << " File path : [" << name << "] doesn't exist" << std::endl;
- tooHigh = true;
- break;
- }
- // std::string b = cwd + a;
- libname = cwd;
- char c = cwd[cwd.size()-1];
- if (c != '/' && c != '\\' )
- libname += fileSeparator;
- libname += a;
-
- if ( a[0] != '.' ) // if . (probabely ../), loop again
- break;
-
- if (IsAtRoot(cwd))
- alreadyProcessRoot = true;
- }
- } // end iterating on ../
- }
-//std::cout << "------------------out of loop]" << std::endl;
- if (tooHigh)
- libname="";
- return (libname);
-
- } // ----- End of expanding path name ( ./ ../ ../../ )
-
- std::cout <<"* ERROR in ExpandLibName : should never get here!" << std::endl;
- // To avoid warning
- return(""); // Will never get here!
- }
-
-// ===================================================================================
-
- static std::string MakeLibnameFromPath(std::string path, std::string pkgname)
- {
- std::string libname = path;
- char c = path[path.size()-1];
-#if defined(__GNUC__)
- if (c != '/')
- libname += "/libbb";
- else
- libname += "libbb";
- libname += pkgname;
- libname += ".so";
-
-#elif defined(_WIN32)
- if (c != '\\')
- libname = path+"\\bb";
- libname += pkgname;
- libname += ".dll";
-#endif
- return libname;
- }
-
-// ===================================================================================
-
- static inline std::string MakePkgnameFromPath(std::string path, std::string pkgname, bool addExt)
- {
- std::string libname = path;
- char c = path[path.size()-1];
- if (c != '/' && c != '\\')
- {
- libname += ConfigurationFile::GetInstance().Get_file_separator ();
- }
- libname += pkgname;
- if (addExt)
- {
- int l = libname.size();
- if (l>4)
- {
- if (libname.substr(l-4, 4) != ".bbs")
- {
- libname = libname + ".bbs";
- }
- }
- }
- return libname;
- }
-
-// ===================================================================================
-
- static inline bool IsAtRoot(std::string cwd)
- {
- if ( cwd == "/" // hope it gets / (for Linux)
- || (cwd.size() <= 3 && cwd[1] == ':') ) // hope it gets C: D: (for Windows)
- return (true);
- else
- return(false);
- }
-
-// ===================================================================================
-
-static bool IsDirectory(std::string const &dirName)
-{
- struct stat fs;
-
- if ( stat(dirName.c_str(), &fs) == 0 )
- {
-#if _WIN32
- return ((fs.st_mode & _S_IFDIR) != 0);
-#else
- return S_ISDIR(fs.st_mode);
-#endif
- }
- else
- {
- return false;
- }
-}
-
-// ===================================================================================
-
- static inline void SplitAroundFirstDot( const std::string& in,
- std::string& left,
- std::string& right)
- {
- std::string delimiter = ".";
- std::string::size_type pos = in.find_first_of(delimiter);
- if (std::string::npos != pos)
- {
- left = in.substr(0,pos);
- right = in.substr(pos+1,in.size());
-
- }
- else
- {
- // bbtkError(in<<" : expected 'a.b' format but no dot found");
- left ="";
- right = "";
- }
- }
-
-// ===================================================================================
-
- static inline std::string get_file_name(const std::string& s)
- {
- std::string::size_type slash_position = s.find_last_of("/\\");
- if (slash_position != std::string::npos)
- {
- return s.substr(slash_position+1,std::string::npos);
- }
- else
- {
- return s;
- }
- }