Kaydet (Commit) 725a52c5 authored tarafından Juergen Funk's avatar Juergen Funk Kaydeden (comit) Caolán McNamara

Preparation of the LibreOfficeKit for Windows

- not yet included in the make for windows

Change-Id: Iee31b0ed0c6545572295ce00a3bb0f909c428b5a
Reviewed-on: https://gerrit.libreoffice.org/12425Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 0cda507b
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL) inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
{ {
return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions); return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
} }
inline LibreOfficeKitDocument *get() { return mpDoc; } inline LibreOfficeKitDocument *get() { return mpDoc; }
......
...@@ -17,22 +17,115 @@ extern "C" ...@@ -17,22 +17,115 @@ extern "C"
{ {
#endif #endif
#if defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX) #if defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX) || defined(_WIN32)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <dlfcn.h>
#ifdef _AIX #ifndef _WIN32
# include <sys/ldr.h> #include "dlfcn.h"
#ifdef _AIX
# include <sys/ldr.h>
#endif
#define TARGET_LIB "lib" "sofficeapp" ".so"
#define TARGET_MERGED_LIB "lib" "mergedlo" ".so"
#define SEPERATOR '/'
void *_dlopen(const char *pFN)
{
return dlopen(pFN, RTLD_LAZY);
}
void *_dlsym(void *Hnd, const char *pName)
{
return dlsym(Hnd, pName);
}
int _dlclose(void *Hnd)
{
return dlclose(Hnd);
}
void extendUnoPath(const char *pPath)
{
(void)pPath;
}
#else
#include <windows.h>
#define TARGET_LIB "sofficeapp" ".dll"
#define TARGET_MERGED_LIB "mergedlo" ".dll"
#define SEPERATOR '\\'
#define UNOPATH "\\..\\URE\\bin"
void *_dlopen(const char *pFN)
{
return (void *) LoadLibrary(pFN);
}
void *_dlsym(void *Hnd, const char *pName)
{
return GetProcAddress((HINSTANCE) Hnd, pName);
}
int _dlclose(void *Hnd)
{
return FreeLibrary((HINSTANCE) Hnd);
}
void extendUnoPath(const char *pPath)
{
if (!pPath)
return;
char* sEnvPath = NULL;
DWORD cChars = GetEnvironmentVariable("PATH", sEnvPath, 0);
if (cChars > 0)
{
sEnvPath = new char[cChars];
cChars = GetEnvironmentVariable("PATH", sEnvPath, cChars);
//If PATH is not set then it is no error
if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND)
{
delete[] sEnvPath;
return;
}
}
//prepare the new PATH. Add the Ure/bin directory at the front.
//note also adding ';'
char * sNewPath = new char[strlen(sEnvPath) + strlen(pPath) + strlen(UNOPATH) + 2];
sNewPath[0] = L'\0';
strcat(sNewPath, pPath);
strcat(sNewPath, UNOPATH);
if (strlen(sEnvPath))
{
strcat(sNewPath, ";");
strcat(sNewPath, sEnvPath);
}
SetEnvironmentVariable("PATH", sNewPath);
delete[] sEnvPath;
delete[] sNewPath;
}
#endif #endif
#define TARGET_LIB "lib" "sofficeapp" ".so"
#define TARGET_MERGED_LIB "lib" "mergedlo" ".so"
typedef LibreOfficeKit *(HookFunction)( const char *install_path); typedef LibreOfficeKit *(HookFunction)( const char *install_path);
static LibreOfficeKit *lok_init( const char *install_path ) static LibreOfficeKit *lok_init( const char *install_path )
{ {
char *imp_lib; char *imp_lib;
...@@ -54,15 +147,17 @@ static LibreOfficeKit *lok_init( const char *install_path ) ...@@ -54,15 +147,17 @@ static LibreOfficeKit *lok_init( const char *install_path )
strcpy(imp_lib, install_path); strcpy(imp_lib, install_path);
imp_lib[partial_length++] = '/'; extendUnoPath(install_path);
imp_lib[partial_length++] = SEPERATOR;
strcpy(imp_lib + partial_length, TARGET_LIB); strcpy(imp_lib + partial_length, TARGET_LIB);
dlhandle = dlopen(imp_lib, RTLD_LAZY); dlhandle = _dlopen(imp_lib);
if (!dlhandle) if (!dlhandle)
{ {
strcpy(imp_lib + partial_length, TARGET_MERGED_LIB); strcpy(imp_lib + partial_length, TARGET_MERGED_LIB);
dlhandle = dlopen(imp_lib, RTLD_LAZY); dlhandle = _dlopen(imp_lib);
if (!dlhandle) if (!dlhandle)
{ {
fprintf(stderr, "failed to open library '%s' or '%s' in '%s/'\n", fprintf(stderr, "failed to open library '%s' or '%s' in '%s/'\n",
...@@ -72,11 +167,11 @@ static LibreOfficeKit *lok_init( const char *install_path ) ...@@ -72,11 +167,11 @@ static LibreOfficeKit *lok_init( const char *install_path )
} }
} }
pSym = (HookFunction *) dlsym( dlhandle, "libreofficekit_hook" ); pSym = (HookFunction *) _dlsym( dlhandle, "libreofficekit_hook" );
if (!pSym) if (!pSym)
{ {
fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib ); fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
dlclose( dlhandle ); _dlclose( dlhandle );
free( imp_lib ); free( imp_lib );
return NULL; return NULL;
} }
......
...@@ -12,19 +12,55 @@ ...@@ -12,19 +12,55 @@
#include <malloc.h> #include <malloc.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <sys/time.h>
#include <sal/types.h>
#include <LibreOfficeKit/LibreOfficeKitInit.h> #include <LibreOfficeKit/LibreOfficeKitInit.h>
#include <LibreOfficeKit/LibreOfficeKit.hxx> #include <LibreOfficeKit/LibreOfficeKit.hxx>
using namespace ::lok;
long getTimeMS()
{ #ifdef _WIN32
//#include <Windows.h> // come from LibreOfficeKitInit.h
long getTimeMS()
{
return GetTickCount();
}
bool IsAbsolutePath(char *pPath)
{
if (pPath[1] != ':')
{
fprintf( stderr, "Absolute path required to libreoffice install\n" );
return false;
}
return true;
}
#else
#include <sys/time.h>
#include <sal/types.h>
long getTimeMS()
{
struct timeval t; struct timeval t;
gettimeofday(&t, NULL); gettimeofday(&t, NULL);
return t.tv_sec*1000 + t.tv_usec/1000; return t.tv_sec*1000 + t.tv_usec/1000;
} }
bool IsAbsolutePath(char *pPath)
{
if (pPath[0] != '/')
{
fprintf( stderr, "Absolute path required to libreoffice install\n" );
return false;
}
return true;
}
#endif
using namespace ::lok;
static int help() static int help()
{ {
...@@ -42,11 +78,9 @@ int main (int argc, char **argv) ...@@ -42,11 +78,9 @@ int main (int argc, char **argv)
( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) ) ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
return help(); return help();
if (argv[1][0] != '/')
{ if( !IsAbsolutePath(argv[1]) )
fprintf( stderr, "Absolute path required to libreoffice install\n" );
return 1; return 1;
}
// coverity[tainted_string] - build time test tool // coverity[tainted_string] - build time test tool
Office *pOffice = lok_cpp_init( argv[1] ); Office *pOffice = lok_cpp_init( argv[1] );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment