1 /****************************************************************************
2 * Copyright (c) 1998-2005,2007 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 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
34
35 /*
36 * comp_error.c -- Error message routines
37 *
38 */
39
40 #include <curses.priv.h>
41
42 #include <tic.h>
43
44 MODULE_ID("$Id: comp_error.c,v 1.31 2007/04/21 23:38:32 tom Exp $")
45
46 NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
47 NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
48 NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
49
50 #define SourceName _nc_globals.comp_sourcename
51 #define TermType _nc_globals.comp_termtype
52
53 NCURSES_EXPORT(const char *)
_nc_get_source(void)54 _nc_get_source(void)
55 {
56 return SourceName;
57 }
58
59 NCURSES_EXPORT(void)
_nc_set_source(const char * const name)60 _nc_set_source(const char *const name)
61 {
62 SourceName = name;
63 }
64
65 NCURSES_EXPORT(void)
_nc_set_type(const char * const name)66 _nc_set_type(const char *const name)
67 {
68 if (TermType == 0)
69 TermType = typeMalloc(char, MAX_NAME_SIZE + 1);
70 if (TermType != 0) {
71 TermType[0] = '\0';
72 if (name)
73 strncat(TermType, name, MAX_NAME_SIZE);
74 }
75 }
76
77 NCURSES_EXPORT(void)
_nc_get_type(char * name)78 _nc_get_type(char *name)
79 {
80 #if NO_LEAKS
81 if (name == 0 && TermType != 0) {
82 FreeAndNull(TermType);
83 return;
84 }
85 #endif
86 if (name != 0)
87 strcpy(name, TermType != 0 ? TermType : "");
88 }
89
90 static NCURSES_INLINE void
where_is_problem(void)91 where_is_problem(void)
92 {
93 fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?");
94 if (_nc_curr_line >= 0)
95 fprintf(stderr, ", line %d", _nc_curr_line);
96 if (_nc_curr_col >= 0)
97 fprintf(stderr, ", col %d", _nc_curr_col);
98 if (TermType != 0 && TermType[0] != '\0')
99 fprintf(stderr, ", terminal '%s'", TermType);
100 fputc(':', stderr);
101 fputc(' ', stderr);
102 }
103
104 NCURSES_EXPORT(void)
_nc_warning(const char * const fmt,...)105 _nc_warning(const char *const fmt,...)
106 {
107 va_list argp;
108
109 if (_nc_suppress_warnings)
110 return;
111
112 where_is_problem();
113 va_start(argp, fmt);
114 vfprintf(stderr, fmt, argp);
115 fprintf(stderr, "\n");
116 va_end(argp);
117 }
118
119 NCURSES_EXPORT(void)
_nc_err_abort(const char * const fmt,...)120 _nc_err_abort(const char *const fmt,...)
121 {
122 va_list argp;
123
124 where_is_problem();
125 va_start(argp, fmt);
126 vfprintf(stderr, fmt, argp);
127 fprintf(stderr, "\n");
128 va_end(argp);
129 exit(EXIT_FAILURE);
130 }
131
132 NCURSES_EXPORT(void)
_nc_syserr_abort(const char * const fmt,...)133 _nc_syserr_abort(const char *const fmt,...)
134 {
135 va_list argp;
136
137 where_is_problem();
138 va_start(argp, fmt);
139 vfprintf(stderr, fmt, argp);
140 fprintf(stderr, "\n");
141 va_end(argp);
142
143 /* If we're debugging, try to show where the problem occurred - this
144 * will dump core.
145 */
146 #if defined(TRACE) || !defined(NDEBUG)
147 abort();
148 #else
149 /* Dumping core in production code is not a good idea.
150 */
151 exit(EXIT_FAILURE);
152 #endif
153 }
154