winerror.c revision 05b261ec
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#ifdef XVENDORNAME
35#define VENDOR_STRING XVENDORNAME
36#define VERSION_STRING XORG_RELEASE
37#define VENDOR_CONTACT BUILDERADDR
38#endif
39
40#include "win.h"
41
42/* References to external symbols */
43extern char *		g_pszCommandLine;
44extern char *		g_pszLogFile;
45extern Bool		g_fSilentFatalError;
46
47
48#ifdef DDXOSVERRORF
49/* Prototype */
50void
51OsVendorVErrorF (const char *pszFormat, va_list va_args);
52
53void
54OsVendorVErrorF (const char *pszFormat, va_list va_args)
55{
56#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
57  /* make sure the clipboard and multiwindow threads do not interfere the
58   * main thread */
59  static pthread_mutex_t	s_pmPrinting = PTHREAD_MUTEX_INITIALIZER;
60
61  /* Lock the printing mutex */
62  pthread_mutex_lock (&s_pmPrinting);
63#endif
64
65  /* Print the error message to a log file, could be stderr */
66  LogVWrite (0, pszFormat, va_args);
67
68#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
69  /* Unlock the printing mutex */
70  pthread_mutex_unlock (&s_pmPrinting);
71#endif
72}
73#endif
74
75
76/*
77 * os/util.c/FatalError () calls our vendor ErrorF, so the message
78 * from a FatalError will be logged.  Thus, the message for the
79 * fatal error is not passed to this function.
80 *
81 * Attempt to do last-ditch, safe, important cleanup here.
82 */
83#ifdef DDXOSFATALERROR
84void
85OsVendorFatalError (void)
86{
87  /* Don't give duplicate warning if UseMsg was called */
88  if (g_fSilentFatalError)
89    return;
90
91  winMessageBoxF (
92          "A fatal error has occurred and " PROJECT_NAME " will now exit.\n" \
93		  "Please open %s for more information.\n",
94		  MB_ICONERROR, (g_pszLogFile?g_pszLogFile:"the logfile"));
95}
96#endif
97
98
99/*
100 * winMessageBoxF - Print a formatted error message in a useful
101 * message box.
102 */
103
104void
105winMessageBoxF (const char *pszError, UINT uType, ...)
106{
107  char *	pszErrorF = NULL;
108  char *	pszMsgBox = NULL;
109  va_list	args;
110
111  va_start(args, uType);
112  pszErrorF = Xvprintf(pszError, args);
113  va_end(args);
114  if (!pszErrorF)
115    goto winMessageBoxF_Cleanup;
116
117#define MESSAGEBOXF \
118	"%s\n" \
119	"Vendor: %s\n" \
120	"Release: %s\n" \
121	"Contact: %s\n" \
122	"XWin was started with the following command-line:\n\n" \
123	"%s\n"
124
125  pszMsgBox = Xprintf (MESSAGEBOXF,
126	   pszErrorF, VENDOR_STRING, VERSION_STRING, VENDOR_CONTACT,
127	   g_pszCommandLine);
128  if (!pszMsgBox)
129    goto winMessageBoxF_Cleanup;
130
131  /* Display the message box string */
132  MessageBox (NULL,
133	      pszMsgBox,
134	      PROJECT_NAME,
135	      MB_OK | uType);
136
137 winMessageBoxF_Cleanup:
138  if (pszErrorF)
139    xfree (pszErrorF);
140  if (pszMsgBox)
141    xfree (pszMsgBox);
142#undef MESSAGEBOXF
143}
144