1 /* $OpenBSD: comp_error.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 33 * and: Eric S. Raymond <esr@snark.thyrsus.com> * 34 * and: Thomas E. Dickey 1996-on * 35 ****************************************************************************/ 36 37 /* 38 * comp_error.c -- Error message routines 39 * 40 */ 41 42 #include <curses.priv.h> 43 44 #include <tic.h> 45 46 MODULE_ID("$Id: comp_error.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") 47 48 NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE; 49 NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */ 50 NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */ 51 52 #define SourceName _nc_globals.comp_sourcename 53 #define TermType _nc_globals.comp_termtype 54 55 NCURSES_EXPORT(const char *) 56 _nc_get_source(void) 57 { 58 return SourceName; 59 } 60 61 NCURSES_EXPORT(void) 62 _nc_set_source(const char *const name) 63 { 64 SourceName = name; 65 } 66 67 NCURSES_EXPORT(void) 68 _nc_set_type(const char *const name) 69 { 70 if (TermType == 0) 71 TermType = typeMalloc(char, MAX_NAME_SIZE + 1); 72 if (TermType != 0) { 73 TermType[0] = '\0'; 74 if (name) 75 strncat(TermType, name, MAX_NAME_SIZE); 76 } 77 } 78 79 NCURSES_EXPORT(void) 80 _nc_get_type(char *name) 81 { 82 #if NO_LEAKS 83 if (name == 0 && TermType != 0) { 84 FreeAndNull(TermType); 85 return; 86 } 87 #endif 88 if (name != 0) 89 strlcpy(name, TermType != 0 ? TermType : "", MAX_NAME_SIZE + 1); 90 } 91 92 static NCURSES_INLINE void 93 where_is_problem(void) 94 { 95 fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?"); 96 if (_nc_curr_line >= 0) 97 fprintf(stderr, ", line %d", _nc_curr_line); 98 if (_nc_curr_col >= 0) 99 fprintf(stderr, ", col %d", _nc_curr_col); 100 if (TermType != 0 && TermType[0] != '\0') 101 fprintf(stderr, ", terminal '%s'", TermType); 102 fputc(':', stderr); 103 fputc(' ', stderr); 104 } 105 106 NCURSES_EXPORT(void) 107 _nc_warning(const char *const fmt,...) 108 { 109 va_list argp; 110 111 if (_nc_suppress_warnings) 112 return; 113 114 where_is_problem(); 115 va_start(argp, fmt); 116 vfprintf(stderr, fmt, argp); 117 fprintf(stderr, "\n"); 118 va_end(argp); 119 } 120 121 NCURSES_EXPORT(void) 122 _nc_err_abort(const char *const fmt,...) 123 { 124 va_list argp; 125 126 where_is_problem(); 127 va_start(argp, fmt); 128 vfprintf(stderr, fmt, argp); 129 fprintf(stderr, "\n"); 130 va_end(argp); 131 exit(EXIT_FAILURE); 132 } 133 134 NCURSES_EXPORT(void) 135 _nc_syserr_abort(const char *const fmt,...) 136 { 137 va_list argp; 138 139 where_is_problem(); 140 va_start(argp, fmt); 141 vfprintf(stderr, fmt, argp); 142 fprintf(stderr, "\n"); 143 va_end(argp); 144 145 /* If we're debugging, try to show where the problem occurred - this 146 * will dump core. 147 */ 148 #if defined(TRACE) || !defined(NDEBUG) 149 abort(); 150 #else 151 /* Dumping core in production code is not a good idea. 152 */ 153 exit(EXIT_FAILURE); 154 #endif 155 } 156