Back to index

tetex-bin  3.0
comp_error.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00031  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00032  *     and: Thomas E. Dickey                        1996-on                 *
00033  ****************************************************************************/
00034 
00035 /*
00036  *     comp_error.c -- Error message routines
00037  *
00038  */
00039 
00040 #include <curses.priv.h>
00041 
00042 #include <tic.h>
00043 
00044 MODULE_ID("$Id: comp_error.c,v 1.26 2004/04/17 22:20:06 tom Exp $")
00045 
00046 NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
00047 NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
00048 NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
00049 
00050 static const char *sourcename;
00051 static char *termtype;
00052 
00053 NCURSES_EXPORT(void)
00054 _nc_set_source(const char *const name)
00055 {
00056     sourcename = name;
00057 }
00058 
00059 NCURSES_EXPORT(void)
00060 _nc_set_type(const char *const name)
00061 {
00062     if (termtype == 0)
00063        termtype = typeMalloc(char, MAX_NAME_SIZE + 1);
00064     if (termtype != 0) {
00065        termtype[0] = '\0';
00066        if (name)
00067            strncat(termtype, name, MAX_NAME_SIZE);
00068     }
00069 }
00070 
00071 NCURSES_EXPORT(void)
00072 _nc_get_type(char *name)
00073 {
00074 #if NO_LEAKS
00075     if (name == 0) {
00076        FreeAndNull(termtype);
00077        return;
00078     }
00079 #endif
00080     strcpy(name, termtype != 0 ? termtype : "");
00081 }
00082 
00083 static inline void
00084 where_is_problem(void)
00085 {
00086     fprintf(stderr, "\"%s\"", sourcename);
00087     if (_nc_curr_line >= 0)
00088        fprintf(stderr, ", line %d", _nc_curr_line);
00089     if (_nc_curr_col >= 0)
00090        fprintf(stderr, ", col %d", _nc_curr_col);
00091     if (termtype != 0 && termtype[0] != '\0')
00092        fprintf(stderr, ", terminal '%s'", termtype);
00093     fputc(':', stderr);
00094     fputc(' ', stderr);
00095 }
00096 
00097 NCURSES_EXPORT(void)
00098 _nc_warning(const char *const fmt,...)
00099 {
00100     va_list argp;
00101 
00102     if (_nc_suppress_warnings)
00103        return;
00104 
00105     where_is_problem();
00106     va_start(argp, fmt);
00107     vfprintf(stderr, fmt, argp);
00108     fprintf(stderr, "\n");
00109     va_end(argp);
00110 }
00111 
00112 NCURSES_EXPORT(void)
00113 _nc_err_abort(const char *const fmt,...)
00114 {
00115     va_list argp;
00116 
00117     where_is_problem();
00118     va_start(argp, fmt);
00119     vfprintf(stderr, fmt, argp);
00120     fprintf(stderr, "\n");
00121     va_end(argp);
00122     exit(EXIT_FAILURE);
00123 }
00124 
00125 NCURSES_EXPORT(void)
00126 _nc_syserr_abort(const char *const fmt,...)
00127 {
00128     va_list argp;
00129 
00130     where_is_problem();
00131     va_start(argp, fmt);
00132     vfprintf(stderr, fmt, argp);
00133     fprintf(stderr, "\n");
00134     va_end(argp);
00135 
00136     /* If we're debugging, try to show where the problem occurred - this
00137      * will dump core.
00138      */
00139 #if defined(TRACE) || !defined(NDEBUG)
00140     abort();
00141 #else
00142     /* Dumping core in production code is not a good idea.
00143      */
00144     exit(EXIT_FAILURE);
00145 #endif
00146 }