Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / libpspp / message.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006, 2010, 2011 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_C_GENERAL,              /* General info. */
28     MSG_C_SYNTAX,               /* Messages that relate to syntax files. */
29     MSG_C_DATA,                 /* Messages that relate to data files. */
30     MSG_N_CATEGORIES
31   };
32
33 /* How important a condition is it? */
34 enum msg_severity
35   {
36     MSG_S_ERROR,
37     MSG_S_WARNING,
38     MSG_S_NOTE,
39     MSG_N_SEVERITIES
40   };
41
42 /* Combination of a category and a severity for convenience. */
43 enum msg_class
44   {
45     ME, MW, MN,                 /* General error/warning/note. */
46     SE, SW, SN,                 /* Script error/warning/note. */
47     DE, DW, DN,                 /* Data-file error/note. */
48     MSG_CLASS_CNT,
49   };
50
51 static inline enum msg_category
52 msg_class_to_category (enum msg_class class)
53 {
54   return class / 3;
55 }
56
57 static inline enum msg_severity
58 msg_class_to_severity (enum msg_class class)
59 {
60   return class % 3;
61 }
62
63 static inline enum msg_class
64 msg_class_from_category_and_severity (enum msg_category category,
65                                       enum msg_severity severity)
66 {
67   return category * 3 + severity;
68 }
69
70 /* A file location.  */
71 struct msg_locator
72   {
73     char *file_name;           /* File name (NULL if none). */
74     int line_number;           /* Line number (0 if none). */
75     int first_column;          /* 1-based column number (0 if none). */
76     int last_column;           /* 1-based exclusive last column (0 if none). */
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 struct source_stream ;
89
90 /* Initialization. */
91 void msg_init (struct source_stream *, void (*handler) (const struct msg *) );
92
93 void msg_done (void);
94
95 /* Working with messages. */
96 struct msg *msg_dup (const struct msg *);
97 void msg_destroy(struct msg *);
98 char *msg_to_string (const struct msg *, const char *command_name);
99
100 /* Emitting messages. */
101 void msg (enum msg_class, const char *format, ...)
102      PRINTF_FORMAT (2, 3);
103 void msg_emit (struct msg *);
104
105 /* Enable and disable messages. */
106 void msg_enable (void);
107 void msg_disable (void);
108
109 /* Error context. */
110 void msg_push_msg_locator (const struct msg_locator *);
111 void msg_pop_msg_locator (const struct msg_locator *);
112
113 bool msg_ui_too_many_errors (void);
114 void msg_ui_reset_counts (void);
115 bool msg_ui_any_errors (void);
116 void msg_ui_disable_warnings (bool);
117
118
119 /* Used in panic situations only. */
120 void request_bug_report (const char *msg);
121
122
123 #endif /* message.h */