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