1*87d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*87d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*87d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*87d2adbcSAndrew Rist * distributed with this work for additional information 6*87d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*87d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*87d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 9*87d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 10*87d2adbcSAndrew Rist * 11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*87d2adbcSAndrew Rist * 13*87d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*87d2adbcSAndrew Rist * software distributed under the License is distributed on an 15*87d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*87d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 17*87d2adbcSAndrew Rist * specific language governing permissions and limitations 18*87d2adbcSAndrew Rist * under the License. 19*87d2adbcSAndrew Rist * 20*87d2adbcSAndrew Rist *************************************************************/ 21*87d2adbcSAndrew Rist 22*87d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #define INCL_DOS 25cdf0e10cSrcweir #include <os2.h> 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "precompiled_sal.hxx" 28cdf0e10cSrcweir #include "sal/config.h" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "osl/process.h" 31cdf0e10cSrcweir #include "sal/main.h" 32cdf0e10cSrcweir #include "sal/types.h" 33cdf0e10cSrcweir 34cdf0e10cSrcweir // for exception logging 35cdf0e10cSrcweir #include <stdio.h> 36cdf0e10cSrcweir #include <string.h> 37cdf0e10cSrcweir #include <setjmp.h> 38cdf0e10cSrcweir #include "helpers/except.h" 39cdf0e10cSrcweir 40cdf0e10cSrcweir extern "C" { 41cdf0e10cSrcweir 42cdf0e10cSrcweir /*----------------------------------------------------------------------------*/ 43cdf0e10cSrcweir 44cdf0e10cSrcweir static CHAR szOOoExe[CCHMAXPATH]; 45cdf0e10cSrcweir 46cdf0e10cSrcweir static FILE* APIENTRY _oslExceptOpenLogFile(VOID) 47cdf0e10cSrcweir { 48cdf0e10cSrcweir FILE *file; 49cdf0e10cSrcweir DATETIME DT; 50cdf0e10cSrcweir PPIB pib; 51cdf0e10cSrcweir PSZ slash; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // get executable fullpath 54cdf0e10cSrcweir DosGetInfoBlocks(NULL, &pib); 55cdf0e10cSrcweir DosQueryModuleName(pib->pib_hmte, sizeof(szOOoExe), szOOoExe); 56cdf0e10cSrcweir // truncate to exe name 57cdf0e10cSrcweir slash = (PSZ)strrchr( szOOoExe, '.'); 58cdf0e10cSrcweir *slash = '\0'; 59cdf0e10cSrcweir // make log path 60cdf0e10cSrcweir strcat( szOOoExe, ".log"); 61cdf0e10cSrcweir 62cdf0e10cSrcweir file = fopen( szOOoExe, "a"); 63cdf0e10cSrcweir if (!file) { // e.g. readonly drive 64cdf0e10cSrcweir // try again, usually C exist and is writable 65cdf0e10cSrcweir file = fopen( "c:\\OOo.log", "a"); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir if (file) { 68cdf0e10cSrcweir DosGetDateTime(&DT); 69cdf0e10cSrcweir fprintf(file, "\nTrap message -- Date: %04d-%02d-%02d, Time: %02d:%02d:%02d\n", 70cdf0e10cSrcweir DT.year, DT.month, DT.day, 71cdf0e10cSrcweir DT.hours, DT.minutes, DT.seconds); 72cdf0e10cSrcweir fprintf(file, "-------------------------------------------------------\n" 73cdf0e10cSrcweir "\nAn internal error occurred (Built " __DATE__ "-" __TIME__ ").\n"); 74cdf0e10cSrcweir 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // ok, return handle 78cdf0e10cSrcweir return (file); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir /*----------------------------------------------------------------------------*/ 82cdf0e10cSrcweir 83cdf0e10cSrcweir static EXCEPTSTRUCT g_excptstruct = {0}; 84cdf0e10cSrcweir 85cdf0e10cSrcweir void SAL_CALL sal_detail_initialize(int argc, char ** argv) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir APIRET rc = -1; 88cdf0e10cSrcweir 89cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0 90cdf0e10cSrcweir excRegisterHooks(_oslExceptOpenLogFile, NULL, NULL, FALSE); 91cdf0e10cSrcweir 92cdf0e10cSrcweir g_excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; 93cdf0e10cSrcweir g_excptstruct.arc = DosSetExceptionHandler( 94cdf0e10cSrcweir (PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2)); 95cdf0e10cSrcweir 96cdf0e10cSrcweir if (g_excptstruct.arc) 97cdf0e10cSrcweir if (G_pfnExcHookError) 98cdf0e10cSrcweir G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, g_excptstruct.arc); 99cdf0e10cSrcweir else 100cdf0e10cSrcweir DosBeep(1000, 1000); 101cdf0e10cSrcweir g_excptstruct.ulExcpt = setjmp(g_excptstruct.RegRec2.jmpThread); 102cdf0e10cSrcweir #endif 103cdf0e10cSrcweir 104cdf0e10cSrcweir osl_setCommandArgs(argc, argv); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir void SAL_CALL sal_detail_deinitialize() 108cdf0e10cSrcweir { 109cdf0e10cSrcweir APIRET rc = -1; 110cdf0e10cSrcweir 111cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0 112cdf0e10cSrcweir rc = DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2)); 113cdf0e10cSrcweir #endif 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir } 117