output: Introduce group_item in place of TEXT_ITEM_COMMAND_OPEN and CLOSE.
[pspp] / src / libpspp / message.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006, 2010, 2011, 2014 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 const char *msg_severity_to_string (enum msg_severity);
43
44 /* Combination of a category and a severity for convenience. */
45 enum msg_class
46   {
47     ME, MW, MN,                 /* General error/warning/note. */
48     SE, SW, SN,                 /* Script error/warning/note. */
49     DE, DW, DN,                 /* Data-file error/note. */
50     MSG_CLASS_CNT,
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 message. */
73 struct msg
74   {
75     enum msg_category category; /* Message category. */
76     enum msg_severity severity; /* Message severity. */
77     char *file_name;            /* Name of file containing error, or NULL. */
78     char *command_name;         /* Name of erroneous command, or NULL.  */
79     int first_line;             /* 1-based line number, or 0 if none. */
80     int last_line;             /* 1-based exclusive last line (0=none). */
81     int first_column;           /* 1-based first column, or 0 if none. */
82     int last_column;            /* 1-based exclusive last column (0=none). */
83     char *text;                 /* Error text. */
84     bool shipped;               /* True if this message has been emitted */
85   };
86
87 /* Initialization. */
88 void msg_set_handler (void (*handler) (const struct msg *, void *lexer),
89                       void *aux);
90
91 /* Working with messages. */
92 struct msg *msg_dup (const struct msg *);
93 void msg_destroy(struct msg *);
94 char *msg_to_string (const struct msg *);
95
96 /* Emitting messages. */
97 void vmsg (enum msg_class class, const char *format, va_list args)
98      PRINTF_FORMAT (2, 0);
99 void msg (enum msg_class, const char *format, ...)
100      PRINTF_FORMAT (2, 3);
101 void msg_emit (struct msg *);
102
103 void msg_error (int errnum, const char *format, ...);
104
105
106 /* Enable and disable messages. */
107 void msg_enable (void);
108 void msg_disable (void);
109
110 /* Error context. */
111 bool msg_ui_too_many_errors (void);
112 void msg_ui_reset_counts (void);
113 bool msg_ui_any_errors (void);
114 void msg_ui_disable_warnings (bool);
115
116
117 /* Used in panic situations only. */
118 void request_bug_report (const char *msg);
119
120
121 #endif /* message.h */