Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xwin / winerror.c
CommitLineData
a09e091a
JB
1/*
2 *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
3 *
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
11 *
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
14 *
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 *Except as contained in this notice, the name of Harold L Hunt II
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from Harold L Hunt II.
27 *
28 * Authors: Harold L Hunt II
29 */
30
31#ifdef HAVE_XWIN_CONFIG_H
32#include <xwin-config.h>
33#endif
34
35#include <../xfree86/common/xorgVersion.h>
36#include "win.h"
37
38#ifdef DDXOSVERRORF
39void
40OsVendorVErrorF(const char *pszFormat, va_list va_args)
41{
42#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
43 /* make sure the clipboard and multiwindow threads do not interfere the
44 * main thread */
45 static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER;
46
47 /* Lock the printing mutex */
48 pthread_mutex_lock(&s_pmPrinting);
49#endif
50
51 /* Print the error message to a log file, could be stderr */
52 LogVWrite(0, pszFormat, va_args);
53
54#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
55 /* Unlock the printing mutex */
56 pthread_mutex_unlock(&s_pmPrinting);
57#endif
58}
59#endif
60
61/*
62 * os/log.c:FatalError () calls our vendor ErrorF, so the message
63 * from a FatalError will be logged.
64 *
65 * Attempt to do last-ditch, safe, important cleanup here.
66 */
67void
68OsVendorFatalError(const char *f, va_list args)
69{
70 char errormsg[1024] = "";
71
72 /* Don't give duplicate warning if UseMsg was called */
73 if (g_fSilentFatalError)
74 return;
75
76 if (!g_fLogInited) {
77 g_fLogInited = TRUE;
78 g_pszLogFile = LogInit(g_pszLogFile, NULL);
79 }
80 LogClose(EXIT_ERR_ABORT);
81
82 /* Format the error message */
83 vsnprintf(errormsg, sizeof(errormsg), f, args);
84
85 /*
86 Sometimes the error message needs a bit of cosmetic cleaning
87 up for use in a dialog box...
88 */
89 {
90 char *s;
91
92 while ((s = strstr(errormsg, "\n\t")) != NULL) {
93 s[0] = ' ';
94 s[1] = '\n';
95 }
96 }
97
98 winMessageBoxF("A fatal error has occurred and " PROJECT_NAME " will now exit.\n\n"
99 "%s\n\n"
100 "Please open %s for more information.\n",
101 MB_ICONERROR,
102 errormsg,
103 (g_pszLogFile ? g_pszLogFile : "the logfile"));
104}
105
106/*
107 * winMessageBoxF - Print a formatted error message in a useful
108 * message box.
109 */
110
111void
112winMessageBoxF(const char *pszError, UINT uType, ...)
113{
114 char *pszErrorF = NULL;
115 char *pszMsgBox = NULL;
116 va_list args;
117 int size;
118
119 va_start(args, uType);
120 size = vasprintf(&pszErrorF, pszError, args);
121 va_end(args);
122 if (size == -1) {
123 pszErrorF = NULL;
124 goto winMessageBoxF_Cleanup;
125 }
126
127#define MESSAGEBOXF \
128 "%s\n" \
129 "Vendor: %s\n" \
130 "Release: %d.%d.%d.%d\n" \
131 "Contact: %s\n" \
132 "%s\n\n" \
133 "XWin was started with the following command-line:\n\n" \
134 "%s\n"
135
136 size = asprintf(&pszMsgBox, MESSAGEBOXF,
137 pszErrorF, XVENDORNAME,
138 XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH,
139 XORG_VERSION_SNAP,
140 BUILDERADDR, BUILDERSTRING, g_pszCommandLine);
141
142 if (size == -1) {
143 pszMsgBox = NULL;
144 goto winMessageBoxF_Cleanup;
145 }
146
147 /* Display the message box string */
148 MessageBox(NULL, pszMsgBox, PROJECT_NAME, MB_OK | uType);
149
150 winMessageBoxF_Cleanup:
151 free(pszErrorF);
152 free(pszMsgBox);
153#undef MESSAGEBOXF
154}