]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/comp_error.c
ncurses 5.3
[ncurses.git] / ncurses / tinfo / comp_error.c
1 /****************************************************************************
2  * Copyright (c) 1998-2001,2002 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
43 MODULE_ID("$Id: comp_error.c,v 1.25 2002/09/07 20:05:07 tom Exp $")
44
45 NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
46 NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
47 NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
48
49 static const char *sourcename;
50 static char *termtype;
51
52 NCURSES_EXPORT(void)
53 _nc_set_source(const char *const name)
54 {
55     sourcename = name;
56 }
57
58 NCURSES_EXPORT(void)
59 _nc_set_type(const char *const name)
60 {
61     if (termtype == 0)
62         termtype = typeMalloc(char, MAX_NAME_SIZE + 1);
63     if (termtype != 0) {
64         termtype[0] = '\0';
65         if (name)
66             strncat(termtype, name, MAX_NAME_SIZE);
67     }
68 }
69
70 NCURSES_EXPORT(void)
71 _nc_get_type(char *name)
72 {
73     strcpy(name, termtype != 0 ? termtype : "");
74 }
75
76 static inline void
77 where_is_problem(void)
78 {
79     fprintf(stderr, "\"%s\"", sourcename);
80     if (_nc_curr_line >= 0)
81         fprintf(stderr, ", line %d", _nc_curr_line);
82     if (_nc_curr_col >= 0)
83         fprintf(stderr, ", col %d", _nc_curr_col);
84     if (termtype != 0 && termtype[0] != '\0')
85         fprintf(stderr, ", terminal '%s'", termtype);
86     fputc(':', stderr);
87     fputc(' ', stderr);
88 }
89
90 NCURSES_EXPORT(void)
91 _nc_warning(const char *const fmt,...)
92 {
93     va_list argp;
94
95     if (_nc_suppress_warnings)
96         return;
97
98     where_is_problem();
99     va_start(argp, fmt);
100     vfprintf(stderr, fmt, argp);
101     fprintf(stderr, "\n");
102     va_end(argp);
103 }
104
105 NCURSES_EXPORT(void)
106 _nc_err_abort(const char *const fmt,...)
107 {
108     va_list argp;
109
110     where_is_problem();
111     va_start(argp, fmt);
112     vfprintf(stderr, fmt, argp);
113     fprintf(stderr, "\n");
114     va_end(argp);
115     exit(EXIT_FAILURE);
116 }
117
118 NCURSES_EXPORT(void)
119 _nc_syserr_abort(const char *const fmt,...)
120 {
121     va_list argp;
122
123     where_is_problem();
124     va_start(argp, fmt);
125     vfprintf(stderr, fmt, argp);
126     fprintf(stderr, "\n");
127     va_end(argp);
128
129     /* If we're debugging, try to show where the problem occurred - this
130      * will dump core.
131      */
132 #if defined(TRACE) || !defined(NDEBUG)
133     abort();
134 #else
135     /* Dumping core in production code is not a good idea.
136      */
137     exit(EXIT_FAILURE);
138 #endif
139 }