xref: /AOO41X/main/sal/osl/os2/salinit.cxx (revision 1a6da4ce8c047845eeeaec2dcb6a8b9276848791)
187d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
387d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
487d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
587d2adbcSAndrew Rist  * distributed with this work for additional information
687d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
787d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
887d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
987d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1187d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1387d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1487d2adbcSAndrew Rist  * software distributed under the License is distributed on an
1587d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1687d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
1787d2adbcSAndrew Rist  * specific language governing permissions and limitations
1887d2adbcSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2087d2adbcSAndrew Rist  *************************************************************/
2187d2adbcSAndrew Rist 
2287d2adbcSAndrew 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 
39cdf0e10cSrcweir extern "C" {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
42cdf0e10cSrcweir 
43cdf0e10cSrcweir static CHAR        szOOoExe[CCHMAXPATH];
44cdf0e10cSrcweir 
45cdf0e10cSrcweir static FILE* APIENTRY _oslExceptOpenLogFile(VOID)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir    FILE        *file;
48cdf0e10cSrcweir    DATETIME    DT;
49cdf0e10cSrcweir    PPIB        pib;
50cdf0e10cSrcweir    PSZ         slash;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir    // get executable fullpath
53cdf0e10cSrcweir    DosGetInfoBlocks(NULL, &pib);
54cdf0e10cSrcweir    DosQueryModuleName(pib->pib_hmte, sizeof(szOOoExe), szOOoExe);
55cdf0e10cSrcweir    // truncate to exe name
56cdf0e10cSrcweir    slash = (PSZ)strrchr( szOOoExe, '.');
57cdf0e10cSrcweir    *slash = '\0';
58cdf0e10cSrcweir    // make log path
59cdf0e10cSrcweir    strcat( szOOoExe, ".log");
60cdf0e10cSrcweir 
61cdf0e10cSrcweir    file = fopen( szOOoExe, "a");
62cdf0e10cSrcweir    if (!file) { // e.g. readonly drive
63cdf0e10cSrcweir       // try again, usually C exist and is writable
64cdf0e10cSrcweir       file = fopen( "c:\\OOo.log", "a");
65cdf0e10cSrcweir    }
66cdf0e10cSrcweir    if (file) {
67cdf0e10cSrcweir         DosGetDateTime(&DT);
68cdf0e10cSrcweir         fprintf(file, "\nTrap message -- Date: %04d-%02d-%02d, Time: %02d:%02d:%02d\n",
69cdf0e10cSrcweir             DT.year, DT.month, DT.day,
70cdf0e10cSrcweir             DT.hours, DT.minutes, DT.seconds);
71cdf0e10cSrcweir         fprintf(file, "-------------------------------------------------------\n"
72cdf0e10cSrcweir                       "\nAn internal error occurred (Built " __DATE__ "-" __TIME__ ").\n");
73cdf0e10cSrcweir 
74cdf0e10cSrcweir    }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir    // ok, return handle
77cdf0e10cSrcweir    return (file);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
81cdf0e10cSrcweir 
82*1a6da4ceSYuri Dario #if 0 // until exceptions restored OSL_DEBUG_LEVEL == 0
83cdf0e10cSrcweir static EXCEPTSTRUCT 	g_excptstruct = {0};
84*1a6da4ceSYuri Dario #endif
85cdf0e10cSrcweir 
86cdf0e10cSrcweir void SAL_CALL sal_detail_initialize(int argc, char ** argv)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	APIRET rc = -1;
89cdf0e10cSrcweir 
90*1a6da4ceSYuri Dario #if 0 // until exceptions restored OSL_DEBUG_LEVEL == 0
91cdf0e10cSrcweir 	excRegisterHooks(_oslExceptOpenLogFile, NULL, NULL, FALSE);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	g_excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud;
94cdf0e10cSrcweir 	g_excptstruct.arc = DosSetExceptionHandler(
95cdf0e10cSrcweir 	   		(PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2));
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	if (g_excptstruct.arc)
98cdf0e10cSrcweir 		if (G_pfnExcHookError)
99cdf0e10cSrcweir 			G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, g_excptstruct.arc);
100cdf0e10cSrcweir 		else
101cdf0e10cSrcweir 			DosBeep(1000, 1000);
102cdf0e10cSrcweir 	g_excptstruct.ulExcpt = setjmp(g_excptstruct.RegRec2.jmpThread);
103cdf0e10cSrcweir #endif
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	osl_setCommandArgs(argc, argv);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir void SAL_CALL sal_detail_deinitialize()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	APIRET rc = -1;
111cdf0e10cSrcweir 
112*1a6da4ceSYuri Dario #if 0 // until exceptions restored OSL_DEBUG_LEVEL == 0
113cdf0e10cSrcweir 	rc = DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2));
114cdf0e10cSrcweir #endif
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir }
118