]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/comp_error.c
ncurses 4.1
[ncurses.git] / ncurses / comp_error.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22
23 /*
24  *      comp_error.c -- Error message routines
25  *
26  */
27
28 #include <curses.priv.h>
29
30 #include <tic.h>
31
32 MODULE_ID("$Id: comp_error.c,v 1.12 1996/12/21 14:24:06 tom Exp $")
33
34 bool _nc_suppress_warnings;
35
36 static const char *sourcename;
37 static char termtype[MAX_NAME_SIZE+1];
38
39 void _nc_set_source(const char *const name)
40 {
41         sourcename = name;
42 }
43
44 void _nc_set_type(const char *const name)
45 {
46         if (name)
47                 strncpy( termtype, name, MAX_NAME_SIZE );
48         else
49                 termtype[0] = '\0';
50 }
51
52 void _nc_get_type(char *name)
53 {
54         strcpy( name, termtype );
55 }
56
57 static inline void where_is_problem(void)
58 {
59         fprintf (stderr, "\"%s\"", sourcename);
60         if (_nc_curr_line >= 0)
61             fprintf (stderr, ", line %d", _nc_curr_line);
62         if (_nc_curr_col >= 0)
63                 fprintf (stderr, ", col %d", _nc_curr_col);
64         if (termtype[0])
65                 fprintf (stderr, ", terminal '%s'", termtype);
66         fputc(':', stderr);
67         fputc(' ', stderr);
68 }
69
70 void _nc_warning(const char *const fmt, ...)
71 {
72 va_list argp;
73
74         if (_nc_suppress_warnings)
75             return;
76
77         where_is_problem();
78         va_start(argp,fmt);
79         vfprintf (stderr, fmt, argp);
80         fprintf (stderr, "\n");
81         va_end(argp);
82 }
83
84
85 void _nc_err_abort(const char *const fmt, ...)
86 {
87 va_list argp;
88
89         where_is_problem();
90         va_start(argp,fmt);
91         vfprintf (stderr, fmt, argp);
92         fprintf (stderr, "\n");
93         va_end(argp);
94         exit(EXIT_FAILURE);
95 }
96
97
98 void _nc_syserr_abort(const char *const fmt, ...)
99 {
100 va_list argp;
101
102         where_is_problem();
103         va_start(argp,fmt);
104         vfprintf (stderr, fmt, argp);
105         fprintf (stderr, "\n");
106         va_end(argp);
107         abort();
108 }