1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
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.
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.
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
23 #include "msg-locator.h"
32 #include <libpspp/alloc.h>
33 #include <libpspp/version.h>
36 #include "xvasprintf.h"
38 /* Current command name as set by msg_set_command_name(). */
39 static char *command_name;
41 /* Message handler as set by msg_init(). */
42 static void (*msg_handler) (const struct msg *);
44 /* Disables emitting messages if positive. */
45 static int messages_disabled;
47 /* Public functions. */
49 /* Writes error message in CLASS, with text FORMAT, formatted with
50 printf, to the standard places. */
52 msg (enum msg_class class, const char *format, ...)
57 m.category = msg_class_to_category (class);
58 m.severity = msg_class_to_severity (class);
59 va_start (args, format);
60 m.text = xvasprintf (format, args);
67 msg_init ( void (*handler) (const struct msg *) )
69 msg_handler = handler;
78 /* Duplicate a message */
80 msg_dup(const struct msg *m)
82 struct msg *new_msg = xmalloc (sizeof *m);
85 new_msg->text = strdup(m->text);
91 msg_destroy(struct msg *m)
97 /* Emits M as an error message.
98 Frees allocated data in M. */
100 msg_emit (struct msg *m)
102 get_msg_location (&m->where);
103 if (!messages_disabled)
108 /* Disables message output until the next call to msg_enable. If
109 this function is called multiple times, msg_enable must be
110 called an equal number of times before messages are actually
118 /* Enables message output that was disabled by msg_disable. */
122 assert (messages_disabled > 0);
126 /* Private functions. */
128 /* Sets COMMAND_NAME as the command name included in some kinds
129 of error messages. */
131 msg_set_command_name (const char *command_name_)
134 command_name = command_name_ ? xstrdup (command_name_) : NULL;
137 /* Returns the current command name, or NULL if none. */
139 msg_get_command_name (void)
145 request_bug_report_and_abort (const char *msg)
147 fprintf (stderr, "******************************************************\n");
148 fprintf (stderr, "You have discovered a bug in PSPP. Please report this\n");
149 fprintf (stderr, "to " PACKAGE_BUGREPORT ". Please include this entire\n");
150 fprintf (stderr, "message, *plus* several lines of output just above it.\n");
151 fprintf (stderr, "For the best chance at having the bug fixed, also\n");
152 fprintf (stderr, "include the syntax file that triggered it and a sample\n");
153 fprintf (stderr, "of any data file used for input.\n");
154 fprintf (stderr, "proximate cause: %s\n", msg);
155 fprintf (stderr, "version: %s\n", stat_version);
156 fprintf (stderr, "host_system: %s\n", host_system);
157 fprintf (stderr, "build_system: %s\n", build_system);
158 fprintf (stderr, "default_config_path: %s\n", default_config_path);
159 fprintf (stderr, "include_path: %s\n", include_path);
160 fprintf (stderr, "locale_dir: %s\n", locale_dir);
161 fprintf (stderr, "compiler version: %s\n",
168 fprintf (stderr, "******************************************************\n");
170 _exit (EXIT_FAILURE);