12722ceddSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file 52722ceddSAndrew Rist * distributed with this work for additional information 62722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file 72722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the 82722ceddSAndrew Rist * "License"); you may not use this file except in compliance 92722ceddSAndrew Rist * with the License. You may obtain a copy of the License at 102722ceddSAndrew Rist * 112722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 122722ceddSAndrew Rist * 132722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing, 142722ceddSAndrew Rist * software distributed under the License is distributed on an 152722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162722ceddSAndrew Rist * KIND, either express or implied. See the License for the 172722ceddSAndrew Rist * specific language governing permissions and limitations 182722ceddSAndrew Rist * under the License. 192722ceddSAndrew Rist * 202722ceddSAndrew Rist *************************************************************/ 212722ceddSAndrew Rist 222722ceddSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "launcher.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <stdio.h> 27cdf0e10cSrcweir #include <stdlib.h> 28cdf0e10cSrcweir #include <string.h> 29cdf0e10cSrcweir #include <malloc.h> 30cdf0e10cSrcweir #include <process.h> 31cdf0e10cSrcweir 32cdf0e10cSrcweir int main( int argc, char* argv[]) 33cdf0e10cSrcweir { 34cdf0e10cSrcweir PPIB pib; 35cdf0e10cSrcweir APIRET rc; 36cdf0e10cSrcweir RESULTCODES result = {0}; 37cdf0e10cSrcweir char szFail[ _MAX_PATH]; 38cdf0e10cSrcweir 39cdf0e10cSrcweir HAB hab = WinInitialize( 0); 40cdf0e10cSrcweir HMQ hmq = WinCreateMsgQueue( hab, 0); 41cdf0e10cSrcweir ERRORID erridErrorCode = 0; 42cdf0e10cSrcweir erridErrorCode = WinGetLastError(hab); 43cdf0e10cSrcweir 44cdf0e10cSrcweir // Calculate application name 45cdf0e10cSrcweir CHAR szLibpath[_MAX_PATH*2]; 46cdf0e10cSrcweir CHAR szApplicationName[_MAX_PATH]; 47cdf0e10cSrcweir CHAR szDrive[_MAX_PATH]; 48cdf0e10cSrcweir CHAR szDir[_MAX_PATH]; 49cdf0e10cSrcweir CHAR szFileName[_MAX_PATH]; 50cdf0e10cSrcweir CHAR szExt[_MAX_PATH]; 51cdf0e10cSrcweir 52cdf0e10cSrcweir // get executable fullpath 53cdf0e10cSrcweir DosGetInfoBlocks(NULL, &pib); 54cdf0e10cSrcweir DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName); 55cdf0e10cSrcweir 56cdf0e10cSrcweir // adjust libpath 57055eca97SYuri Dario #if OSL_DEBUG_LEVEL > 0 58055eca97SYuri Dario rc = DosQueryExtLIBPATH( (PSZ)szLibpath, BEGIN_LIBPATH); 59055eca97SYuri Dario fprintf( stderr, "1 BeginLibPath: %s\n", szLibpath); 60055eca97SYuri Dario #endif 61cdf0e10cSrcweir _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt ); 62cdf0e10cSrcweir char* basedir = strstr( szDir, "\\PROGRAM\\"); 63cdf0e10cSrcweir if (basedir) *basedir = 0; 64055eca97SYuri Dario sprintf( szLibpath, "\"%s%s\\URE\\BIN\";\"%s%s\\BASIS\\PROGRAM\";%%BeginLIBPATH%%;", 65cdf0e10cSrcweir szDrive, szDir, szDrive, szDir); 66cdf0e10cSrcweir DosSetExtLIBPATH( (PCSZ)szLibpath, BEGIN_LIBPATH); 67*79e08879SYuri Dario 68cdf0e10cSrcweir // make sure we load DLL from our path only, so multiple instances/versions 69cdf0e10cSrcweir // can be loaded. 70cdf0e10cSrcweir DosSetExtLIBPATH( (PCSZ)"T", LIBPATHSTRICT); 71*79e08879SYuri Dario 72055eca97SYuri Dario #if OSL_DEBUG_LEVEL > 0 73055eca97SYuri Dario rc = DosQueryExtLIBPATH( (PSZ)szLibpath, BEGIN_LIBPATH); 74055eca97SYuri Dario fprintf( stderr, "2 BeginLibPath: %s\n", szLibpath); 75055eca97SYuri Dario #endif 76cdf0e10cSrcweir 77cdf0e10cSrcweir // adjust exe name 78cdf0e10cSrcweir _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt ); 79cdf0e10cSrcweir _makepath( szApplicationName, szDrive, szDir, OFFICE_IMAGE_NAME, (".bin") ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir // copy command line parameters 82cdf0e10cSrcweir int i, len; 83cdf0e10cSrcweir len = strlen(szApplicationName) + 1 + strlen( APPLICATION_SWITCH) + 1 + 1; 84cdf0e10cSrcweir for( i=1; i<argc; i++) 85cdf0e10cSrcweir len += strlen( argv[i]) + 1; 86cdf0e10cSrcweir 87cdf0e10cSrcweir char* pszCommandLine, *pszArgs; 88cdf0e10cSrcweir pszCommandLine = (char*) calloc( 1, len); 89cdf0e10cSrcweir strcpy( pszCommandLine, szApplicationName); 90cdf0e10cSrcweir pszArgs = pszCommandLine + strlen(szApplicationName) + 1; 91cdf0e10cSrcweir strcat( pszArgs, APPLICATION_SWITCH); 92cdf0e10cSrcweir strcat( pszArgs, " "); 93cdf0e10cSrcweir for( i=1; i<argc; i++) { 94cdf0e10cSrcweir // add quotes if argument has spaces! 95cdf0e10cSrcweir if (strchr( argv[i], ' ')) 96cdf0e10cSrcweir strcat( pszArgs, "\""); 97cdf0e10cSrcweir strcat( pszArgs, argv[i]); 98cdf0e10cSrcweir if (strchr( argv[i], ' ')) 99cdf0e10cSrcweir strcat( pszArgs, "\""); 100cdf0e10cSrcweir strcat( pszArgs, " "); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir pszArgs[ strlen( pszArgs) + 0] = 0; 103cdf0e10cSrcweir 104cdf0e10cSrcweir // execute 105cdf0e10cSrcweir rc = DosExecPgm(szFail, sizeof(szFail), 106cdf0e10cSrcweir EXEC_SYNC, (PCSZ)pszCommandLine, (PCSZ)NULL, &result, 107cdf0e10cSrcweir (PCSZ)szApplicationName); 108cdf0e10cSrcweir if (rc) { 109cdf0e10cSrcweir char szMessage[ _MAX_PATH*2]; 110cdf0e10cSrcweir sprintf( szMessage, "Execution failed! Contact technical support.\n\nReturn code: %d\nFailing module:%s\n", rc, szFail); 111cdf0e10cSrcweir rc = WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, 112cdf0e10cSrcweir (PSZ)szMessage, 1138951e390SHerbert Dürr (PSZ)"Unable to start Apache OpenOffice!", 114cdf0e10cSrcweir 0, MB_ERROR | MB_OK); 115cdf0e10cSrcweir WinDestroyMsgQueue( hmq); 116cdf0e10cSrcweir WinTerminate( hab); 117cdf0e10cSrcweir exit(1); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir WinDestroyMsgQueue( hmq); 121cdf0e10cSrcweir WinTerminate( hab); 122cdf0e10cSrcweir 123cdf0e10cSrcweir exit( result.codeResult); 124cdf0e10cSrcweir } 125