Continue reforming error message support. In this phase, rename
[pspp-builds.git] / src / libpspp / message.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2006 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 #ifndef MESSAGE_H
21 #define MESSAGE_H 1
22
23 #include <stdarg.h>
24 #include <stdbool.h>
25 #include <libpspp/compiler.h>
26
27 /* What kind of message is this? */
28 enum msg_category 
29   {
30     MSG_GENERAL,        /* General info. */
31     MSG_SYNTAX,         /* Messages that relate to syntax files. */
32     MSG_DATA            /* Messages that relate to data files. */
33   };
34
35 /* How important a condition is it? */
36 enum msg_severity 
37   {
38     MSG_ERROR,
39     MSG_WARNING,
40     MSG_NOTE
41   };
42
43 /* Combination of a category and a severity for convenience. */
44 enum msg_class
45   {
46     ME, MW, MN,                 /* General error/warning/note. */
47     SE, SW, SN,                 /* Script error/warning/note. */
48     DE, DW, DN,                 /* Data-file error/note. */
49     MSG_CLASS_CNT,
50   };
51
52
53 static inline enum msg_category
54 msg_class_to_category (enum msg_class class) 
55 {
56   return class / 3;
57 }
58
59 static inline enum msg_severity
60 msg_class_to_severity (enum msg_class class) 
61 {
62   return class % 3;
63 }
64
65 static inline enum msg_class
66 msg_class_from_category_and_severity (enum msg_category category,
67                                       enum msg_severity severity) 
68 {
69   return category * 3 + severity;
70 }
71
72 /* A file location.  */
73 struct msg_locator
74   {
75     const char *file_name;              /* File name. */
76     int line_number;                    /* Line number. */
77   };
78
79 /* A message. */
80 struct msg
81   {
82     enum msg_category category; /* Message category. */
83     enum msg_severity severity; /* Message severity. */
84     struct msg_locator where;   /* File location, or (NULL, -1). */
85     char *text;                 /* Error text. */
86   };
87
88 /* Number of errors, warnings reported. */
89 extern int err_error_count;
90 extern int err_warning_count;
91
92 /* If number of allowable errors/warnings is exceeded, then a message
93    is displayed and this flag is set to suppress subsequent
94    messages. */
95 extern int err_already_flagged;
96
97 /* Nonnegative verbosity level.  Higher value == more verbose. */
98 extern int err_verbosity;
99
100 /* Initialization. */
101 void msg_done (void);
102
103 /* Emitting messages. */
104 void msg (enum msg_class, const char *format, ...)
105      PRINTF_FORMAT (2, 3);
106 void msg_emit (const struct msg *);
107
108 void verbose_msg (int level, const char *format, ...)
109      PRINTF_FORMAT (2, 3);
110
111 /* Error context. */
112 void msg_set_command_name (const char *);
113 void msg_push_msg_locator (const struct msg_locator *);
114 void msg_pop_msg_locator (const struct msg_locator *);
115 void msg_location (struct msg_locator *);
116 void err_check_count (void);
117
118 /* Used in panic situations only. */
119 void request_bug_report_and_abort (const char *msg);
120
121 void msg_assert_fail (const char *expr, const char *file, int line);
122
123 #undef __STRING
124 #define __STRING(x) #x
125 #undef assert
126                                
127 #define assert(expr) ( (void) ( expr ? (void) 0 : \
128                msg_assert_fail(__STRING(expr), __FILE__, __LINE__)) )
129
130 #endif /* message.h */