1 /****************************************************************************
2 * Copyright 2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2012,2016 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 ****************************************************************************/
37 * comp_error.c -- Error message routines
41 #include <curses.priv.h>
45 MODULE_ID("$Id: comp_error.c,v 1.40 2020/02/02 23:34:34 tom Exp $")
47 NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
48 NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
49 NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
51 #define SourceName _nc_globals.comp_sourcename
52 #define TermType _nc_globals.comp_termtype
54 NCURSES_EXPORT(const char *)
61 _nc_set_source(const char *const name)
63 FreeIfNeeded(SourceName);
64 SourceName = strdup(name);
68 _nc_set_type(const char *const name)
70 #define MY_SIZE (size_t) MAX_NAME_SIZE
72 TermType = typeMalloc(char, MY_SIZE + 1);
76 _nc_STRNCAT(TermType, name, MY_SIZE, MY_SIZE);
82 _nc_get_type(char *name)
85 if (name == 0 && TermType != 0) {
86 FreeAndNull(TermType);
91 _nc_STRCPY(name, TermType != 0 ? TermType : "", MAX_NAME_SIZE);
94 static NCURSES_INLINE void
95 where_is_problem(void)
97 fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?");
98 if (_nc_curr_line >= 0)
99 fprintf(stderr, ", line %d", _nc_curr_line);
100 if (_nc_curr_col >= 0)
101 fprintf(stderr, ", col %d", _nc_curr_col);
102 if (TermType != 0 && TermType[0] != '\0')
103 fprintf(stderr, ", terminal '%s'", TermType);
109 _nc_warning(const char *const fmt, ...)
113 if (_nc_suppress_warnings)
118 vfprintf(stderr, fmt, argp);
119 fprintf(stderr, "\n");
124 _nc_err_abort(const char *const fmt, ...)
130 vfprintf(stderr, fmt, argp);
131 fprintf(stderr, "\n");
137 _nc_syserr_abort(const char *const fmt, ...)
143 vfprintf(stderr, fmt, argp);
144 fprintf(stderr, "\n");
147 #if defined(TRACE) || !defined(NDEBUG)
148 /* If we're debugging, try to show where the problem occurred - this
151 #ifndef USE_ROOT_ENVIRON
152 if (getuid() != ROOT_UID)
156 /* Dumping core in production code is not a good idea.
163 _nc_comp_error_leaks(void)
165 FreeAndNull(SourceName);
166 FreeAndNull(TermType);