X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkUtilities.h;h=2e771a94baca939286ac7941fb263774b738e661;hb=fb4178612a6d5b670bb5991d4427ddd7b7bcd6ae;hp=d9c3193a0a07eac9f7c8cdcefb62fed751a76e84;hpb=6990a8aeeaf98fc901ed193b95365b2eee2fb950;p=bbtk.git diff --git a/kernel/src/bbtkUtilities.h b/kernel/src/bbtkUtilities.h index d9c3193..2e771a9 100644 --- a/kernel/src/bbtkUtilities.h +++ b/kernel/src/bbtkUtilities.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkUtilities.h,v $ Language: C++ - Date: $Date: 2008/01/22 16:55:04 $ - Version: $Revision: 1.2 $ + Date: $Date: 2008/01/28 09:12:49 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -39,11 +39,17 @@ #define BBTK_USE_TERMIOS_BASED_PROMPT #endif +//#include "bbtkMessageManager.h" + namespace bbtk { /// Holds various usefull methods struct BBTK_EXPORT Utilities { + + +// =================================================================================== + // See : http://www.techbytes.ca/techbyte103.html for more O.S. static inline bool FileExists(std::string strFilename) { @@ -81,23 +87,23 @@ namespace bbtk std::string::size_type slash_position = name.find_last_of("/\\"); if (slash_position != std::string::npos) - { - pkgname = name.substr(slash_position+1,std::string::npos); - path = name.substr(0,slash_position); - // std::cout << "F:P='"<.so @@ -117,8 +123,8 @@ namespace bbtk // remove {bb} if any if (memcmp (pkgname.c_str(), "bb", 2) == 0) { pkgname = pkgname.substr(2, pkgname.length()); - } - + } + /* /// \ \todo what would happen if (stupid) user names his package 'bb' ?!? /// \ --> Should be forbidden! @@ -159,20 +165,28 @@ namespace bbtk char * currentDir = getcwd(buf, 2048); std::string cwd(currentDir); std::string libname(name); - + std::string fileSeparator; + fileSeparator = ConfigurationFile::GetInstance().Get_file_separator(); // tooHigh : true is user supplies a library pathname with too many "../" bool tooHigh = false; - + +//std::cout << "------------------cwd [" << cwd << "]" << std::endl; + if ( name[0] == '/' || name[0] == '\\' ) { return(libname); - } - else if (name[0] == '.' && (name[1] == '/' || name[1] == '\\') ) + } + else if ( name =="." ) { - libname = cwd + ConfigurationFile::GetInstance().Get_file_separator () + name.substr(2, name.length()); + libname = cwd + fileSeparator; return(libname); - } - else if ( name[0] == '.' && name[1] == '.' && (name[2] == '/' || name[2] == '\\') ) + } + 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) { @@ -186,18 +200,30 @@ namespace bbtk // iterate on ../ and go up from the current working dir! std::string a(name); bool alreadyProcessRoot = false; - for(;;) + + //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(ConfigurationFile::GetInstance().Get_file_separator ()); + 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*/); - a = a.substr(3, name.length()); // remove ../ +//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; + std::cout << " File path : [" << name << "] doesn't exist" << std::endl; tooHigh = true; break; } @@ -205,7 +231,7 @@ namespace bbtk libname = cwd; char c = cwd[cwd.size()-1]; if (c != '/' && c != '\\' ) - libname += ConfigurationFile::GetInstance().Get_file_separator (); + libname += fileSeparator; libname += a; if ( a[0] != '.' ) // if . (probabely ../), loop again @@ -216,12 +242,14 @@ namespace bbtk } } // 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! } @@ -235,6 +263,8 @@ namespace bbtk #if defined(__GNUC__) if (c != '/') libname += "/libbb"; + else + libname += "libbb"; libname += pkgname; libname += ".so"; @@ -271,6 +301,7 @@ namespace bbtk return(false); } + // =================================================================================== static inline void SplitAroundFirstDot( const std::string& in, @@ -285,16 +316,16 @@ namespace bbtk right = in.substr(pos+1,in.size()); } - /* else { - bbtkError(in<<" : expected 'a.b' format but no dot found"); + // bbtkError(in<<" : expected 'a.b' format but no dot found"); + left =""; + right = ""; } - */ - left =""; - right = ""; } +// =================================================================================== + static inline std::string get_file_name(const std::string& s) { std::string::size_type slash_position = s.find_last_of("/\\"); @@ -310,9 +341,9 @@ namespace bbtk //======================================================================== - // Usefull functions for html generation - - //======================================================================== + // Usefull functions for html generation + //======================================================================== + static inline void replace( std::string& str, const std::string& from, const std::string& to ) @@ -327,7 +358,6 @@ namespace bbtk } //======================================================================== - //======================================================================== static inline void html_format(std::string& str) { replace( str, "&", "&" );