Error.c revision 1477040f
1444c061aSmrg/* $Xorg: Error.c,v 1.5 2001/02/09 02:03:54 xorgcvs Exp $ */
2444c061aSmrg
3444c061aSmrg/***********************************************************
41477040fSmrgCopyright 1993 Sun Microsystems, Inc.  All rights reserved.
51477040fSmrg
61477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
71477040fSmrgcopy of this software and associated documentation files (the "Software"),
81477040fSmrgto deal in the Software without restriction, including without limitation
91477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
101477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
111477040fSmrgSoftware is furnished to do so, subject to the following conditions:
121477040fSmrg
131477040fSmrgThe above copyright notice and this permission notice (including the next
141477040fSmrgparagraph) shall be included in all copies or substantial portions of the
151477040fSmrgSoftware.
161477040fSmrg
171477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
181477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
201477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
211477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
221477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
231477040fSmrgDEALINGS IN THE SOFTWARE.
241477040fSmrg
251477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
26444c061aSmrg
27444c061aSmrg                        All Rights Reserved
28444c061aSmrg
29444c061aSmrgPermission to use, copy, modify, and distribute this software and its
30444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
31444c061aSmrgprovided that the above copyright notice appear in all copies and that
32444c061aSmrgboth that copyright notice and this permission notice appear in
331477040fSmrgsupporting documentation, and that the name of Digital not be
34444c061aSmrgused in advertising or publicity pertaining to distribution of the
35444c061aSmrgsoftware without specific, written prior permission.
36444c061aSmrg
37444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43444c061aSmrgSOFTWARE.
44444c061aSmrg
45444c061aSmrg******************************************************************/
46444c061aSmrg/* $XFree86: xc/lib/Xt/Error.c,v 3.13tsi Exp $ */
47444c061aSmrg
48444c061aSmrg/*
49444c061aSmrg
50444c061aSmrgCopyright 1987, 1988, 1998  The Open Group
51444c061aSmrg
52444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
53444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
54444c061aSmrgthe above copyright notice appear in all copies and that both that
55444c061aSmrgcopyright notice and this permission notice appear in supporting
56444c061aSmrgdocumentation.
57444c061aSmrg
58444c061aSmrgThe above copyright notice and this permission notice shall be included in
59444c061aSmrgall copies or substantial portions of the Software.
60444c061aSmrg
61444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
64444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
65444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
66444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67444c061aSmrg
68444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
69444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
70444c061aSmrgin this Software without prior written authorization from The Open Group.
71444c061aSmrg
72444c061aSmrg*/
73444c061aSmrg
74444c061aSmrg#ifdef HAVE_CONFIG_H
75444c061aSmrg#include <config.h>
76444c061aSmrg#endif
77444c061aSmrg#include "IntrinsicI.h"
78444c061aSmrg#include <stdio.h>
79444c061aSmrg#include <stdlib.h>
80444c061aSmrg
81444c061aSmrg/* The error handlers in the application context aren't used since we can't
82444c061aSmrg   come up with a uniform way of using them.  If you can, define
83444c061aSmrg   GLOBALERRORS to be FALSE (or 0). */
84444c061aSmrg
85444c061aSmrg#ifndef GLOBALERRORS
86444c061aSmrg#define GLOBALERRORS 1
87444c061aSmrg#endif
88444c061aSmrg
89444c061aSmrgstatic void InitErrorHandling(XrmDatabase *);
90444c061aSmrg#if GLOBALERRORS
91444c061aSmrgstatic XrmDatabase errorDB = NULL;
92444c061aSmrgstatic Boolean error_inited = FALSE;
93444c061aSmrgvoid _XtDefaultErrorMsg(String, String, String, String, String*, Cardinal*);
94444c061aSmrgvoid _XtDefaultWarningMsg(String, String, String, String, String*, Cardinal*);
95444c061aSmrgvoid _XtDefaultError(String);
96444c061aSmrgvoid _XtDefaultWarning(String);
97444c061aSmrgstatic XtErrorMsgHandler errorMsgHandler = _XtDefaultErrorMsg;
98444c061aSmrgstatic XtErrorMsgHandler warningMsgHandler = _XtDefaultWarningMsg;
99444c061aSmrgstatic XtErrorHandler errorHandler = _XtDefaultError;
100444c061aSmrgstatic XtErrorHandler warningHandler = _XtDefaultWarning;
101444c061aSmrg#endif /* GLOBALERRORS */
102444c061aSmrg
103444c061aSmrgXrmDatabase *XtGetErrorDatabase(void)
104444c061aSmrg{
105444c061aSmrg    XrmDatabase* retval;
106444c061aSmrg#if GLOBALERRORS
107444c061aSmrg    LOCK_PROCESS;
108444c061aSmrg    retval = &errorDB;
109444c061aSmrg    UNLOCK_PROCESS;
110444c061aSmrg#else
111444c061aSmrg    retval = XtAppGetErrorDatabase(_XtDefaultAppContext());
112444c061aSmrg#endif /* GLOBALERRORS */
113444c061aSmrg    return retval;
114444c061aSmrg}
115444c061aSmrg
116444c061aSmrgXrmDatabase *XtAppGetErrorDatabase(
117444c061aSmrg	XtAppContext app)
118444c061aSmrg{
119444c061aSmrg    XrmDatabase* retval;
120444c061aSmrg#if GLOBALERRORS
121444c061aSmrg    LOCK_PROCESS;
122444c061aSmrg    retval = &errorDB;
123444c061aSmrg    UNLOCK_PROCESS;
124444c061aSmrg#else
125444c061aSmrg    LOCK_APP(app);
126444c061aSmrg    retval= &app->errorDB;
127444c061aSmrg    UNLOCK_APP(app);
128444c061aSmrg#endif /* GLOBALERRORS */
129444c061aSmrg    return retval;
130444c061aSmrg}
131444c061aSmrg
132444c061aSmrgvoid XtGetErrorDatabaseText(
133444c061aSmrg    register _Xconst char* name,
134444c061aSmrg    register _Xconst char* type,
135444c061aSmrg    register _Xconst char* class,
136444c061aSmrg    _Xconst char* defaultp,
137444c061aSmrg    String buffer,
138444c061aSmrg    int nbytes)
139444c061aSmrg{
140444c061aSmrg#if GLOBALERRORS
141444c061aSmrg    XtAppGetErrorDatabaseText(NULL,
142444c061aSmrg	    name,type,class,defaultp, buffer, nbytes, NULL);
143444c061aSmrg#else
144444c061aSmrg    XtAppGetErrorDatabaseText(_XtDefaultAppContext(),
145444c061aSmrg	    name,type,class,defaultp, buffer, nbytes, NULL);
146444c061aSmrg#endif /* GLOBALERRORS */
147444c061aSmrg}
148444c061aSmrg
149444c061aSmrgvoid XtAppGetErrorDatabaseText(
150444c061aSmrg    XtAppContext app,
151444c061aSmrg    register _Xconst char* name,
152444c061aSmrg    register _Xconst char* type,
153444c061aSmrg    register _Xconst char* class,
154444c061aSmrg    _Xconst char* defaultp,
155444c061aSmrg    String buffer,
156444c061aSmrg    int nbytes,
157444c061aSmrg    XrmDatabase db)
158444c061aSmrg{
159444c061aSmrg    String str_class;
160444c061aSmrg    String type_str;
161444c061aSmrg    XrmValue result;
162444c061aSmrg    char *str_name = NULL;
163444c061aSmrg    char *temp = NULL;
164444c061aSmrg
165444c061aSmrg#if GLOBALERRORS
166444c061aSmrg    LOCK_PROCESS;
167444c061aSmrg    if (error_inited == FALSE) {
168444c061aSmrg        InitErrorHandling (&errorDB);
169444c061aSmrg        error_inited = TRUE;
170444c061aSmrg    }
171444c061aSmrg#else
172444c061aSmrg    LOCK_APP(app);
173444c061aSmrg    if (app->error_inited == FALSE) {
174444c061aSmrg        InitErrorHandling (&app->errorDB);
175444c061aSmrg        app->error_inited = TRUE;
176444c061aSmrg    }
177444c061aSmrg#endif /* GLOBALERRORS */
178444c061aSmrg    if (!(str_name = ALLOCATE_LOCAL(strlen(name) + strlen(type) + 2)))
179444c061aSmrg	_XtAllocError(NULL);
180444c061aSmrg    (void) sprintf(str_name, "%s.%s", name, type);
181444c061aSmrg    /* XrmGetResource requires the name and class to be fully qualified
182444c061aSmrg     * and to have the same number of components. */
183444c061aSmrg    str_class = (char *)class;
184444c061aSmrg    if (! strchr(class, '.')) {
185444c061aSmrg	if (!(temp = ALLOCATE_LOCAL(2 * strlen(class) + 2)))
186444c061aSmrg	    _XtAllocError(NULL);
187444c061aSmrg	(void) sprintf(temp, "%s.%s", class, class);
188444c061aSmrg	str_class = temp;
189444c061aSmrg    }
190444c061aSmrg    if (db == NULL) {
191444c061aSmrg#if GLOBALERRORS
192444c061aSmrg	(void) XrmGetResource(errorDB, str_name, str_class, &type_str,
193444c061aSmrg			      &result);
194444c061aSmrg#else
195444c061aSmrg	(void) XrmGetResource(app->errorDB, str_name, str_class, &type_str,
196444c061aSmrg			      &result);
197444c061aSmrg#endif /* GLOBALERRORS */
198444c061aSmrg    } else (void) XrmGetResource(db, str_name, str_class, &type_str, &result);
199444c061aSmrg    if (result.addr) {
200444c061aSmrg        (void) strncpy (buffer, result.addr, nbytes);
201444c061aSmrg        if (result.size > (unsigned) nbytes) buffer[nbytes-1] = 0;
202444c061aSmrg    } else {
203444c061aSmrg	int len = strlen(defaultp);
204444c061aSmrg	if (len >= nbytes) len = nbytes-1;
205444c061aSmrg	(void) memmove(buffer, defaultp, len);
206444c061aSmrg	buffer[len] = '\0';
207444c061aSmrg    }
208444c061aSmrg    if (str_name)
209444c061aSmrg	DEALLOCATE_LOCAL(str_name);
210444c061aSmrg    if (temp)
211444c061aSmrg	DEALLOCATE_LOCAL(temp);
212444c061aSmrg#if GLOBALERRORS
213444c061aSmrg    UNLOCK_PROCESS;
214444c061aSmrg#else
215444c061aSmrg    UNLOCK_APP(app);
216444c061aSmrg#endif
217444c061aSmrg}
218444c061aSmrg
219444c061aSmrgstatic void InitErrorHandling (
220444c061aSmrg    XrmDatabase *db)
221444c061aSmrg{
222444c061aSmrg    XrmDatabase errordb;
223444c061aSmrg
224444c061aSmrg    errordb = XrmGetFileDatabase(ERRORDB);
225444c061aSmrg    XrmMergeDatabases(errordb, db);
226444c061aSmrg}
227444c061aSmrg
228444c061aSmrgstatic void DefaultMsg (
229444c061aSmrg    String name,
230444c061aSmrg    String type,
231444c061aSmrg    String class,
232444c061aSmrg    String defaultp,
233444c061aSmrg    String* params,
234444c061aSmrg    Cardinal* num_params,
235444c061aSmrg    Bool error,
236444c061aSmrg    void (*fn)(_Xconst _XtString))
237444c061aSmrg{
238444c061aSmrg#define BIGBUF 1024
239444c061aSmrg#ifdef notyet /* older versions don't, might want to wait until more do */
240444c061aSmrg#if defined(__linux__)  || defined(CSRG_BASED) /* everyone else needs to get with the program */
241444c061aSmrg#define USE_SNPRINTF
242444c061aSmrg#endif
243444c061aSmrg#endif
244444c061aSmrg    char buffer[BIGBUF];
245444c061aSmrg    char* message;
246444c061aSmrg    XtGetErrorDatabaseText(name,type,class,defaultp, buffer, BIGBUF);
247444c061aSmrg/*need better solution here, perhaps use lower level printf primitives? */
248444c061aSmrg    if (params == NULL || num_params == NULL || *num_params == 0)
249444c061aSmrg	(*fn)(buffer);
250444c061aSmrg#ifndef WIN32 /* and OS/2 */
251444c061aSmrg    else if ((getuid () != geteuid ()) || getuid() == 0) {
252444c061aSmrg	if ((error && errorHandler == _XtDefaultError) ||
253444c061aSmrg	    (!error && warningHandler == _XtDefaultWarning)) {
254444c061aSmrg	    /*
255444c061aSmrg	     * if it's just going to go to stderr anyway, then we'll
256444c061aSmrg	     * fprintf to stderr ourselves and skip the insecure sprintf.
257444c061aSmrg	     */
258444c061aSmrg	    Cardinal i = *num_params;
259444c061aSmrg	    String par[10];
260444c061aSmrg	    if (i > 10) i = 10;
261444c061aSmrg	    (void) memmove((char*)par, (char*)params, i * sizeof(String) );
262444c061aSmrg	    bzero( &par[i], (10-i) * sizeof(String) );
263444c061aSmrg	    (void) fprintf (stderr, "%s%s",
264444c061aSmrg			    error ? XTERROR_PREFIX : XTWARNING_PREFIX,
265444c061aSmrg			    error ? "Error: " : "Warning: ");
266444c061aSmrg	    (void) fprintf (stderr, buffer,
267444c061aSmrg			    par[0], par[1], par[2], par[3], par[4],
268444c061aSmrg			    par[5], par[6], par[7], par[8], par[9]);
269444c061aSmrg	    (void) fprintf (stderr, "%c", '\n');
270444c061aSmrg	    if (i != *num_params)
271444c061aSmrg		(*fn) ( "Some arguments in previous message were lost" );
272444c061aSmrg	    else if (error) exit (1);
273444c061aSmrg	} else {
274444c061aSmrg	    /*
275444c061aSmrg	     * can't tell what it might do, so we'll play it safe
276444c061aSmrg	     */
277444c061aSmrg	    XtWarning ("\
278444c061aSmrgThis program is an suid-root program or is being run by the root user.\n\
279444c061aSmrgThe full text of the error or warning message cannot be safely formatted\n\
280444c061aSmrgin this environment. You may get a more descriptive message by running the\n\
281444c061aSmrgprogram as a non-root user or by removing the suid bit on the executable.");
282444c061aSmrg	    (*fn)(buffer); /* if *fn is an ErrorHandler it should exit */
283444c061aSmrg	}
284444c061aSmrg    }
285444c061aSmrg#endif
286444c061aSmrg    else {
287444c061aSmrg	/*
288444c061aSmrg	 * If you have snprintf the worst thing that could happen is you'd
289444c061aSmrg	 * lose some information. Without snprintf you're probably going to
290444c061aSmrg	 * scramble your heap and perhaps SEGV -- sooner or later.
291444c061aSmrg	 * If it hurts when you go like this then don't go like this! :-)
292444c061aSmrg	 */
293444c061aSmrg	Cardinal i = *num_params;
294444c061aSmrg	String par[10];
295444c061aSmrg	if (i > 10) i = 10;
296444c061aSmrg	(void) memmove((char*)par, (char*)params, i * sizeof(String) );
297444c061aSmrg	bzero( &par[i], (10-i) * sizeof(String) );
298444c061aSmrg	if (i != *num_params)
299444c061aSmrg	    XtWarning( "Some arguments in following message were lost" );
300444c061aSmrg	/*
301444c061aSmrg	 * resist any temptation you might have to make `message' a
302444c061aSmrg	 * local buffer on the stack. Doing so is a security hole
303444c061aSmrg	 * in programs executing as root. Error and Warning
304444c061aSmrg	 * messages shouldn't be called frequently enough for this
305444c061aSmrg	 * to be a performance issue.
306444c061aSmrg	 */
307444c061aSmrg	if ((message = __XtMalloc (BIGBUF))) {
308444c061aSmrg#ifndef USE_SNPRINTF
309444c061aSmrg	    message[BIGBUF-1] = 0;
310444c061aSmrg	    (void) sprintf (message, buffer,
311444c061aSmrg#else
312444c061aSmrg	    (void) snprintf (message, BIGBUF, buffer,
313444c061aSmrg#endif
314444c061aSmrg			    par[0], par[1], par[2], par[3], par[4],
315444c061aSmrg			    par[5], par[6], par[7], par[8], par[9]);
316444c061aSmrg#ifndef USE_SNPRINTF
317444c061aSmrg	    if (message[BIGBUF-1] != '\0')
318444c061aSmrg		XtWarning ("Possible heap corruption in Xt{Error,Warning}MsgHandler");
319444c061aSmrg#endif
320444c061aSmrg	    (*fn)(message);
321444c061aSmrg	    XtFree(message);
322444c061aSmrg	} else {
323444c061aSmrg	    XtWarning ("Memory allocation failed, arguments in the following message were lost");
324444c061aSmrg	    (*fn)(buffer);
325444c061aSmrg	}
326444c061aSmrg    }
327444c061aSmrg}
328444c061aSmrg
329444c061aSmrgvoid _XtDefaultErrorMsg (
330444c061aSmrg    String name,
331444c061aSmrg    String type,
332444c061aSmrg    String class,
333444c061aSmrg    String defaultp,
334444c061aSmrg    String* params,
335444c061aSmrg    Cardinal* num_params)
336444c061aSmrg{
337444c061aSmrg    DefaultMsg (name,type,class,defaultp,params,num_params,True,XtError);
338444c061aSmrg}
339444c061aSmrg
340444c061aSmrgvoid _XtDefaultWarningMsg (
341444c061aSmrg    String name,
342444c061aSmrg    String type,
343444c061aSmrg    String class,
344444c061aSmrg    String defaultp,
345444c061aSmrg    String* params,
346444c061aSmrg    Cardinal* num_params)
347444c061aSmrg{
348444c061aSmrg    DefaultMsg (name,type,class,defaultp,params,num_params,False,XtWarning);
349444c061aSmrg}
350444c061aSmrg
351444c061aSmrgvoid XtErrorMsg(
352444c061aSmrg    _Xconst char* name,
353444c061aSmrg    _Xconst char* type,
354444c061aSmrg    _Xconst char* class,
355444c061aSmrg    _Xconst char* defaultp,
356444c061aSmrg    String* params,
357444c061aSmrg    Cardinal* num_params)
358444c061aSmrg{
359444c061aSmrg#if GLOBALERRORS
360444c061aSmrg    LOCK_PROCESS;
361444c061aSmrg    (*errorMsgHandler)((String)name,(String)type,(String)class,
362444c061aSmrg		       (String)defaultp,params,num_params);
363444c061aSmrg    UNLOCK_PROCESS;
364444c061aSmrg#else
365444c061aSmrg    XtAppErrorMsg(_XtDefaultAppContext(),name,type,class,
366444c061aSmrg	    defaultp,params,num_params);
367444c061aSmrg#endif /* GLOBALERRORS */
368444c061aSmrg}
369444c061aSmrg
370444c061aSmrgvoid XtAppErrorMsg(
371444c061aSmrg    XtAppContext app,
372444c061aSmrg    _Xconst char* name,
373444c061aSmrg    _Xconst char* type,
374444c061aSmrg    _Xconst char* class,
375444c061aSmrg    _Xconst char* defaultp,
376444c061aSmrg    String* params,
377444c061aSmrg    Cardinal* num_params)
378444c061aSmrg{
379444c061aSmrg#if GLOBALERRORS
380444c061aSmrg    LOCK_PROCESS;
381444c061aSmrg    (*errorMsgHandler)((String)name,(String)type,(String)class,
382444c061aSmrg		       (String)defaultp,params,num_params);
383444c061aSmrg    UNLOCK_PROCESS;
384444c061aSmrg#else
385444c061aSmrg    LOCK_APP(app);
386444c061aSmrg    (*app->errorMsgHandler)(name,type,class,defaultp,params,num_params);
387444c061aSmrg    UNLOCK_APP(app);
388444c061aSmrg#endif /* GLOBALERRORS */
389444c061aSmrg}
390444c061aSmrg
391444c061aSmrgvoid XtWarningMsg(
392444c061aSmrg    _Xconst char* name,
393444c061aSmrg    _Xconst char* type,
394444c061aSmrg    _Xconst char* class,
395444c061aSmrg    _Xconst char* defaultp,
396444c061aSmrg    String* params,
397444c061aSmrg    Cardinal* num_params)
398444c061aSmrg{
399444c061aSmrg#if GLOBALERRORS
400444c061aSmrg    LOCK_PROCESS;
401444c061aSmrg    (*warningMsgHandler)((String)name,(String)type,(String)class,
402444c061aSmrg			 (String)defaultp,params,num_params);
403444c061aSmrg    UNLOCK_PROCESS;
404444c061aSmrg#else
405444c061aSmrg    XtAppWarningMsg(_XtDefaultAppContext(),name,type,class,
406444c061aSmrg	    defaultp,params,num_params);
407444c061aSmrg#endif /* GLOBALERRORS */
408444c061aSmrg}
409444c061aSmrg
410444c061aSmrgvoid XtAppWarningMsg(
411444c061aSmrg    XtAppContext app,
412444c061aSmrg    _Xconst char* name,
413444c061aSmrg    _Xconst char* type,
414444c061aSmrg    _Xconst char* class,
415444c061aSmrg    _Xconst char* defaultp,
416444c061aSmrg    String* params,
417444c061aSmrg    Cardinal* num_params)
418444c061aSmrg{
419444c061aSmrg#if GLOBALERRORS
420444c061aSmrg    LOCK_PROCESS;
421444c061aSmrg    (*warningMsgHandler)((String)name,(String)type,(String)class,
422444c061aSmrg			 (String)defaultp,params,num_params);
423444c061aSmrg    UNLOCK_PROCESS;
424444c061aSmrg#else
425444c061aSmrg    LOCK_APP(app);
426444c061aSmrg    (*app->warningMsgHandler)(name,type,class,defaultp,params,num_params);
427444c061aSmrg    UNLOCK_APP(app);
428444c061aSmrg#endif /* GLOBALERRORS */
429444c061aSmrg}
430444c061aSmrg
431444c061aSmrgvoid XtSetErrorMsgHandler(
432444c061aSmrg    XtErrorMsgHandler handler)
433444c061aSmrg{
434444c061aSmrg#if GLOBALERRORS
435444c061aSmrg    LOCK_PROCESS;
436444c061aSmrg    if (handler != NULL) errorMsgHandler = handler;
437444c061aSmrg    else errorMsgHandler  = _XtDefaultErrorMsg;
438444c061aSmrg    UNLOCK_PROCESS;
439444c061aSmrg#else
440444c061aSmrg    XtAppSetErrorMsgHandler(_XtDefaultAppContext(), handler);
441444c061aSmrg#endif /* GLOBALERRORS */
442444c061aSmrg}
443444c061aSmrg
444444c061aSmrgXtErrorMsgHandler XtAppSetErrorMsgHandler(
445444c061aSmrg    XtAppContext app,
446444c061aSmrg    XtErrorMsgHandler handler)
447444c061aSmrg{
448444c061aSmrg    XtErrorMsgHandler old;
449444c061aSmrg#if GLOBALERRORS
450444c061aSmrg    LOCK_PROCESS;
451444c061aSmrg    old = errorMsgHandler;
452444c061aSmrg    if (handler != NULL) errorMsgHandler = handler;
453444c061aSmrg    else errorMsgHandler  = _XtDefaultErrorMsg;
454444c061aSmrg    UNLOCK_PROCESS;
455444c061aSmrg#else
456444c061aSmrg    LOCK_APP(app);
457444c061aSmrg    old = app->errorMsgHandler;
458444c061aSmrg    if (handler != NULL) app->errorMsgHandler = handler;
459444c061aSmrg    else app->errorMsgHandler  = _XtDefaultErrorMsg;
460444c061aSmrg    UNLOCK_APP(app);
461444c061aSmrg#endif /* GLOBALERRORS */
462444c061aSmrg    return old;
463444c061aSmrg}
464444c061aSmrg
465444c061aSmrgvoid XtSetWarningMsgHandler(
466444c061aSmrg    XtErrorMsgHandler handler)
467444c061aSmrg{
468444c061aSmrg#if GLOBALERRORS
469444c061aSmrg    LOCK_PROCESS;
470444c061aSmrg    if (handler != NULL) warningMsgHandler  = handler;
471444c061aSmrg    else warningMsgHandler = _XtDefaultWarningMsg;
472444c061aSmrg    UNLOCK_PROCESS;
473444c061aSmrg#else
474444c061aSmrg    XtAppSetWarningMsgHandler(_XtDefaultAppContext(),handler);
475444c061aSmrg#endif /* GLOBALERRORS */
476444c061aSmrg}
477444c061aSmrg
478444c061aSmrgXtErrorMsgHandler XtAppSetWarningMsgHandler(
479444c061aSmrg    XtAppContext app,
480444c061aSmrg    XtErrorMsgHandler handler)
481444c061aSmrg{
482444c061aSmrg    XtErrorMsgHandler old;
483444c061aSmrg#if GLOBALERRORS
484444c061aSmrg    LOCK_PROCESS;
485444c061aSmrg    old = warningMsgHandler;
486444c061aSmrg    if (handler != NULL) warningMsgHandler  = handler;
487444c061aSmrg    else warningMsgHandler = _XtDefaultWarningMsg;
488444c061aSmrg    UNLOCK_PROCESS;
489444c061aSmrg#else
490444c061aSmrg    LOCK_APP(app);
491444c061aSmrg    old = app->warningMsgHandler;
492444c061aSmrg    if (handler != NULL) app->warningMsgHandler  = handler;
493444c061aSmrg    else app->warningMsgHandler = _XtDefaultWarningMsg;
494444c061aSmrg    UNLOCK_APP(app);
495444c061aSmrg#endif /* GLOBALERRORS */
496444c061aSmrg    return old;
497444c061aSmrg}
498444c061aSmrg
499444c061aSmrgvoid _XtDefaultError(String message)
500444c061aSmrg{
501444c061aSmrg    if (message && *message)
502444c061aSmrg	(void)fprintf(stderr, "%sError: %s\n", XTERROR_PREFIX, message);
503444c061aSmrg    exit(1);
504444c061aSmrg}
505444c061aSmrg
506444c061aSmrgvoid _XtDefaultWarning(String message)
507444c061aSmrg{
508444c061aSmrg    if (message && *message)
509444c061aSmrg       (void)fprintf(stderr, "%sWarning: %s\n", XTWARNING_PREFIX, message);
510444c061aSmrg    return;
511444c061aSmrg}
512444c061aSmrg
513444c061aSmrgvoid XtError(
514444c061aSmrg    _Xconst char* message)
515444c061aSmrg{
516444c061aSmrg#if GLOBALERRORS
517444c061aSmrg    LOCK_PROCESS;
518444c061aSmrg    (*errorHandler)((String)message);
519444c061aSmrg    UNLOCK_PROCESS;
520444c061aSmrg#else
521444c061aSmrg    XtAppError(_XtDefaultAppContext(),message);
522444c061aSmrg#endif /* GLOBALERRORS */
523444c061aSmrg}
524444c061aSmrg
525444c061aSmrgvoid XtAppError(
526444c061aSmrg    XtAppContext app,
527444c061aSmrg    _Xconst char* message)
528444c061aSmrg{
529444c061aSmrg#if GLOBALERRORS
530444c061aSmrg    LOCK_PROCESS;
531444c061aSmrg    (*errorHandler)((String)message);
532444c061aSmrg    UNLOCK_PROCESS;
533444c061aSmrg#else
534444c061aSmrg    LOCK_APP(app);
535444c061aSmrg    (*app->errorHandler)(message);
536444c061aSmrg    UNLOCK_APP(app);
537444c061aSmrg#endif /* GLOBALERRORS */
538444c061aSmrg}
539444c061aSmrg
540444c061aSmrgvoid XtWarning(
541444c061aSmrg    _Xconst char* message)
542444c061aSmrg{
543444c061aSmrg#if GLOBALERRORS
544444c061aSmrg    LOCK_PROCESS;
545444c061aSmrg    (*warningHandler)((String)message);
546444c061aSmrg    UNLOCK_PROCESS;
547444c061aSmrg#else
548444c061aSmrg    XtAppWarning(_XtDefaultAppContext(),message);
549444c061aSmrg#endif /* GLOBALERRORS */
550444c061aSmrg}
551444c061aSmrg
552444c061aSmrgvoid XtAppWarning(
553444c061aSmrg    XtAppContext app,
554444c061aSmrg    _Xconst char* message)
555444c061aSmrg{
556444c061aSmrg#if GLOBALERRORS
557444c061aSmrg    LOCK_PROCESS;
558444c061aSmrg    (*warningHandler)((String)message);
559444c061aSmrg    UNLOCK_PROCESS;
560444c061aSmrg#else
561444c061aSmrg    LOCK_APP(app);
562444c061aSmrg    (*app->warningHandler)(message);
563444c061aSmrg    UNLOCK_APP(app);
564444c061aSmrg#endif /* GLOBALERRORS */
565444c061aSmrg}
566444c061aSmrg
567444c061aSmrgvoid XtSetErrorHandler(XtErrorHandler handler)
568444c061aSmrg{
569444c061aSmrg#if GLOBALERRORS
570444c061aSmrg    LOCK_PROCESS;
571444c061aSmrg    if (handler != NULL) errorHandler = handler;
572444c061aSmrg    else errorHandler  = _XtDefaultError;
573444c061aSmrg    UNLOCK_PROCESS;
574444c061aSmrg#else
575444c061aSmrg    XtAppSetErrorHandler(_XtDefaultAppContext(),handler);
576444c061aSmrg#endif /* GLOBALERRORS */
577444c061aSmrg}
578444c061aSmrg
579444c061aSmrgXtErrorHandler XtAppSetErrorHandler(
580444c061aSmrg    XtAppContext app,
581444c061aSmrg    XtErrorHandler handler)
582444c061aSmrg{
583444c061aSmrg    XtErrorHandler old;
584444c061aSmrg#if GLOBALERRORS
585444c061aSmrg    LOCK_PROCESS;
586444c061aSmrg    old = errorHandler;
587444c061aSmrg    if (handler != NULL) errorHandler = handler;
588444c061aSmrg    else errorHandler  = _XtDefaultError;
589444c061aSmrg    UNLOCK_PROCESS;
590444c061aSmrg#else
591444c061aSmrg    LOCK_APP(app);
592444c061aSmrg    old = app->errorHandler;
593444c061aSmrg    if (handler != NULL) app->errorHandler = handler;
594444c061aSmrg    else app->errorHandler  = _XtDefaultError;
595444c061aSmrg    UNLOCK_APP(app);
596444c061aSmrg#endif /* GLOBALERRORS */
597444c061aSmrg    return old;
598444c061aSmrg}
599444c061aSmrg
600444c061aSmrgvoid XtSetWarningHandler(XtErrorHandler handler)
601444c061aSmrg{
602444c061aSmrg#if GLOBALERRORS
603444c061aSmrg    LOCK_PROCESS;
604444c061aSmrg    if (handler != NULL) warningHandler = handler;
605444c061aSmrg    else warningHandler = _XtDefaultWarning;
606444c061aSmrg    UNLOCK_PROCESS;
607444c061aSmrg#else
608444c061aSmrg    XtAppSetWarningHandler(_XtDefaultAppContext(),handler);
609444c061aSmrg#endif /* GLOBALERRORS */
610444c061aSmrg}
611444c061aSmrg
612444c061aSmrgXtErrorHandler XtAppSetWarningHandler(
613444c061aSmrg    XtAppContext app,
614444c061aSmrg    XtErrorHandler handler)
615444c061aSmrg{
616444c061aSmrg    XtErrorHandler old;
617444c061aSmrg#if GLOBALERRORS
618444c061aSmrg    LOCK_PROCESS;
619444c061aSmrg    old = warningHandler;
620444c061aSmrg    if (handler != NULL) warningHandler  = handler;
621444c061aSmrg    else warningHandler = _XtDefaultWarning;
622444c061aSmrg    UNLOCK_PROCESS;
623444c061aSmrg#else
624444c061aSmrg    LOCK_APP(app);
625444c061aSmrg    old = app->warningHandler;
626444c061aSmrg    if (handler != NULL) app->warningHandler  = handler;
627444c061aSmrg    else app->warningHandler = _XtDefaultWarning;
628444c061aSmrg    UNLOCK_APP(app);
629444c061aSmrg#endif /* GLOBALERRORS */
630444c061aSmrg    return old;
631444c061aSmrg}
632444c061aSmrg
633444c061aSmrgvoid _XtSetDefaultErrorHandlers(
634444c061aSmrg    XtErrorMsgHandler *errMsg,
635444c061aSmrg    XtErrorMsgHandler *warnMsg,
636444c061aSmrg    XtErrorHandler *err,
637444c061aSmrg    XtErrorHandler *warn)
638444c061aSmrg{
639444c061aSmrg#ifndef GLOBALERRORS
640444c061aSmrg    LOCK_PROCESS;
641444c061aSmrg    *errMsg = _XtDefaultErrorMsg;
642444c061aSmrg    *warnMsg = _XtDefaultWarningMsg;
643444c061aSmrg    *err = _XtDefaultError;
644444c061aSmrg    *warn = _XtDefaultWarning;
645444c061aSmrg    UNLOCK_PROCESS;
646444c061aSmrg#endif /* GLOBALERRORS */
647444c061aSmrg}
648