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