xref: /aoo41x/main/sal/osl/os2/salinit.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #define INCL_DOS
29 #include <os2.h>
30 
31 #include "precompiled_sal.hxx"
32 #include "sal/config.h"
33 
34 #include "osl/process.h"
35 #include "sal/main.h"
36 #include "sal/types.h"
37 
38 // for exception logging
39 #include <stdio.h>
40 #include <string.h>
41 #include <setjmp.h>
42 #include "helpers/except.h"
43 
44 extern "C" {
45 
46 /*----------------------------------------------------------------------------*/
47 
48 static CHAR        szOOoExe[CCHMAXPATH];
49 
50 static FILE* APIENTRY _oslExceptOpenLogFile(VOID)
51 {
52    FILE        *file;
53    DATETIME    DT;
54    PPIB        pib;
55    PSZ         slash;
56 
57    // get executable fullpath
58    DosGetInfoBlocks(NULL, &pib);
59    DosQueryModuleName(pib->pib_hmte, sizeof(szOOoExe), szOOoExe);
60    // truncate to exe name
61    slash = (PSZ)strrchr( szOOoExe, '.');
62    *slash = '\0';
63    // make log path
64    strcat( szOOoExe, ".log");
65 
66    file = fopen( szOOoExe, "a");
67    if (!file) { // e.g. readonly drive
68       // try again, usually C exist and is writable
69       file = fopen( "c:\\OOo.log", "a");
70    }
71    if (file) {
72         DosGetDateTime(&DT);
73         fprintf(file, "\nTrap message -- Date: %04d-%02d-%02d, Time: %02d:%02d:%02d\n",
74             DT.year, DT.month, DT.day,
75             DT.hours, DT.minutes, DT.seconds);
76         fprintf(file, "-------------------------------------------------------\n"
77                       "\nAn internal error occurred (Built " __DATE__ "-" __TIME__ ").\n");
78 
79    }
80 
81    // ok, return handle
82    return (file);
83 }
84 
85 /*----------------------------------------------------------------------------*/
86 
87 static EXCEPTSTRUCT 	g_excptstruct = {0};
88 
89 void SAL_CALL sal_detail_initialize(int argc, char ** argv)
90 {
91 	APIRET rc = -1;
92 
93 #if OSL_DEBUG_LEVEL == 0
94 	excRegisterHooks(_oslExceptOpenLogFile, NULL, NULL, FALSE);
95 
96 	g_excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud;
97 	g_excptstruct.arc = DosSetExceptionHandler(
98 	   		(PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2));
99 
100 	if (g_excptstruct.arc)
101 		if (G_pfnExcHookError)
102 			G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, g_excptstruct.arc);
103 		else
104 			DosBeep(1000, 1000);
105 	g_excptstruct.ulExcpt = setjmp(g_excptstruct.RegRec2.jmpThread);
106 #endif
107 
108 	osl_setCommandArgs(argc, argv);
109 }
110 
111 void SAL_CALL sal_detail_deinitialize()
112 {
113 	APIRET rc = -1;
114 
115 #if OSL_DEBUG_LEVEL == 0
116 	rc = DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2));
117 #endif
118 }
119 
120 }
121