libncurses: updated to 6.0
[tomato.git] / release / src / router / libncurses / ncurses / tinfo / comp_error.c
blobff0acc79981564ff47bcab52c9207286c16933ed
1 /****************************************************************************
2 * Copyright (c) 1998-2011,2012 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 ****************************************************************************/
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 ****************************************************************************/
36 * comp_error.c -- Error message routines
40 #include <curses.priv.h>
42 #include <tic.h>
44 MODULE_ID("$Id: comp_error.c,v 1.36 2012/02/22 22:34:31 tom Exp $")
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 */
50 #define SourceName _nc_globals.comp_sourcename
51 #define TermType _nc_globals.comp_termtype
53 NCURSES_EXPORT(const char *)
54 _nc_get_source(void)
56 return SourceName;
59 NCURSES_EXPORT(void)
60 _nc_set_source(const char *const name)
62 FreeIfNeeded(SourceName);
63 SourceName = strdup(name);
66 NCURSES_EXPORT(void)
67 _nc_set_type(const char *const name)
69 if (TermType == 0)
70 TermType = typeMalloc(char, MAX_NAME_SIZE + 1);
71 if (TermType != 0) {
72 TermType[0] = '\0';
73 if (name)
74 strncat(TermType, name, (size_t) MAX_NAME_SIZE);
78 NCURSES_EXPORT(void)
79 _nc_get_type(char *name)
81 #if NO_LEAKS
82 if (name == 0 && TermType != 0) {
83 FreeAndNull(TermType);
84 return;
86 #endif
87 if (name != 0)
88 _nc_STRCPY(name, TermType != 0 ? TermType : "", MAX_NAME_SIZE);
91 static NCURSES_INLINE void
92 where_is_problem(void)
94 fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?");
95 if (_nc_curr_line >= 0)
96 fprintf(stderr, ", line %d", _nc_curr_line);
97 if (_nc_curr_col >= 0)
98 fprintf(stderr, ", col %d", _nc_curr_col);
99 if (TermType != 0 && TermType[0] != '\0')
100 fprintf(stderr, ", terminal '%s'", TermType);
101 fputc(':', stderr);
102 fputc(' ', stderr);
105 NCURSES_EXPORT(void)
106 _nc_warning(const char *const fmt,...)
108 va_list argp;
110 if (_nc_suppress_warnings)
111 return;
113 where_is_problem();
114 va_start(argp, fmt);
115 vfprintf(stderr, fmt, argp);
116 fprintf(stderr, "\n");
117 va_end(argp);
120 NCURSES_EXPORT(void)
121 _nc_err_abort(const char *const fmt,...)
123 va_list argp;
125 where_is_problem();
126 va_start(argp, fmt);
127 vfprintf(stderr, fmt, argp);
128 fprintf(stderr, "\n");
129 va_end(argp);
130 exit(EXIT_FAILURE);
133 NCURSES_EXPORT(void)
134 _nc_syserr_abort(const char *const fmt,...)
136 va_list argp;
138 where_is_problem();
139 va_start(argp, fmt);
140 vfprintf(stderr, fmt, argp);
141 fprintf(stderr, "\n");
142 va_end(argp);
144 /* If we're debugging, try to show where the problem occurred - this
145 * will dump core.
147 #if defined(TRACE) || !defined(NDEBUG)
148 abort();
149 #else
150 /* Dumping core in production code is not a good idea.
152 exit(EXIT_FAILURE);
153 #endif
156 #if NO_LEAKS
157 NCURSES_EXPORT(void)
158 _nc_comp_error_leaks(void)
160 FreeAndNull(SourceName);
161 FreeAndNull(TermType);
163 #endif