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
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 *);
40 static void (*msg_location) (struct msg_locator *);
43 /* Public functions. */
45 /* Writes error message in CLASS, with text FORMAT, formatted with
46 printf, to the standard places. */
48 msg (enum msg_class class, const char *format, ...)
53 m.category = msg_class_to_category (class);
54 m.severity = msg_class_to_severity (class);
55 va_start (args, format);
56 m.text = xvasprintf (format, args);
63 msg_init ( void (*handler) (const struct msg *),
64 void (*location) (struct msg_locator *) )
66 msg_handler = handler;
67 msg_location = location;
76 /* Duplicate a message */
78 msg_dup(const struct msg *m)
80 struct msg *new_msg = xmalloc (sizeof *m);
83 new_msg->text = strdup(m->text);
89 msg_destroy(struct msg *m)
96 /* Emits M as an error message.
97 Frees allocated data in M. */
99 msg_emit (struct msg *m)
101 msg_location (&m->where);
106 /* Private functions. */
108 /* Sets COMMAND_NAME as the command name included in some kinds
109 of error messages. */
111 msg_set_command_name (const char *command_name_)
114 command_name = command_name_ ? xstrdup (command_name_) : NULL;
117 /* Returns the current command name, or NULL if none. */
119 msg_get_command_name (void)
125 request_bug_report_and_abort(const char *msg )
128 "******************************************************************\n"
129 "You have discovered a bug in PSPP.\n\n"
130 " Please report this, by sending "
131 "an email to " PACKAGE_BUGREPORT ",\n"
132 "explaining what you were doing when this happened, and including\n"
133 "a sample of your input file which caused it.\n");
136 "Also, please copy the following lines into your bug report:\n\n"
142 "default_config_path: %s\n"
145 "compiler version: %s\n"
164 fprintf(stderr,"Diagnosis: %s\n",msg);
167 "******************************************************************\n");
173 msg_assert_fail(const char *expr, const char *file, int line)
176 snprintf(msg,256,"Assertion failed: %s:%d; (%s)",file,line,expr);
177 request_bug_report_and_abort( msg );