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