1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 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
22 #include <libpspp/message.h>
29 #include <libpspp/alloc.h>
30 #include <libpspp/version.h>
33 #include "xvasprintf.h"
35 /* Current command name as set by msg_set_command_name(). */
36 static char *command_name;
38 /* Message handler as set by msg_init(). */
39 static void (*msg_handler) (const struct msg *);
41 /* Public functions. */
43 /* Writes error message in CLASS, with text FORMAT, formatted with
44 printf, to the standard places. */
46 msg (enum msg_class class, const char *format, ...)
51 m.category = msg_class_to_category (class);
52 m.severity = msg_class_to_severity (class);
53 msg_location (&m.where);
54 va_start (args, format);
55 m.text = xvasprintf (format, args);
62 msg_init (void (*handler) (const struct msg *))
64 msg_handler = handler;
73 /* Duplicate a message */
75 msg_dup(const struct msg *m)
77 struct msg *new_msg = xmalloc (sizeof *m);
80 new_msg->text = strdup(m->text);
86 msg_destroy(struct msg *m)
93 /* Emits M as an error message.
94 Frees allocated data in M. */
96 msg_emit (struct msg *m)
102 /* Private functions. */
104 /* Sets COMMAND_NAME as the command name included in some kinds
105 of error messages. */
107 msg_set_command_name (const char *command_name_)
110 command_name = command_name_ ? xstrdup (command_name_) : NULL;
113 /* Returns the current command name, or NULL if none. */
115 msg_get_command_name (void)
121 request_bug_report_and_abort(const char *msg )
124 "******************************************************************\n"
125 "You have discovered a bug in PSPP.\n\n"
126 " Please report this, by sending "
127 "an email to " PACKAGE_BUGREPORT ",\n"
128 "explaining what you were doing when this happened, and including\n"
129 "a sample of your input file which caused it.\n");
132 "Also, please copy the following lines into your bug report:\n\n"
138 "default_config_path: %s\n"
141 "compiler version: %s\n"
160 fprintf(stderr,"Diagnosis: %s\n",msg);
163 "******************************************************************\n");
169 msg_assert_fail(const char *expr, const char *file, int line)
172 snprintf(msg,256,"Assertion failed: %s:%d; (%s)",file,line,expr);
173 request_bug_report_and_abort( msg );