1 /* $OpenBSD: comp_error.c,v 1.1 1999/01/18 19:10:13 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998 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 ****************************************************************************/ 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("$From: comp_error.c,v 1.16 1998/08/01 23:39:51 tom Exp $") 47 48 bool _nc_suppress_warnings; 49 int _nc_curr_line; /* current line # in input */ 50 int _nc_curr_col; /* current column # in input */ 51 52 static const char *sourcename; 53 static char termtype[MAX_NAME_SIZE+1]; 54 55 void _nc_set_source(const char *const name) 56 { 57 sourcename = name; 58 } 59 60 void _nc_set_type(const char *const name) 61 { 62 if (name) 63 strlcpy( termtype, name, sizeof(termtype) ); 64 else 65 termtype[0] = '\0'; 66 } 67 68 void _nc_get_type(char *name) 69 { 70 strcpy( name, termtype ); 71 } 72 73 static inline void where_is_problem(void) 74 { 75 fprintf (stderr, "\"%s\"", sourcename); 76 if (_nc_curr_line >= 0) 77 fprintf (stderr, ", line %d", _nc_curr_line); 78 if (_nc_curr_col >= 0) 79 fprintf (stderr, ", col %d", _nc_curr_col); 80 if (termtype[0]) 81 fprintf (stderr, ", terminal '%s'", termtype); 82 fputc(':', stderr); 83 fputc(' ', stderr); 84 } 85 86 void _nc_warning(const char *const fmt, ...) 87 { 88 va_list argp; 89 90 if (_nc_suppress_warnings) 91 return; 92 93 where_is_problem(); 94 va_start(argp,fmt); 95 vfprintf (stderr, fmt, argp); 96 fprintf (stderr, "\n"); 97 va_end(argp); 98 } 99 100 101 void _nc_err_abort(const char *const fmt, ...) 102 { 103 va_list argp; 104 105 where_is_problem(); 106 va_start(argp,fmt); 107 vfprintf (stderr, fmt, argp); 108 fprintf (stderr, "\n"); 109 va_end(argp); 110 exit(EXIT_FAILURE); 111 } 112 113 114 void _nc_syserr_abort(const char *const fmt, ...) 115 { 116 va_list argp; 117 118 where_is_problem(); 119 va_start(argp,fmt); 120 vfprintf (stderr, fmt, argp); 121 fprintf (stderr, "\n"); 122 va_end(argp); 123 124 /* If we're debugging, try to show where the problem occurred - this 125 * will dump core. 126 */ 127 #if defined(TRACE) || !defined(NDEBUG) 128 abort(); 129 #else 130 /* Dumping core in production code is not a good idea. 131 */ 132 exit(EXIT_FAILURE); 133 #endif 134 } 135