diff options
author | Rüdiger Timm <rt@openoffice.org> | 2008-06-06 08:30:58 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2008-06-06 08:30:58 +0000 |
commit | 11a03a221adcaa12e4ff57c2c7e7d8a7467c2068 (patch) | |
tree | b69d6cdd3ab1047f488b60652419541db9840e51 /testshl2 | |
parent | 89503139682dddcd7090272be4746d756ba92df8 (diff) |
INTEGRATION: CWS ause093 (1.9.6); FILE MERGED
2008/05/07 11:10:44 lla 1.9.6.3: #i88845# cleanup, for load library locally or absolutely
2008/05/06 12:08:20 hjs 1.9.6.2: #i88845# set of changes from lla to get specified library loaded
2008/05/06 06:42:35 lla 1.9.6.1: #i88845# changes for macosx usage
Diffstat (limited to 'testshl2')
-rw-r--r-- | testshl2/source/dynamicregister.cxx | 161 |
1 files changed, 152 insertions, 9 deletions
diff --git a/testshl2/source/dynamicregister.cxx b/testshl2/source/dynamicregister.cxx index c04e80339c45..a5c41fda277b 100644 --- a/testshl2/source/dynamicregister.cxx +++ b/testshl2/source/dynamicregister.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: dynamicregister.cxx,v $ - * $Revision: 1.9 $ + * $Revision: 1.10 $ * * This file is part of OpenOffice.org. * @@ -38,30 +38,173 @@ #include <rtl/ustring.hxx> #include "filehelper.hxx" +#include <unistd.h> + +#if defined(WIN32) +#include <direct.h> /* w.g. _chdir() */ +#endif + +namespace fixes +{ + void changedir(const char* _sPath) + { +#if defined(WIN32) + // chdir(_sPath) is marked depricated since Visual C++ 2005 + // use _chdir instead + ::_chdir(_sPath); +#else + ::chdir(_sPath); +#endif + } +} + // ----------------------------------------------------------------------------- -DynamicLibraryHelper::DynamicLibraryHelper(rtl::OUString const& _sDLLName, GetOpt & _aOptions) +DynamicLibraryHelper::DynamicLibraryHelper(rtl::OUString const& _suDLLName, GetOpt & _aOptions) :m_pModule(new ::osl::Module()), - m_suDLLName(_sDLLName), + m_suDLLName(_suDLLName), m_aOptions(_aOptions) { // create and load the module (shared library) - rtl::OUString suFile = FileHelper::convertPath( _sDLLName ); - rtl::OString sDLLName = rtl::OUStringToOString(suFile, RTL_TEXTENCODING_ASCII_US); - if (_aOptions.hasOpt("-verbose")) + m_suAbsolutePathFile = FileHelper::convertPath( _suDLLName ); + + // due to some problems on mac OS + // we split the absolute pathname to path and filename + // change to the path and load the filename direct + // then change back to the old path. + rtl::OUString suPathSeparator = rtl::OUString( rtl::OUString::createFromAscii("/")); + sal_Int32 nPos = m_suAbsolutePathFile.lastIndexOf(suPathSeparator); + if (nPos != -1) + { + m_suAbsolutePath = m_suAbsolutePathFile.copy(0, nPos); + m_suFilename = m_suAbsolutePathFile.copy(nPos + 1); + } + else + { + // Should never happen. + rtl::OString sPath = rtl::OUStringToOString(m_suAbsolutePathFile, RTL_TEXTENCODING_ASCII_US); + fprintf(stderr, "There is a problem with path '%s'.\n", sPath.getStr()); + exit(1); + } + + if (getOptions().hasOpt("-absolutepath")) + { + fprintf(stderr, "Hint: Use absolute path to load test library.\n"); + loadLibraryFromAbsolutePath(); + } + else if (getOptions().hasOpt("-localpath")) + { + fprintf(stderr, "Hint: make a chdir() to the test library, then try to load the test library without given path.\n"); + loadLibraryFromLocalPath(); + } + else + { + +// PLEASE DON'T CHANGE THIS STUPID STRUCTURE, JUST ADD YOUR ENVIRONMENT +#if defined(LINUX) + loadLibraryFromAbsolutePath(); + // will fail if load local + +#elif defined(SOLARIS) + loadLibraryFromAbsolutePath(); + // will also be right if load local + +#elif defined(WIN32) + loadLibraryFromAbsolutePath(); + // will fail if load local + +#elif defined(MACOSX) + loadLibraryFromLocalPath(); + // will fail if local absolute +#else + // default is load absolute + loadLibraryFromAbsolutePath(); +#endif +} +} + +void DynamicLibraryHelper::showFilenameIfVerbose() +{ + if (getOptions().hasOpt("-verbose")) { - fprintf(stderr, "Try to load '%s'.\n", sDLLName.getStr()); + rtl::OString sFilename = rtl::OUStringToOString(m_suFilename, RTL_TEXTENCODING_ASCII_US); + rtl::OString sPath = rtl::OUStringToOString(m_suAbsolutePath, RTL_TEXTENCODING_ASCII_US); + fprintf(stderr, "Try to load '%s' from '%s'.\n", sFilename.getStr(), sPath.getStr()); + + // check filename } +} - if (! m_pModule->load(suFile, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL)) +void DynamicLibraryHelper::realLoadLibrary(rtl::OUString const& _suLibToLoad) +{ + if (! m_pModule->load(_suLibToLoad, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL)) { - sDLLName = rtl::OUStringToOString(_sDLLName, RTL_TEXTENCODING_ASCII_US); + rtl::OString sDLLName = rtl::OUStringToOString(m_suDLLName, RTL_TEXTENCODING_ASCII_US); fprintf(stderr, "warning: Can't load module '%s'.\n", sDLLName.getStr()); } } +void DynamicLibraryHelper::loadLibraryFromAbsolutePath() +{ + showFilenameIfVerbose(); + realLoadLibrary(m_suAbsolutePathFile); +} + +void DynamicLibraryHelper::loadLibraryFromLocalPath() +{ + sal_Int32 nPos; + rtl::OUString suPathSeparator = rtl::OUString( rtl::OUString::createFromAscii("/")); +#if defined(WIN32) + suPathSeparator = rtl::OUString( rtl::OUString::createFromAscii("\\")); +#endif + rtl::OUString suSystemPathFile; + osl::FileBase::getSystemPathFromFileURL(m_suAbsolutePathFile, suSystemPathFile); + + nPos = suSystemPathFile.lastIndexOf(suPathSeparator); + rtl::OUString suCurrentDirPath; + if (nPos != -1) + { + // the filename only, no '/' in the path + rtl::OUString suNewPath = suSystemPathFile.copy(0, nPos ); + if (suNewPath.getLength() > 0) + { + rtl::OString sPath = rtl::OUStringToOString(suNewPath, RTL_TEXTENCODING_ASCII_US); + osl_getProcessWorkingDir( &suCurrentDirPath.pData ); + + fixes::changedir(sPath.getStr()); + + // curNewDirPath should be suPath, small self test + rtl::OUString curNewDirPath; + osl_getProcessWorkingDir( &curNewDirPath.pData ); + if (! curNewDirPath.equals(m_suAbsolutePath)) + { + fprintf(stderr, "There is a problem with path '%s'.\n", sPath.getStr()); + } + } + } + + showFilenameIfVerbose(); + realLoadLibrary(m_suFilename); + + // change back to old directory + if (suCurrentDirPath.getLength() > 0) + { + rtl::OString sCurrentDirPath = rtl::OUStringToOString(suCurrentDirPath, RTL_TEXTENCODING_ASCII_US); + fixes::changedir(sCurrentDirPath.getStr()); + } +} + DynamicLibraryHelper::~DynamicLibraryHelper() { + if (getOptions().hasOpt("-verbose")) + { + fprintf(stderr, "Dtor DynamicLibraryHelper.\n"); + fprintf(stderr, "Delete loaded module."); + } delete m_pModule; + if (getOptions().hasOpt("-verbose")) + { + fprintf(stderr, " [done].\n"); + } } |