Continue reforming error message support. In this phase, we divide
[pspp-builds.git] / src / libpspp / message.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !error_h
21 #define error_h 1
22
23 #include <stdarg.h>
24 #include <stdbool.h>
25 #include "compiler.h"
26
27 /* Message classes. */
28 enum msg_class
29   {
30     ME, MW, MN,                 /* General error/warning/note. */
31     SE, SW, SN,                 /* Script error/warning/note. */
32     DE, DW, DN,                 /* Data-file error/note. */
33     MSG_CLASS_CNT,
34   };
35
36 /* What kind of message is this? */
37 enum msg_category 
38   {
39     MSG_GENERAL,        /* General info. */
40     MSG_SYNTAX,         /* Messages that relate to syntax files. */
41     MSG_DATA            /* Messages that relate to data files. */
42   };
43
44 /* How important a condition is it? */
45 enum msg_severity 
46   {
47     MSG_ERROR,
48     MSG_WARNING,
49     MSG_NOTE
50   };
51
52 static inline enum msg_category
53 msg_class_to_category (enum msg_class class) 
54 {
55   return class / 3;
56 }
57
58 static inline enum msg_severity
59 msg_class_to_severity (enum msg_class class) 
60 {
61   return class % 3;
62 }
63
64 static inline enum msg_class
65 msg_class_from_category_and_severity (enum msg_category category,
66                                       enum msg_severity severity) 
67 {
68   return category * 3 + severity;
69 }
70
71 /* A file location.  */
72 struct file_locator
73   {
74     const char *file_name;              /* File name. */
75     int line_number;                    /* Line number. */
76   };
77
78 /* An error message. */
79 struct error
80   {
81     enum msg_category category; /* Message category. */
82     enum msg_severity severity; /* Message severity. */
83     struct file_locator where;  /* File location, or (NULL, -1). */
84     const char *title;          /* Special text inserted if not null. */
85   };
86
87 /* Number of errors, warnings reported. */
88 extern int err_error_count;
89 extern int err_warning_count;
90
91 /* If number of allowable errors/warnings is exceeded, then a message
92    is displayed and this flag is set to suppress subsequent
93    messages. */
94 extern int err_already_flagged;
95
96 /* Nonnegative verbosity level.  Higher value == more verbose. */
97 extern int err_verbosity;
98
99 /* Functions. */
100 void msg (enum msg_class, const char *format, ...)
101      PRINTF_FORMAT (2, 3);
102 void tmsg (enum msg_class, const char *title, const char *format, ...)
103      PRINTF_FORMAT (3, 4);
104
105 void verbose_msg (int level, const char *format, ...)
106      PRINTF_FORMAT (2, 3);
107
108 /* File-locator stack. */
109 void err_push_file_locator (const struct file_locator *);
110 void err_pop_file_locator (const struct file_locator *);
111 void err_location (struct file_locator *);
112
113 /* Obscure functions. */
114 void err_set_command_name (const char *);
115 void err_done (void);
116 void err_check_count (void);
117 void err_vmsg (const struct error *, const char *, va_list);
118
119 /* Used in panic situations only */
120 void request_bug_report_and_abort(const char *msg );
121
122 void err_assert_fail(const char *expr, const char *file, int line);
123
124 #undef __STRING
125 #define __STRING(x) #x
126 #undef assert
127
128                                
129 #define assert(expr) ( (void) ( expr ? (void) 0 : \
130                err_assert_fail(__STRING(expr), __FILE__, __LINE__)) )
131
132
133
134 #endif /* error.h */