150276Speter/**************************************************************************** 2174993Srafan * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * 350276Speter * * 450276Speter * Permission is hereby granted, free of charge, to any person obtaining a * 550276Speter * copy of this software and associated documentation files (the * 650276Speter * "Software"), to deal in the Software without restriction, including * 750276Speter * without limitation the rights to use, copy, modify, merge, publish, * 850276Speter * distribute, distribute with modifications, sublicense, and/or sell * 950276Speter * copies of the Software, and to permit persons to whom the Software is * 1050276Speter * furnished to do so, subject to the following conditions: * 1150276Speter * * 1250276Speter * The above copyright notice and this permission notice shall be included * 1350276Speter * in all copies or substantial portions of the Software. * 1450276Speter * * 1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2250276Speter * * 2350276Speter * Except as contained in this notice, the name(s) of the above copyright * 2450276Speter * holders shall not be used in advertising or otherwise to promote the * 2550276Speter * sale, use or other dealings in this Software without prior written * 2650276Speter * authorization. * 2750276Speter ****************************************************************************/ 2850276Speter 2950276Speter/**************************************************************************** 3050276Speter * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 3150276Speter * and: Eric S. Raymond <esr@snark.thyrsus.com> * 32166124Srafan * and: Thomas E. Dickey 1996-on * 3350276Speter ****************************************************************************/ 3450276Speter 3550276Speter/* 3650276Speter * comp_error.c -- Error message routines 3750276Speter * 3850276Speter */ 3950276Speter 4050276Speter#include <curses.priv.h> 4150276Speter 4250276Speter#include <tic.h> 4350276Speter 44174993SrafanMODULE_ID("$Id: comp_error.c,v 1.31 2007/04/21 23:38:32 tom Exp $") 4550276Speter 4676726SpeterNCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE; 4797049SpeterNCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */ 4897049SpeterNCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */ 4950276Speter 50174993Srafan#define SourceName _nc_globals.comp_sourcename 51174993Srafan#define TermType _nc_globals.comp_termtype 5250276Speter 53166124SrafanNCURSES_EXPORT(const char *) 54166124Srafan_nc_get_source(void) 55166124Srafan{ 56174993Srafan return SourceName; 57166124Srafan} 58166124Srafan 5976726SpeterNCURSES_EXPORT(void) 6076726Speter_nc_set_source(const char *const name) 6150276Speter{ 62174993Srafan SourceName = name; 6350276Speter} 6450276Speter 6576726SpeterNCURSES_EXPORT(void) 6676726Speter_nc_set_type(const char *const name) 6750276Speter{ 68174993Srafan if (TermType == 0) 69174993Srafan TermType = typeMalloc(char, MAX_NAME_SIZE + 1); 70174993Srafan if (TermType != 0) { 71174993Srafan TermType[0] = '\0'; 72166124Srafan if (name) 73174993Srafan strncat(TermType, name, MAX_NAME_SIZE); 74166124Srafan } 7550276Speter} 7650276Speter 7776726SpeterNCURSES_EXPORT(void) 7876726Speter_nc_get_type(char *name) 7950276Speter{ 80166124Srafan#if NO_LEAKS 81174993Srafan if (name == 0 && TermType != 0) { 82174993Srafan FreeAndNull(TermType); 83166124Srafan return; 84166124Srafan } 85166124Srafan#endif 86166124Srafan if (name != 0) 87174993Srafan strcpy(name, TermType != 0 ? TermType : ""); 8850276Speter} 8950276Speter 90166124Srafanstatic NCURSES_INLINE void 9176726Speterwhere_is_problem(void) 9250276Speter{ 93174993Srafan fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?"); 9476726Speter if (_nc_curr_line >= 0) 9576726Speter fprintf(stderr, ", line %d", _nc_curr_line); 9676726Speter if (_nc_curr_col >= 0) 9776726Speter fprintf(stderr, ", col %d", _nc_curr_col); 98174993Srafan if (TermType != 0 && TermType[0] != '\0') 99174993Srafan fprintf(stderr, ", terminal '%s'", TermType); 10076726Speter fputc(':', stderr); 10176726Speter fputc(' ', stderr); 10250276Speter} 10350276Speter 10476726SpeterNCURSES_EXPORT(void) 10576726Speter_nc_warning(const char *const fmt,...) 10650276Speter{ 10776726Speter va_list argp; 10850276Speter 10976726Speter if (_nc_suppress_warnings) 11076726Speter return; 11150276Speter 11276726Speter where_is_problem(); 11376726Speter va_start(argp, fmt); 11476726Speter vfprintf(stderr, fmt, argp); 11576726Speter fprintf(stderr, "\n"); 11676726Speter va_end(argp); 11750276Speter} 11850276Speter 11976726SpeterNCURSES_EXPORT(void) 12076726Speter_nc_err_abort(const char *const fmt,...) 12150276Speter{ 12276726Speter va_list argp; 12350276Speter 12476726Speter where_is_problem(); 12576726Speter va_start(argp, fmt); 12676726Speter vfprintf(stderr, fmt, argp); 12776726Speter fprintf(stderr, "\n"); 12876726Speter va_end(argp); 12976726Speter exit(EXIT_FAILURE); 13050276Speter} 13150276Speter 13276726SpeterNCURSES_EXPORT(void) 13376726Speter_nc_syserr_abort(const char *const fmt,...) 13450276Speter{ 13576726Speter va_list argp; 13650276Speter 13776726Speter where_is_problem(); 13876726Speter va_start(argp, fmt); 13976726Speter vfprintf(stderr, fmt, argp); 14076726Speter fprintf(stderr, "\n"); 14176726Speter va_end(argp); 14250276Speter 14376726Speter /* If we're debugging, try to show where the problem occurred - this 14476726Speter * will dump core. 14576726Speter */ 14650276Speter#if defined(TRACE) || !defined(NDEBUG) 14776726Speter abort(); 14850276Speter#else 14976726Speter /* Dumping core in production code is not a good idea. 15076726Speter */ 15176726Speter exit(EXIT_FAILURE); 15250276Speter#endif 15350276Speter} 154