comp_error.c revision 76726
1/****************************************************************************
2 * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
3 *                                                                          *
4 * Permission is hereby granted, free of charge, to any person obtaining a  *
5 * 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, distribute with modifications, sublicense, and/or sell       *
9 * copies of the Software, and to permit persons to whom the Software is    *
10 * furnished to do so, subject to the following conditions:                 *
11 *                                                                          *
12 * The above copyright notice and this permission notice shall be included  *
13 * in all copies or substantial portions of the Software.                   *
14 *                                                                          *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 *                                                                          *
23 * Except as contained in this notice, the name(s) of the above copyright   *
24 * holders shall not be used in advertising or otherwise to promote the     *
25 * sale, use or other dealings in this Software without prior written       *
26 * authorization.                                                           *
27 ****************************************************************************/
28
29/****************************************************************************
30 *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31 *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32 ****************************************************************************/
33
34/*
35 *	comp_error.c -- Error message routines
36 *
37 */
38
39#include <curses.priv.h>
40
41#include <tic.h>
42
43MODULE_ID("$Id: comp_error.c,v 1.21 2000/12/10 02:55:07 tom Exp $")
44
45NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
46NCURSES_EXPORT_VAR(int)
47_nc_curr_line = 0;		/* current line # in input */
48NCURSES_EXPORT_VAR(int)
49_nc_curr_col = 0;		/* current column # in input */
50
51     static const char *sourcename;
52     static char termtype[MAX_NAME_SIZE + 1];
53
54NCURSES_EXPORT(void)
55_nc_set_source(const char *const name)
56{
57    sourcename = name;
58}
59
60NCURSES_EXPORT(void)
61_nc_set_type(const char *const name)
62{
63    termtype[0] = '\0';
64    if (name)
65	strncat(termtype, name, sizeof(termtype) - 1);
66}
67
68NCURSES_EXPORT(void)
69_nc_get_type(char *name)
70{
71    strcpy(name, termtype);
72}
73
74static inline void
75where_is_problem(void)
76{
77    fprintf(stderr, "\"%s\"", sourcename);
78    if (_nc_curr_line >= 0)
79	fprintf(stderr, ", line %d", _nc_curr_line);
80    if (_nc_curr_col >= 0)
81	fprintf(stderr, ", col %d", _nc_curr_col);
82    if (termtype[0])
83	fprintf(stderr, ", terminal '%s'", termtype);
84    fputc(':', stderr);
85    fputc(' ', stderr);
86}
87
88NCURSES_EXPORT(void)
89_nc_warning(const char *const fmt,...)
90{
91    va_list argp;
92
93    if (_nc_suppress_warnings)
94	return;
95
96    where_is_problem();
97    va_start(argp, fmt);
98    vfprintf(stderr, fmt, argp);
99    fprintf(stderr, "\n");
100    va_end(argp);
101}
102
103NCURSES_EXPORT(void)
104_nc_err_abort(const char *const fmt,...)
105{
106    va_list argp;
107
108    where_is_problem();
109    va_start(argp, fmt);
110    vfprintf(stderr, fmt, argp);
111    fprintf(stderr, "\n");
112    va_end(argp);
113    exit(EXIT_FAILURE);
114}
115
116NCURSES_EXPORT(void)
117_nc_syserr_abort(const char *const fmt,...)
118{
119    va_list argp;
120
121    where_is_problem();
122    va_start(argp, fmt);
123    vfprintf(stderr, fmt, argp);
124    fprintf(stderr, "\n");
125    va_end(argp);
126
127    /* If we're debugging, try to show where the problem occurred - this
128     * will dump core.
129     */
130#if defined(TRACE) || !defined(NDEBUG)
131    abort();
132#else
133    /* Dumping core in production code is not a good idea.
134     */
135    exit(EXIT_FAILURE);
136#endif
137}
138