Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / libpspp / message.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef MESSAGE_H
18 #define MESSAGE_H 1
19
20 #include <stdarg.h>
21 #include <stdbool.h>
22 #include <libpspp/compiler.h>
23
24 /* What kind of message is this? */
25 enum msg_category
26   {
27     MSG_GENERAL,        /* General info. */
28     MSG_SYNTAX,         /* Messages that relate to syntax files. */
29     MSG_DATA            /* Messages that relate to data files. */
30   };
31
32 /* How important a condition is it? */
33 enum msg_severity
34   {
35     MSG_ERROR,
36     MSG_WARNING,
37     MSG_NOTE
38   };
39
40 /* Combination of a category and a severity for convenience. */
41 enum msg_class
42   {
43     ME, MW, MN,                 /* General error/warning/note. */
44     SE, SW, SN,                 /* Script error/warning/note. */
45     DE, DW, DN,                 /* Data-file error/note. */
46     MSG_CLASS_CNT,
47   };
48
49
50 static inline enum msg_category
51 msg_class_to_category (enum msg_class class)
52 {
53   return class / 3;
54 }
55
56 static inline enum msg_severity
57 msg_class_to_severity (enum msg_class class)
58 {
59   return class % 3;
60 }
61
62 static inline enum msg_class
63 msg_class_from_category_and_severity (enum msg_category category,
64                                       enum msg_severity severity)
65 {
66   return category * 3 + severity;
67 }
68
69 /* A file location.  */
70 struct msg_locator
71   {
72     const char *file_name;              /* File name. */
73     int line_number;                    /* Line number. */
74   };
75
76 /* A message. */
77 struct msg
78   {
79     enum msg_category category; /* Message category. */
80     enum msg_severity severity; /* Message severity. */
81     struct msg_locator where;   /* File location, or (NULL, -1). */
82     char *text;                 /* Error text. */
83   };
84
85 struct source_stream ;
86
87 /* Initialization. */
88 void msg_init (struct source_stream *, void (*handler) (const struct msg *) );
89
90 void msg_done (void);
91
92 struct msg * msg_dup(const struct msg *m);
93 void msg_destroy(struct msg *m);
94
95 /* Emitting messages. */
96 void msg (enum msg_class, const char *format, ...)
97      PRINTF_FORMAT (2, 3);
98 void msg_emit (struct msg *);
99
100 /* Enable and disable messages. */
101 void msg_enable (void);
102 void msg_disable (void);
103
104 /* Error context. */
105 void msg_set_command_name (const char *);
106 const char *msg_get_command_name (void);
107 void msg_push_msg_locator (const struct msg_locator *);
108 void msg_pop_msg_locator (const struct msg_locator *);
109
110
111 /* Used in panic situations only. */
112 void request_bug_report_and_abort (const char *msg) NO_RETURN;
113
114 #endif /* message.h */