Added new files resulting from directory restructuring.
[pspp] / 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
26 /* Message classes. */
27 enum
28   {
29     SE, SW, SM,                 /* Script error/warning/message. */
30     IE, IS,                     /* Installation error/script error. */
31     DE, DW,                     /* Data-file error/warning. */
32     ME, MW, MM,                 /* General error/warning/message. */
33     ERR_CLASS_COUNT,            /* Number of message classes. */
34     ERR_CLASS_MASK = 0xf,       /* Bitmask for class. */
35     ERR_VERBOSITY_SHIFT = 4,    /* Shift count for verbosity. */
36     ERR_VERBOSITY_MASK = 0xf    /* Bitmask for verbosity. */
37   };
38
39 /* If passed to msg() as CLASS, the return value will cause the message
40    to be displayed only if `verbosity' is at least LEVEL. */
41 #define VM(LEVEL) (MM | ((LEVEL) << ERR_VERBOSITY_SHIFT))
42
43 /* A file location.  */
44 struct file_locator
45   {
46     const char *filename;               /* Filename. */
47     int line_number;                    /* Line number. */
48   };
49
50 /* An error message. */
51 struct error
52   {
53     int class;                  /* One of the classes above. */
54     struct file_locator where;  /* File location, or (NULL, -1). */
55     const char *title;          /* Special text inserted if not null. */
56   };
57
58 /* Number of errors, warnings reported. */
59 extern int err_error_count;
60 extern int err_warning_count;
61
62 /* If number of allowable errors/warnings is exceeded, then a message
63    is displayed and this flag is set to suppress subsequent
64    messages. */
65 extern int err_already_flagged;
66
67 /* Nonnegative verbosity level.  Higher value == more verbose. */
68 extern int err_verbosity;
69
70 /* Functions. */
71 void msg (int class, const char *format, ...)
72      PRINTF_FORMAT (2, 3);
73 void tmsg (int class, const char *title, const char *format, ...)
74      PRINTF_FORMAT (3, 4);
75
76 /* File-locator stack. */
77 void err_push_file_locator (const struct file_locator *);
78 void err_pop_file_locator (const struct file_locator *);
79 void err_location (struct file_locator *);
80
81 /* Obscure functions. */
82 void err_set_command_name (const char *);
83 void err_done (void);
84 void err_check_count (void);
85 void err_vmsg (const struct error *, const char *, va_list);
86
87 /* Used in panic situations only */
88 void request_bug_report_and_abort(const char *msg );
89
90 void err_assert_fail(const char *expr, const char *file, int line);
91
92 #undef __STRING
93 #define __STRING(x) #x
94 #undef assert
95
96                                
97 #define assert(expr) ( (void) ( expr ? (void) 0 : \
98                err_assert_fail(__STRING(expr), __FILE__, __LINE__)) )
99
100
101
102 #endif /* error.h */