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 10cdf0e10cSrcweir * 112722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 szApplicationName[_MAX_PATH]; 46cdf0e10cSrcweir 47cdf0e10cSrcweir // get executable fullpath 48cdf0e10cSrcweir DosGetInfoBlocks(NULL, &pib); 49cdf0e10cSrcweir DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName); 50cdf0e10cSrcweir 51cdf0e10cSrcweir // adjust libpath 52055eca97SYuri Dario #if OSL_DEBUG_LEVEL > 0 53*ebec3577SYuri Dario CHAR szLibpath[_MAX_PATH*2]; 54055eca97SYuri Dario rc = DosQueryExtLIBPATH( (PSZ)szLibpath, BEGIN_LIBPATH); 55055eca97SYuri Dario fprintf( stderr, "1 BeginLibPath: %s\n", szLibpath); 56055eca97SYuri Dario #endif 57*ebec3577SYuri Dario char* basedir = strrchr( szApplicationName, '\\'); 58cdf0e10cSrcweir if (basedir) *basedir = 0; 59*ebec3577SYuri Dario DosSetExtLIBPATH( (PCSZ)szApplicationName, BEGIN_LIBPATH); 6079e08879SYuri Dario 61cdf0e10cSrcweir // make sure we load DLL from our path only, so multiple instances/versions 62cdf0e10cSrcweir // can be loaded. 63cdf0e10cSrcweir DosSetExtLIBPATH( (PCSZ)"T", LIBPATHSTRICT); 6479e08879SYuri Dario 65055eca97SYuri Dario #if OSL_DEBUG_LEVEL > 0 66055eca97SYuri Dario rc = DosQueryExtLIBPATH( (PSZ)szLibpath, BEGIN_LIBPATH); 67055eca97SYuri Dario fprintf( stderr, "2 BeginLibPath: %s\n", szLibpath); 68055eca97SYuri Dario #endif 69cdf0e10cSrcweir 70cdf0e10cSrcweir // adjust exe name 71*ebec3577SYuri Dario strcat( szApplicationName, "\\" OFFICE_IMAGE_NAME ".bin"); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // copy command line parameters 74cdf0e10cSrcweir int i, len; 75cdf0e10cSrcweir len = strlen(szApplicationName) + 1 + strlen( APPLICATION_SWITCH) + 1 + 1; 76cdf0e10cSrcweir for( i=1; i<argc; i++) 77cdf0e10cSrcweir len += strlen( argv[i]) + 1; 78cdf0e10cSrcweir 79cdf0e10cSrcweir char* pszCommandLine, *pszArgs; 80cdf0e10cSrcweir pszCommandLine = (char*) calloc( 1, len); 81cdf0e10cSrcweir strcpy( pszCommandLine, szApplicationName); 82cdf0e10cSrcweir pszArgs = pszCommandLine + strlen(szApplicationName) + 1; 83cdf0e10cSrcweir strcat( pszArgs, APPLICATION_SWITCH); 84cdf0e10cSrcweir strcat( pszArgs, " "); 85cdf0e10cSrcweir for( i=1; i<argc; i++) { 86cdf0e10cSrcweir // add quotes if argument has spaces! 87cdf0e10cSrcweir if (strchr( argv[i], ' ')) 88cdf0e10cSrcweir strcat( pszArgs, "\""); 89cdf0e10cSrcweir strcat( pszArgs, argv[i]); 90cdf0e10cSrcweir if (strchr( argv[i], ' ')) 91cdf0e10cSrcweir strcat( pszArgs, "\""); 92cdf0e10cSrcweir strcat( pszArgs, " "); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir pszArgs[ strlen( pszArgs) + 0] = 0; 95cdf0e10cSrcweir 96cdf0e10cSrcweir // execute 97cdf0e10cSrcweir rc = DosExecPgm(szFail, sizeof(szFail), 98cdf0e10cSrcweir EXEC_SYNC, (PCSZ)pszCommandLine, (PCSZ)NULL, &result, 99cdf0e10cSrcweir (PCSZ)szApplicationName); 100cdf0e10cSrcweir if (rc) { 101cdf0e10cSrcweir char szMessage[ _MAX_PATH*2]; 102cdf0e10cSrcweir sprintf( szMessage, "Execution failed! Contact technical support.\n\nReturn code: %d\nFailing module:%s\n", rc, szFail); 103cdf0e10cSrcweir rc = WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, 104cdf0e10cSrcweir (PSZ)szMessage, 1058951e390SHerbert Dürr (PSZ)"Unable to start Apache OpenOffice!", 106cdf0e10cSrcweir 0, MB_ERROR | MB_OK); 107cdf0e10cSrcweir WinDestroyMsgQueue( hmq); 108cdf0e10cSrcweir WinTerminate( hab); 109cdf0e10cSrcweir exit(1); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir WinDestroyMsgQueue( hmq); 113cdf0e10cSrcweir WinTerminate( hab); 114cdf0e10cSrcweir 115cdf0e10cSrcweir exit( result.codeResult); 116cdf0e10cSrcweir } 117