Error.c revision fdf6a26f
1444c061aSmrg/***********************************************************
2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates.
31477040fSmrg
41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
51477040fSmrgcopy of this software and associated documentation files (the "Software"),
61477040fSmrgto deal in the Software without restriction, including without limitation
71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
91477040fSmrgSoftware is furnished to do so, subject to the following conditions:
101477040fSmrg
111477040fSmrgThe above copyright notice and this permission notice (including the next
121477040fSmrgparagraph) shall be included in all copies or substantial portions of the
131477040fSmrgSoftware.
141477040fSmrg
151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211477040fSmrgDEALINGS IN THE SOFTWARE.
221477040fSmrg
231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24444c061aSmrg
25444c061aSmrg                        All Rights Reserved
26444c061aSmrg
27444c061aSmrgPermission to use, copy, modify, and distribute this software and its
28444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
29444c061aSmrgprovided that the above copyright notice appear in all copies and that
30444c061aSmrgboth that copyright notice and this permission notice appear in
311477040fSmrgsupporting documentation, and that the name of Digital not be
32444c061aSmrgused in advertising or publicity pertaining to distribution of the
33444c061aSmrgsoftware without specific, written prior permission.
34444c061aSmrg
35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41444c061aSmrgSOFTWARE.
42444c061aSmrg
43444c061aSmrg******************************************************************/
44444c061aSmrg
45444c061aSmrg/*
46444c061aSmrg
47444c061aSmrgCopyright 1987, 1988, 1998  The Open Group
48444c061aSmrg
49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
51444c061aSmrgthe above copyright notice appear in all copies and that both that
52444c061aSmrgcopyright notice and this permission notice appear in supporting
53444c061aSmrgdocumentation.
54444c061aSmrg
55444c061aSmrgThe above copyright notice and this permission notice shall be included in
56444c061aSmrgall copies or substantial portions of the Software.
57444c061aSmrg
58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64444c061aSmrg
65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
67444c061aSmrgin this Software without prior written authorization from The Open Group.
68444c061aSmrg
69444c061aSmrg*/
70444c061aSmrg
71444c061aSmrg#ifdef HAVE_CONFIG_H
72444c061aSmrg#include <config.h>
73444c061aSmrg#endif
74444c061aSmrg#include "IntrinsicI.h"
75444c061aSmrg#include <stdio.h>
76444c061aSmrg#include <stdlib.h>
77444c061aSmrg
78444c061aSmrg/* The error handlers in the application context aren't used since we can't
79444c061aSmrg   come up with a uniform way of using them.  If you can, define
80444c061aSmrg   GLOBALERRORS to be FALSE (or 0). */
81444c061aSmrg
82444c061aSmrg#ifndef GLOBALERRORS
83444c061aSmrg#define GLOBALERRORS 1
84444c061aSmrg#endif
85444c061aSmrg
86444c061aSmrgstatic void InitErrorHandling(XrmDatabase *);
87a3bd7f05Smrg
88444c061aSmrg#if GLOBALERRORS
89444c061aSmrgstatic XrmDatabase errorDB = NULL;
90444c061aSmrgstatic Boolean error_inited = FALSE;
91a3bd7f05Smrgvoid _XtDefaultErrorMsg(String, String, String, String, String *, Cardinal *);
92a3bd7f05Smrgvoid _XtDefaultWarningMsg(String, String, String, String, String *, Cardinal *);
93a3bd7f05Smrgvoid
94a3bd7f05Smrg_XtDefaultError(String)
95a3bd7f05Smrg    _X_NORETURN;
96a3bd7f05Smrgvoid
97a3bd7f05Smrg_XtDefaultWarning(String);
98444c061aSmrgstatic XtErrorMsgHandler errorMsgHandler = _XtDefaultErrorMsg;
99444c061aSmrgstatic XtErrorMsgHandler warningMsgHandler = _XtDefaultWarningMsg;
1000568f49bSmrgstatic XtErrorHandler errorHandler _X_NORETURN = _XtDefaultError;
101444c061aSmrgstatic XtErrorHandler warningHandler = _XtDefaultWarning;
102a3bd7f05Smrg#endif                          /* GLOBALERRORS */
103444c061aSmrg
104a3bd7f05SmrgXrmDatabase *
105a3bd7f05SmrgXtGetErrorDatabase(void)
106444c061aSmrg{
107a3bd7f05Smrg    XrmDatabase *retval;
108a3bd7f05Smrg
109444c061aSmrg#if GLOBALERRORS
110444c061aSmrg    LOCK_PROCESS;
111444c061aSmrg    retval = &errorDB;
112444c061aSmrg    UNLOCK_PROCESS;
113444c061aSmrg#else
114444c061aSmrg    retval = XtAppGetErrorDatabase(_XtDefaultAppContext());
115a3bd7f05Smrg#endif                          /* GLOBALERRORS */
116444c061aSmrg    return retval;
117444c061aSmrg}
118444c061aSmrg
119a3bd7f05SmrgXrmDatabase *
120a3bd7f05SmrgXtAppGetErrorDatabase(XtAppContext app _X_UNUSED)
121444c061aSmrg{
122a3bd7f05Smrg    XrmDatabase *retval;
123a3bd7f05Smrg
124444c061aSmrg#if GLOBALERRORS
125444c061aSmrg    LOCK_PROCESS;
126444c061aSmrg    retval = &errorDB;
127444c061aSmrg    UNLOCK_PROCESS;
128444c061aSmrg#else
129444c061aSmrg    LOCK_APP(app);
130a3bd7f05Smrg    retval = &app->errorDB;
131444c061aSmrg    UNLOCK_APP(app);
132a3bd7f05Smrg#endif                          /* GLOBALERRORS */
133444c061aSmrg    return retval;
134444c061aSmrg}
135444c061aSmrg
136a3bd7f05Smrgvoid
137a3bd7f05SmrgXtGetErrorDatabaseText(register _Xconst char *name,
138a3bd7f05Smrg                       register _Xconst char *type,
139a3bd7f05Smrg                       register _Xconst char *class,
140a3bd7f05Smrg                       _Xconst char *defaultp,
141a3bd7f05Smrg                       _XtString buffer, int nbytes)
142444c061aSmrg{
143444c061aSmrg#if GLOBALERRORS
144444c061aSmrg    XtAppGetErrorDatabaseText(NULL,
145a3bd7f05Smrg                              name, type, class, defaultp, buffer, nbytes,
146a3bd7f05Smrg                              NULL);
147444c061aSmrg#else
148444c061aSmrg    XtAppGetErrorDatabaseText(_XtDefaultAppContext(),
149a3bd7f05Smrg                              name, type, class, defaultp, buffer, nbytes,
150a3bd7f05Smrg                              NULL);
151a3bd7f05Smrg#endif                          /* GLOBALERRORS */
152444c061aSmrg}
153444c061aSmrg
154a3bd7f05Smrgvoid
155a3bd7f05SmrgXtAppGetErrorDatabaseText(XtAppContext app _X_UNUSED,
156a3bd7f05Smrg                          register _Xconst char *name,
157a3bd7f05Smrg                          register _Xconst char *type,
158a3bd7f05Smrg                          register _Xconst char *class,
159a3bd7f05Smrg                          _Xconst char *defaultp,
160a3bd7f05Smrg                          _XtString buffer,
161a3bd7f05Smrg                          int nbytes,
162a3bd7f05Smrg                          XrmDatabase db)
163444c061aSmrg{
164444c061aSmrg    String str_class;
1650568f49bSmrg    _XtString type_str;
166444c061aSmrg    XrmValue result;
167444c061aSmrg    char *str_name = NULL;
168444c061aSmrg    char *temp = NULL;
169444c061aSmrg
170444c061aSmrg#if GLOBALERRORS
171444c061aSmrg    LOCK_PROCESS;
172444c061aSmrg    if (error_inited == FALSE) {
173a3bd7f05Smrg        InitErrorHandling(&errorDB);
174444c061aSmrg        error_inited = TRUE;
175444c061aSmrg    }
176444c061aSmrg#else
177444c061aSmrg    LOCK_APP(app);
178444c061aSmrg    if (app->error_inited == FALSE) {
179a3bd7f05Smrg        InitErrorHandling(&app->errorDB);
180444c061aSmrg        app->error_inited = TRUE;
181444c061aSmrg    }
182a3bd7f05Smrg#endif                          /* GLOBALERRORS */
183444c061aSmrg    if (!(str_name = ALLOCATE_LOCAL(strlen(name) + strlen(type) + 2)))
184a3bd7f05Smrg        _XtAllocError(NULL);
185444c061aSmrg    (void) sprintf(str_name, "%s.%s", name, type);
186444c061aSmrg    /* XrmGetResource requires the name and class to be fully qualified
187444c061aSmrg     * and to have the same number of components. */
188a3bd7f05Smrg    str_class = (String) class;
189a3bd7f05Smrg    if (!strchr(class, '.')) {
190a3bd7f05Smrg        if (!(temp = ALLOCATE_LOCAL(2 * strlen(class) + 2)))
191a3bd7f05Smrg            _XtAllocError(NULL);
192a3bd7f05Smrg        (void) sprintf(temp, "%s.%s", class, class);
193a3bd7f05Smrg        str_class = temp;
194444c061aSmrg    }
195444c061aSmrg    if (db == NULL) {
196444c061aSmrg#if GLOBALERRORS
197a3bd7f05Smrg        (void) XrmGetResource(errorDB, str_name, str_class, &type_str, &result);
198444c061aSmrg#else
199a3bd7f05Smrg        (void) XrmGetResource(app->errorDB, str_name, str_class, &type_str,
200a3bd7f05Smrg                              &result);
201a3bd7f05Smrg#endif                          /* GLOBALERRORS */
202a3bd7f05Smrg    }
203a3bd7f05Smrg    else
204a3bd7f05Smrg        (void) XrmGetResource(db, str_name, str_class, &type_str, &result);
205444c061aSmrg    if (result.addr) {
206a3bd7f05Smrg        (void) strncpy(buffer, result.addr, (size_t) nbytes);
207a3bd7f05Smrg        if (result.size > (unsigned) nbytes)
208a3bd7f05Smrg            buffer[nbytes - 1] = 0;
209a3bd7f05Smrg    }
210a3bd7f05Smrg    else {
211a3bd7f05Smrg        int len = (int) strlen(defaultp);
212a3bd7f05Smrg
213a3bd7f05Smrg        if (len >= nbytes)
214a3bd7f05Smrg            len = nbytes - 1;
215a3bd7f05Smrg        (void) memmove(buffer, defaultp, (size_t) len);
216a3bd7f05Smrg        buffer[len] = '\0';
217444c061aSmrg    }
218444c061aSmrg    if (str_name)
219a3bd7f05Smrg        DEALLOCATE_LOCAL(str_name);
220444c061aSmrg    if (temp)
221a3bd7f05Smrg        DEALLOCATE_LOCAL(temp);
222444c061aSmrg#if GLOBALERRORS
223444c061aSmrg    UNLOCK_PROCESS;
224444c061aSmrg#else
225444c061aSmrg    UNLOCK_APP(app);
226444c061aSmrg#endif
227444c061aSmrg}
228444c061aSmrg
229a3bd7f05Smrgstatic void
230a3bd7f05SmrgInitErrorHandling(XrmDatabase *db)
231444c061aSmrg{
232444c061aSmrg    XrmDatabase errordb;
233444c061aSmrg
234444c061aSmrg    errordb = XrmGetFileDatabase(ERRORDB);
235444c061aSmrg    XrmMergeDatabases(errordb, db);
236444c061aSmrg}
237444c061aSmrg
238a3bd7f05Smrgstatic void
239a3bd7f05SmrgDefaultMsg(String name,
240a3bd7f05Smrg           String type,
241a3bd7f05Smrg           String class,
242a3bd7f05Smrg           String defaultp,
243a3bd7f05Smrg           String *params,
244fdf6a26fSmrg           const Cardinal *num_params,
245a3bd7f05Smrg           Bool error,
246a3bd7f05Smrg           void (*fn) (_Xconst _XtString))
247444c061aSmrg{
248444c061aSmrg#define BIGBUF 1024
249444c061aSmrg    char buffer[BIGBUF];
250a3bd7f05Smrg    char *message;
251a3bd7f05Smrg
252a3bd7f05Smrg    XtGetErrorDatabaseText(name, type, class, defaultp, buffer, BIGBUF);
253444c061aSmrg/*need better solution here, perhaps use lower level printf primitives? */
254444c061aSmrg    if (params == NULL || num_params == NULL || *num_params == 0)
255a3bd7f05Smrg        (*fn) (buffer);
256a3bd7f05Smrg#ifndef WIN32                   /* and OS/2 */
257a3bd7f05Smrg    else if ((getuid() != geteuid()) || getuid() == 0) {
258a3bd7f05Smrg        if ((error && errorHandler == _XtDefaultError) ||
259a3bd7f05Smrg            (!error && warningHandler == _XtDefaultWarning)) {
260a3bd7f05Smrg            /*
261a3bd7f05Smrg             * if it's just going to go to stderr anyway, then we'll
262a3bd7f05Smrg             * fprintf to stderr ourselves and skip the insecure sprintf.
263a3bd7f05Smrg             */
264a3bd7f05Smrg            Cardinal i = *num_params;
265a3bd7f05Smrg            String par[10];
266a3bd7f05Smrg
267a3bd7f05Smrg            if (i > 10)
268a3bd7f05Smrg                i = 10;
269fdf6a26fSmrg            (void) memcpy(par, params, i * sizeof(String));
270a3bd7f05Smrg            memset(&par[i], 0, (10 - i) * sizeof(String));
271a3bd7f05Smrg            (void) fprintf(stderr, "%s%s",
272a3bd7f05Smrg                           error ? XTERROR_PREFIX : XTWARNING_PREFIX,
273a3bd7f05Smrg                           error ? "Error: " : "Warning: ");
274a3bd7f05Smrg            (void) fprintf(stderr, buffer,
275a3bd7f05Smrg                           par[0], par[1], par[2], par[3], par[4],
276a3bd7f05Smrg                           par[5], par[6], par[7], par[8], par[9]);
277a3bd7f05Smrg            (void) fprintf(stderr, "%c", '\n');
278a3bd7f05Smrg            if (i != *num_params)
279a3bd7f05Smrg                (*fn) ("Some arguments in previous message were lost");
280a3bd7f05Smrg            else if (error)
281a3bd7f05Smrg                exit(1);
282a3bd7f05Smrg        }
283a3bd7f05Smrg        else {
284a3bd7f05Smrg            /*
285a3bd7f05Smrg             * can't tell what it might do, so we'll play it safe
286a3bd7f05Smrg             */
287a3bd7f05Smrg            XtWarning("\
288444c061aSmrgThis program is an suid-root program or is being run by the root user.\n\
289444c061aSmrgThe full text of the error or warning message cannot be safely formatted\n\
290444c061aSmrgin this environment. You may get a more descriptive message by running the\n\
291444c061aSmrgprogram as a non-root user or by removing the suid bit on the executable.");
292a3bd7f05Smrg            (*fn) (buffer);     /* if *fn is an ErrorHandler it should exit */
293a3bd7f05Smrg        }
294444c061aSmrg    }
295444c061aSmrg#endif
296444c061aSmrg    else {
297a3bd7f05Smrg        /*
298a3bd7f05Smrg         * If you have snprintf the worst thing that could happen is you'd
299a3bd7f05Smrg         * lose some information. Without snprintf you're probably going to
300a3bd7f05Smrg         * scramble your heap and perhaps SEGV -- sooner or later.
301a3bd7f05Smrg         * If it hurts when you go like this then don't go like this! :-)
302a3bd7f05Smrg         */
303a3bd7f05Smrg        Cardinal i = *num_params;
304a3bd7f05Smrg        String par[10];
305a3bd7f05Smrg
306a3bd7f05Smrg        if (i > 10)
307a3bd7f05Smrg            i = 10;
308fdf6a26fSmrg        (void) memcpy(par, params, i * sizeof(String));
309a3bd7f05Smrg        memset(&par[i], 0, (10 - i) * sizeof(String));
310a3bd7f05Smrg        if (i != *num_params)
311a3bd7f05Smrg            XtWarning("Some arguments in following message were lost");
312a3bd7f05Smrg        /*
313a3bd7f05Smrg         * resist any temptation you might have to make `message' a
314a3bd7f05Smrg         * local buffer on the stack. Doing so is a security hole
315a3bd7f05Smrg         * in programs executing as root. Error and Warning
316a3bd7f05Smrg         * messages shouldn't be called frequently enough for this
317a3bd7f05Smrg         * to be a performance issue.
318a3bd7f05Smrg         */
319a3bd7f05Smrg        if ((message = __XtMalloc(BIGBUF))) {
320a3bd7f05Smrg            (void) snprintf(message, BIGBUF, buffer,
321a3bd7f05Smrg                            par[0], par[1], par[2], par[3], par[4],
322a3bd7f05Smrg                            par[5], par[6], par[7], par[8], par[9]);
323a3bd7f05Smrg            (*fn) (message);
324a3bd7f05Smrg            XtFree(message);
325a3bd7f05Smrg        }
326a3bd7f05Smrg        else {
327a3bd7f05Smrg            XtWarning
328a3bd7f05Smrg                ("Memory allocation failed, arguments in the following message were lost");
329a3bd7f05Smrg            (*fn) (buffer);
330a3bd7f05Smrg        }
331444c061aSmrg    }
332444c061aSmrg}
333444c061aSmrg
334a3bd7f05Smrgvoid
335a3bd7f05Smrg_XtDefaultErrorMsg(String name,
336a3bd7f05Smrg                   String type,
337a3bd7f05Smrg                   String class,
338a3bd7f05Smrg                   String defaultp,
339a3bd7f05Smrg                   String *params,
340a3bd7f05Smrg                   Cardinal *num_params)
341444c061aSmrg{
342a3bd7f05Smrg    DefaultMsg(name, type, class, defaultp, params, num_params, True, XtError);
343444c061aSmrg}
344444c061aSmrg
345a3bd7f05Smrgvoid
346a3bd7f05Smrg_XtDefaultWarningMsg(String name,
347a3bd7f05Smrg                     String type,
348a3bd7f05Smrg                     String class,
349a3bd7f05Smrg                     String defaultp,
350a3bd7f05Smrg                     String *params,
351a3bd7f05Smrg                     Cardinal *num_params)
352444c061aSmrg{
353a3bd7f05Smrg    DefaultMsg(name, type, class, defaultp, params, num_params, False,
354a3bd7f05Smrg               XtWarning);
355444c061aSmrg}
356444c061aSmrg
357a3bd7f05Smrgvoid
358a3bd7f05SmrgXtErrorMsg(_Xconst char *name,
359a3bd7f05Smrg           _Xconst char *type,
360a3bd7f05Smrg           _Xconst char *class,
361a3bd7f05Smrg           _Xconst char *defaultp,
362a3bd7f05Smrg           String *params,
363a3bd7f05Smrg           Cardinal *num_params)
364444c061aSmrg{
365444c061aSmrg#if GLOBALERRORS
366444c061aSmrg    LOCK_PROCESS;
367a3bd7f05Smrg    (*errorMsgHandler) ((String) name, (String) type, (String) class,
368a3bd7f05Smrg                        (String) defaultp, params, num_params);
369444c061aSmrg    UNLOCK_PROCESS;
3700568f49bSmrg    exit(1);
371444c061aSmrg#else
372a3bd7f05Smrg    XtAppErrorMsg(_XtDefaultAppContext(), name, type, class,
373a3bd7f05Smrg                  defaultp, params, num_params);
374a3bd7f05Smrg#endif                          /* GLOBALERRORS */
375444c061aSmrg}
376444c061aSmrg
377a3bd7f05Smrgvoid
378a3bd7f05SmrgXtAppErrorMsg(XtAppContext app _X_UNUSED,
379a3bd7f05Smrg              _Xconst char *name,
380a3bd7f05Smrg              _Xconst char *type,
381a3bd7f05Smrg              _Xconst char *class,
382a3bd7f05Smrg              _Xconst char *defaultp,
383a3bd7f05Smrg              String *params,
384a3bd7f05Smrg              Cardinal *num_params)
385444c061aSmrg{
386444c061aSmrg#if GLOBALERRORS
387444c061aSmrg    LOCK_PROCESS;
388a3bd7f05Smrg    (*errorMsgHandler) ((String) name, (String) type, (String) class,
389a3bd7f05Smrg                        (String) defaultp, params, num_params);
390444c061aSmrg    UNLOCK_PROCESS;
3910568f49bSmrg    exit(1);
392444c061aSmrg#else
393444c061aSmrg    LOCK_APP(app);
394a3bd7f05Smrg    (*app->errorMsgHandler) (name, type, class, defaultp, params, num_params);
395444c061aSmrg    UNLOCK_APP(app);
396a3bd7f05Smrg#endif                          /* GLOBALERRORS */
397444c061aSmrg}
398444c061aSmrg
399a3bd7f05Smrgvoid
400a3bd7f05SmrgXtWarningMsg(_Xconst char *name,
401a3bd7f05Smrg             _Xconst char *type,
402a3bd7f05Smrg             _Xconst char *class,
403a3bd7f05Smrg             _Xconst char *defaultp,
404a3bd7f05Smrg             String *params,
405a3bd7f05Smrg             Cardinal *num_params)
406444c061aSmrg{
407444c061aSmrg#if GLOBALERRORS
408444c061aSmrg    LOCK_PROCESS;
409a3bd7f05Smrg    (*warningMsgHandler) ((String) name, (String) type, (String) class,
410a3bd7f05Smrg                          (String) defaultp, params, num_params);
411444c061aSmrg    UNLOCK_PROCESS;
412444c061aSmrg#else
413a3bd7f05Smrg    XtAppWarningMsg(_XtDefaultAppContext(), name, type, class,
414a3bd7f05Smrg                    defaultp, params, num_params);
415a3bd7f05Smrg#endif                          /* GLOBALERRORS */
416444c061aSmrg}
417444c061aSmrg
418a3bd7f05Smrgvoid
419a3bd7f05SmrgXtAppWarningMsg(XtAppContext app _X_UNUSED,
420a3bd7f05Smrg                _Xconst char *name,
421a3bd7f05Smrg                _Xconst char *type,
422a3bd7f05Smrg                _Xconst char *class,
423a3bd7f05Smrg                _Xconst char *defaultp,
424a3bd7f05Smrg                String *params,
425a3bd7f05Smrg                Cardinal *num_params)
426444c061aSmrg{
427444c061aSmrg#if GLOBALERRORS
428444c061aSmrg    LOCK_PROCESS;
429a3bd7f05Smrg    (*warningMsgHandler) ((String) name, (String) type, (String) class,
430a3bd7f05Smrg                          (String) defaultp, params, num_params);
431444c061aSmrg    UNLOCK_PROCESS;
432444c061aSmrg#else
433444c061aSmrg    LOCK_APP(app);
434a3bd7f05Smrg    (*app->warningMsgHandler) (name, type, class, defaultp, params, num_params);
435444c061aSmrg    UNLOCK_APP(app);
436a3bd7f05Smrg#endif                          /* GLOBALERRORS */
437444c061aSmrg}
438444c061aSmrg
439a3bd7f05Smrgvoid
440a3bd7f05SmrgXtSetErrorMsgHandler(XtErrorMsgHandler handler _X_NORETURN)
441444c061aSmrg{
442444c061aSmrg#if GLOBALERRORS
443444c061aSmrg    LOCK_PROCESS;
444a3bd7f05Smrg    if (handler != NULL)
445a3bd7f05Smrg        errorMsgHandler = handler;
446a3bd7f05Smrg    else
447a3bd7f05Smrg        errorMsgHandler = _XtDefaultErrorMsg;
448444c061aSmrg    UNLOCK_PROCESS;
449444c061aSmrg#else
450444c061aSmrg    XtAppSetErrorMsgHandler(_XtDefaultAppContext(), handler);
451a3bd7f05Smrg#endif                          /* GLOBALERRORS */
452444c061aSmrg}
453444c061aSmrg
454a3bd7f05SmrgXtErrorMsgHandler
455a3bd7f05SmrgXtAppSetErrorMsgHandler(XtAppContext app _X_UNUSED,
456a3bd7f05Smrg                        XtErrorMsgHandler handler _X_NORETURN)
457444c061aSmrg{
458444c061aSmrg    XtErrorMsgHandler old;
459a3bd7f05Smrg
460444c061aSmrg#if GLOBALERRORS
461444c061aSmrg    LOCK_PROCESS;
462444c061aSmrg    old = errorMsgHandler;
463a3bd7f05Smrg    if (handler != NULL)
464a3bd7f05Smrg        errorMsgHandler = handler;
465a3bd7f05Smrg    else
466a3bd7f05Smrg        errorMsgHandler = _XtDefaultErrorMsg;
467444c061aSmrg    UNLOCK_PROCESS;
468444c061aSmrg#else
469444c061aSmrg    LOCK_APP(app);
470444c061aSmrg    old = app->errorMsgHandler;
471a3bd7f05Smrg    if (handler != NULL)
472a3bd7f05Smrg        app->errorMsgHandler = handler;
473a3bd7f05Smrg    else
474a3bd7f05Smrg        app->errorMsgHandler = _XtDefaultErrorMsg;
475444c061aSmrg    UNLOCK_APP(app);
476a3bd7f05Smrg#endif                          /* GLOBALERRORS */
477444c061aSmrg    return old;
478444c061aSmrg}
479444c061aSmrg
480a3bd7f05Smrgvoid
481a3bd7f05SmrgXtSetWarningMsgHandler(XtErrorMsgHandler handler)
482444c061aSmrg{
483444c061aSmrg#if GLOBALERRORS
484444c061aSmrg    LOCK_PROCESS;
485a3bd7f05Smrg    if (handler != NULL)
486a3bd7f05Smrg        warningMsgHandler = handler;
487a3bd7f05Smrg    else
488a3bd7f05Smrg        warningMsgHandler = _XtDefaultWarningMsg;
489444c061aSmrg    UNLOCK_PROCESS;
490444c061aSmrg#else
491a3bd7f05Smrg    XtAppSetWarningMsgHandler(_XtDefaultAppContext(), handler);
492a3bd7f05Smrg#endif                          /* GLOBALERRORS */
493444c061aSmrg}
494444c061aSmrg
495a3bd7f05SmrgXtErrorMsgHandler
496a3bd7f05SmrgXtAppSetWarningMsgHandler(XtAppContext app _X_UNUSED, XtErrorMsgHandler handler)
497444c061aSmrg{
498444c061aSmrg    XtErrorMsgHandler old;
499a3bd7f05Smrg
500444c061aSmrg#if GLOBALERRORS
501444c061aSmrg    LOCK_PROCESS;
502444c061aSmrg    old = warningMsgHandler;
503a3bd7f05Smrg    if (handler != NULL)
504a3bd7f05Smrg        warningMsgHandler = handler;
505a3bd7f05Smrg    else
506a3bd7f05Smrg        warningMsgHandler = _XtDefaultWarningMsg;
507444c061aSmrg    UNLOCK_PROCESS;
508444c061aSmrg#else
509444c061aSmrg    LOCK_APP(app);
510444c061aSmrg    old = app->warningMsgHandler;
511a3bd7f05Smrg    if (handler != NULL)
512a3bd7f05Smrg        app->warningMsgHandler = handler;
513a3bd7f05Smrg    else
514a3bd7f05Smrg        app->warningMsgHandler = _XtDefaultWarningMsg;
515444c061aSmrg    UNLOCK_APP(app);
516a3bd7f05Smrg#endif                          /* GLOBALERRORS */
517444c061aSmrg    return old;
518444c061aSmrg}
519444c061aSmrg
520a3bd7f05Smrgvoid
521a3bd7f05Smrg_XtDefaultError(String message)
522444c061aSmrg{
523444c061aSmrg    if (message && *message)
524a3bd7f05Smrg        (void) fprintf(stderr, "%sError: %s\n", XTERROR_PREFIX, message);
525444c061aSmrg    exit(1);
526444c061aSmrg}
527444c061aSmrg
528a3bd7f05Smrgvoid
529a3bd7f05Smrg_XtDefaultWarning(String message)
530444c061aSmrg{
531444c061aSmrg    if (message && *message)
532a3bd7f05Smrg        (void) fprintf(stderr, "%sWarning: %s\n", XTWARNING_PREFIX, message);
533444c061aSmrg    return;
534444c061aSmrg}
535444c061aSmrg
536a3bd7f05Smrgvoid
537a3bd7f05SmrgXtError(_Xconst char *message)
538444c061aSmrg{
539444c061aSmrg#if GLOBALERRORS
540444c061aSmrg    LOCK_PROCESS;
541a3bd7f05Smrg    (*errorHandler) ((String) message);
542444c061aSmrg    UNLOCK_PROCESS;
543444c061aSmrg#else
544a3bd7f05Smrg    XtAppError(_XtDefaultAppContext(), message);
545a3bd7f05Smrg#endif                          /* GLOBALERRORS */
546444c061aSmrg}
547444c061aSmrg
548a3bd7f05Smrgvoid
549a3bd7f05SmrgXtAppError(XtAppContext app _X_UNUSED, _Xconst char *message)
550444c061aSmrg{
551444c061aSmrg#if GLOBALERRORS
552444c061aSmrg    LOCK_PROCESS;
553a3bd7f05Smrg    (*errorHandler) ((String) message);
554444c061aSmrg    UNLOCK_PROCESS;
555444c061aSmrg#else
556444c061aSmrg    LOCK_APP(app);
557a3bd7f05Smrg    (*app->errorHandler) (message);
558444c061aSmrg    UNLOCK_APP(app);
559a3bd7f05Smrg#endif                          /* GLOBALERRORS */
560444c061aSmrg}
561444c061aSmrg
562a3bd7f05Smrgvoid
563a3bd7f05SmrgXtWarning(_Xconst char *message)
564444c061aSmrg{
565444c061aSmrg#if GLOBALERRORS
566444c061aSmrg    LOCK_PROCESS;
567a3bd7f05Smrg    (*warningHandler) ((String) message);
568444c061aSmrg    UNLOCK_PROCESS;
569444c061aSmrg#else
570a3bd7f05Smrg    XtAppWarning(_XtDefaultAppContext(), message);
571a3bd7f05Smrg#endif                          /* GLOBALERRORS */
572444c061aSmrg}
573444c061aSmrg
574a3bd7f05Smrgvoid
575a3bd7f05SmrgXtAppWarning(XtAppContext app _X_UNUSED, _Xconst char *message)
576444c061aSmrg{
577444c061aSmrg#if GLOBALERRORS
578444c061aSmrg    LOCK_PROCESS;
579a3bd7f05Smrg    (*warningHandler) ((String) message);
580444c061aSmrg    UNLOCK_PROCESS;
581444c061aSmrg#else
582444c061aSmrg    LOCK_APP(app);
583a3bd7f05Smrg    (*app->warningHandler) (message);
584444c061aSmrg    UNLOCK_APP(app);
585a3bd7f05Smrg#endif                          /* GLOBALERRORS */
586444c061aSmrg}
587444c061aSmrg
588a3bd7f05Smrgvoid
589a3bd7f05SmrgXtSetErrorHandler(XtErrorHandler handler _X_NORETURN)
590444c061aSmrg{
591444c061aSmrg#if GLOBALERRORS
592444c061aSmrg    LOCK_PROCESS;
593a3bd7f05Smrg    if (handler != NULL)
594a3bd7f05Smrg        errorHandler = handler;
595a3bd7f05Smrg    else
596a3bd7f05Smrg        errorHandler = _XtDefaultError;
597444c061aSmrg    UNLOCK_PROCESS;
598444c061aSmrg#else
599a3bd7f05Smrg    XtAppSetErrorHandler(_XtDefaultAppContext(), handler);
600a3bd7f05Smrg#endif                          /* GLOBALERRORS */
601444c061aSmrg}
602444c061aSmrg
603a3bd7f05SmrgXtErrorHandler
604a3bd7f05SmrgXtAppSetErrorHandler(XtAppContext app _X_UNUSED,
605a3bd7f05Smrg                     XtErrorHandler handler _X_NORETURN)
606444c061aSmrg{
607444c061aSmrg    XtErrorHandler old;
608a3bd7f05Smrg
609444c061aSmrg#if GLOBALERRORS
610444c061aSmrg    LOCK_PROCESS;
611444c061aSmrg    old = errorHandler;
612a3bd7f05Smrg    if (handler != NULL)
613a3bd7f05Smrg        errorHandler = handler;
614a3bd7f05Smrg    else
615a3bd7f05Smrg        errorHandler = _XtDefaultError;
616444c061aSmrg    UNLOCK_PROCESS;
617444c061aSmrg#else
618444c061aSmrg    LOCK_APP(app);
619444c061aSmrg    old = app->errorHandler;
620a3bd7f05Smrg    if (handler != NULL)
621a3bd7f05Smrg        app->errorHandler = handler;
622a3bd7f05Smrg    else
623a3bd7f05Smrg        app->errorHandler = _XtDefaultError;
624444c061aSmrg    UNLOCK_APP(app);
625a3bd7f05Smrg#endif                          /* GLOBALERRORS */
626444c061aSmrg    return old;
627444c061aSmrg}
628444c061aSmrg
629a3bd7f05Smrgvoid
630a3bd7f05SmrgXtSetWarningHandler(XtErrorHandler handler)
631444c061aSmrg{
632444c061aSmrg#if GLOBALERRORS
633444c061aSmrg    LOCK_PROCESS;
634a3bd7f05Smrg    if (handler != NULL)
635a3bd7f05Smrg        warningHandler = handler;
636a3bd7f05Smrg    else
637a3bd7f05Smrg        warningHandler = _XtDefaultWarning;
638444c061aSmrg    UNLOCK_PROCESS;
639444c061aSmrg#else
640a3bd7f05Smrg    XtAppSetWarningHandler(_XtDefaultAppContext(), handler);
641a3bd7f05Smrg#endif                          /* GLOBALERRORS */
642444c061aSmrg}
643444c061aSmrg
644a3bd7f05SmrgXtErrorHandler
645a3bd7f05SmrgXtAppSetWarningHandler(XtAppContext app _X_UNUSED, XtErrorHandler handler)
646444c061aSmrg{
647444c061aSmrg    XtErrorHandler old;
648a3bd7f05Smrg
649444c061aSmrg#if GLOBALERRORS
650444c061aSmrg    LOCK_PROCESS;
651444c061aSmrg    old = warningHandler;
652a3bd7f05Smrg    if (handler != NULL)
653a3bd7f05Smrg        warningHandler = handler;
654a3bd7f05Smrg    else
655a3bd7f05Smrg        warningHandler = _XtDefaultWarning;
656444c061aSmrg    UNLOCK_PROCESS;
657444c061aSmrg#else
658444c061aSmrg    LOCK_APP(app);
659444c061aSmrg    old = app->warningHandler;
660a3bd7f05Smrg    if (handler != NULL)
661a3bd7f05Smrg        app->warningHandler = handler;
662a3bd7f05Smrg    else
663a3bd7f05Smrg        app->warningHandler = _XtDefaultWarning;
664444c061aSmrg    UNLOCK_APP(app);
665a3bd7f05Smrg#endif                          /* GLOBALERRORS */
666444c061aSmrg    return old;
667444c061aSmrg}
668444c061aSmrg
669a3bd7f05Smrgvoid
670a3bd7f05Smrg_XtSetDefaultErrorHandlers(XtErrorMsgHandler *errMsg _X_UNUSED,
671a3bd7f05Smrg                           XtErrorMsgHandler *warnMsg _X_UNUSED,
672a3bd7f05Smrg                           XtErrorHandler *err _X_UNUSED,
673a3bd7f05Smrg                           XtErrorHandler *warn _X_UNUSED)
674444c061aSmrg{
675444c061aSmrg#ifndef GLOBALERRORS
676444c061aSmrg    LOCK_PROCESS;
677444c061aSmrg    *errMsg = _XtDefaultErrorMsg;
678444c061aSmrg    *warnMsg = _XtDefaultWarningMsg;
679444c061aSmrg    *err = _XtDefaultError;
680444c061aSmrg    *warn = _XtDefaultWarning;
681444c061aSmrg    UNLOCK_PROCESS;
682a3bd7f05Smrg#endif                          /* GLOBALERRORS */
683444c061aSmrg}
684