+Mon Apr 24 17:40:08 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, rename
+ all the message functions and types to start with "msg", except
+ for the ones that will be moving to other modules anyway.
+
+ All references to the identifiers below were updated likewise.
+
+ * message.c: (err_done) Renamed msg_done().
+ (err_push_file_locator) Renamed msg_push_msg_locator().
+ (err_pop_file_locator) Renamed msg_pop_msg_locator().
+ (err_location) Renamed msg_location().
+ (err_set_command_name) Renamed msg_set_command_name().
+
Mon Apr 24 14:11:33 2006 Ben Pfaff <blp@gnu.org>
* message.c: Use exit.h from gnulib instead of checking for and
{
if (cf->ok)
{
- struct error e;
+ struct msg m;
va_list args;
- e.category = MSG_GENERAL;
- e.severity = MSG_ERROR;
- e.where.file_name = NULL;
- e.where.line_number = -1;
+ m.category = MSG_GENERAL;
+ m.severity = MSG_ERROR;
+ m.where.file_name = NULL;
+ m.where.line_number = -1;
va_start (args, format);
- e.text = xvasprintf (format, args);
+ m.text = xvasprintf (format, args);
va_end (args);
- err_msg (&e);
+ msg_emit (&m);
}
cf->ok = false;
}
static void
vdls_error (const struct data_in *i, const char *format, va_list args)
{
- struct error e;
+ struct msg m;
struct string text;
if (i->flags & DI_IGNORE_ERROR)
ds_printf (&text, _(", field type %s) "), fmt_to_string (&i->format));
ds_vprintf (&text, format, args);
- e.category = MSG_DATA;
- e.severity = MSG_ERROR;
- err_location (&e.where);
- e.text = ds_c_str (&text);
+ m.category = MSG_DATA;
+ m.severity = MSG_ERROR;
+ msg_location (&m.where);
+ m.text = ds_c_str (&text);
- err_msg (&e);
+ msg_emit (&m);
}
static void
static void
error (struct pfm_reader *r, const char *msg, ...)
{
- struct error e;
+ struct msg m;
struct string text;
va_list args;
ds_vprintf (&text, msg, args);
va_end (args);
- e.category = MSG_GENERAL;
- e.severity = MSG_ERROR;
- e.where.file_name = NULL;
- e.where.line_number = 0;
- e.text = ds_c_str (&text);
+ m.category = MSG_GENERAL;
+ m.severity = MSG_ERROR;
+ m.where.file_name = NULL;
+ m.where.line_number = 0;
+ m.text = ds_c_str (&text);
- err_msg (&e);
+ msg_emit (&m);
r->ok = false;
static void
corrupt_msg (int class, const char *format,...)
{
- struct error e;
+ struct msg m;
va_list args;
struct string text;
ds_vprintf (&text, format, args);
va_end (args);
- e.category = msg_class_to_category (class);
- e.severity = msg_class_to_severity (class);
- e.where.file_name = NULL;
- e.where.line_number = 0;
- e.text = ds_c_str (&text);
+ m.category = msg_class_to_category (class);
+ m.severity = msg_class_to_severity (class);
+ m.where.file_name = NULL;
+ m.where.line_number = 0;
+ m.text = ds_c_str (&text);
- err_msg (&e);
+ msg_emit (&m);
}
/* Closes a system file after we're done with it. */
int result;
/* Call the command dispatcher. */
- err_set_command_name (cp->name);
+ msg_set_command_name (cp->name);
tab_set_command_name (cp->name);
result = cp->func ();
- err_set_command_name (NULL);
+ msg_set_command_name (NULL);
tab_set_command_name (NULL);
/* Perform the state transition if the command completed
static void
rpd_msg (enum msg_class class, const char *format, ...)
{
- struct error e;
+ struct msg m;
va_list args;
struct string text;
ds_vprintf (&text, format, args);
va_end (args);
- e.category = msg_class_to_category (class);
- e.severity = msg_class_to_severity (class);
- e.where.file_name = NULL;
- e.where.line_number = 0;
- e.text = ds_c_str (&text);
+ m.category = msg_class_to_category (class);
+ m.severity = msg_class_to_severity (class);
+ m.where.file_name = NULL;
+ m.where.line_number = 0;
+ m.text = ds_c_str (&text);
- err_msg (&e);
+ msg_emit (&m);
}
struct dfm_reader
{
struct file_handle *fh; /* File handle. */
- struct file_locator where; /* Current location in data file. */
+ struct msg_locator where; /* Current location in data file. */
struct string line; /* Current line. */
struct string scratch; /* Extra line buffer. */
enum dfm_reader_flags flags; /* Zero or more of DFM_*. */
dfm_push (struct dfm_reader *r)
{
if (r->fh != fh_inline_file ())
- err_push_file_locator (&r->where);
+ msg_push_msg_locator (&r->where);
}
/* Pops the file name and line number from the fn/ln stack. */
dfm_pop (struct dfm_reader *r)
{
if (r->fh != fh_inline_file ())
- err_pop_file_locator (&r->where);
+ msg_pop_msg_locator (&r->where);
}
\f
/* BEGIN DATA...END DATA procedure. */
static void
expr_error (void *aux UNUSED, const char *format, ...)
{
- struct error e;
+ struct msg m;
va_list args;
/* FIXME: we can do better about saying where the error
occurred. */
- e.category = MSG_SYNTAX;
- e.severity = MSG_ERROR;
- err_location (&e.where);
+ m.category = MSG_SYNTAX;
+ m.severity = MSG_ERROR;
+ msg_location (&m.where);
va_start (args, format);
- e.text = xvasprintf (format, args);
+ m.text = xvasprintf (format, args);
va_end (args);
- err_msg (&e);
+ msg_emit (&m);
}
double
}
/* File locator stack. */
-static const struct file_locator **file_loc;
+static const struct msg_locator **file_loc;
static int nfile_loc, mfile_loc;
\f
/* Close getl. */
/* Pushes F onto the stack of file locations. */
void
-err_push_file_locator (const struct file_locator *f)
+msg_push_msg_locator (const struct msg_locator *loc)
{
if (nfile_loc >= mfile_loc)
{
file_loc = xnrealloc (file_loc, mfile_loc, sizeof *file_loc);
}
- file_loc[nfile_loc++] = f;
+ file_loc[nfile_loc++] = loc;
}
/* Pops F off the stack of file locations.
Argument F is only used for verification that that is actually the
item on top of the stack. */
void
-err_pop_file_locator (const struct file_locator *f)
+msg_pop_msg_locator (const struct msg_locator *loc)
{
- assert (nfile_loc >= 0 && file_loc[nfile_loc - 1] == f);
+ assert (nfile_loc >= 0 && file_loc[nfile_loc - 1] == loc);
nfile_loc--;
}
/* Puts the current file and line number in F, or NULL and -1 if
none. */
void
-err_location (struct file_locator *f)
+msg_location (struct msg_locator *loc)
{
if (nfile_loc)
- *f = *file_loc[nfile_loc - 1];
+ *loc = *file_loc[nfile_loc - 1];
else
- getl_location (&f->file_name, &f->line_number);
+ getl_location (&loc->file_name, &loc->line_number);
}
/* Reads a line from syntax file source S into LINE.
+Mon Apr 24 17:26:47 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, rename
+ all the message functions and types to start with "msg", except
+ for the ones that will be moving to other modules anyway.
+
+ All references to the identifiers below were updated likewise.
+
+ * message.h: (enum file_locator) Renamed `enum msg_locator'.
+ (struct error) Renamed `struct msg'.
+ (err_assert_fail) Renamed msg_assert_fail().
+
Sun Apr 23 22:07:06 2006 Ben Pfaff <blp@gnu.org>
Continue reforming error message support. In this phase, get rid
/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
Written by Ben Pfaff <blp@gnu.org>.
This program is free software; you can redistribute it and/or
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA. */
-#if !error_h
-#define error_h 1
+#ifndef MESSAGE_H
+#define MESSAGE_H 1
#include <stdarg.h>
#include <stdbool.h>
-#include "compiler.h"
-
-/* Message classes. */
-enum msg_class
- {
- ME, MW, MN, /* General error/warning/note. */
- SE, SW, SN, /* Script error/warning/note. */
- DE, DW, DN, /* Data-file error/note. */
- MSG_CLASS_CNT,
- };
+#include <libpspp/compiler.h>
/* What kind of message is this? */
enum msg_category
MSG_NOTE
};
+/* Combination of a category and a severity for convenience. */
+enum msg_class
+ {
+ ME, MW, MN, /* General error/warning/note. */
+ SE, SW, SN, /* Script error/warning/note. */
+ DE, DW, DN, /* Data-file error/note. */
+ MSG_CLASS_CNT,
+ };
+
+
static inline enum msg_category
msg_class_to_category (enum msg_class class)
{
}
/* A file location. */
-struct file_locator
+struct msg_locator
{
const char *file_name; /* File name. */
int line_number; /* Line number. */
};
-/* An error message. */
-struct error
+/* A message. */
+struct msg
{
enum msg_category category; /* Message category. */
enum msg_severity severity; /* Message severity. */
- struct file_locator where; /* File location, or (NULL, -1). */
+ struct msg_locator where; /* File location, or (NULL, -1). */
char *text; /* Error text. */
};
/* Nonnegative verbosity level. Higher value == more verbose. */
extern int err_verbosity;
+/* Initialization. */
+void msg_done (void);
+
/* Emitting messages. */
void msg (enum msg_class, const char *format, ...)
PRINTF_FORMAT (2, 3);
-void err_msg (const struct error *);
+void msg_emit (const struct msg *);
void verbose_msg (int level, const char *format, ...)
PRINTF_FORMAT (2, 3);
-/* File-locator stack. */
-void err_push_file_locator (const struct file_locator *);
-void err_pop_file_locator (const struct file_locator *);
-void err_location (struct file_locator *);
-
-/* Obscure functions. */
-void err_set_command_name (const char *);
-void err_done (void);
+/* Error context. */
+void msg_set_command_name (const char *);
+void msg_push_msg_locator (const struct msg_locator *);
+void msg_pop_msg_locator (const struct msg_locator *);
+void msg_location (struct msg_locator *);
void err_check_count (void);
-/* Used in panic situations only */
-void request_bug_report_and_abort(const char *msg );
+/* Used in panic situations only. */
+void request_bug_report_and_abort (const char *msg);
-void err_assert_fail(const char *expr, const char *file, int line);
+void msg_assert_fail (const char *expr, const char *file, int line);
#undef __STRING
#define __STRING(x) #x
#undef assert
-
#define assert(expr) ( (void) ( expr ? (void) 0 : \
- err_assert_fail(__STRING(expr), __FILE__, __LINE__)) )
-
-
+ msg_assert_fail(__STRING(expr), __FILE__, __LINE__)) )
-#endif /* error.h */
+#endif /* message.h */
void
msg (enum msg_class class, const char *format, ...)
{
- struct error e;
+ struct msg m;
va_list args;
- e.category = msg_class_to_category (class);
- e.severity = msg_class_to_severity (class);
- err_location (&e.where);
+ m.category = msg_class_to_category (class);
+ m.severity = msg_class_to_severity (class);
+ msg_location (&m.where);
va_start (args, format);
- e.text = xvasprintf (format, args);
+ m.text = xvasprintf (format, args);
va_end (args);
- err_msg (&e);
+ msg_emit (&m);
}
/* Writes MESSAGE formatted with printf, to stderr, if the
unsigned width, unsigned indent);
void
-err_done (void)
+msg_done (void)
{
lex_done();
getl_uninitialize ();
/* Emits E as an error message.
Frees `text' member in E. */
void
-err_msg (const struct error *e)
+msg_emit (const struct msg *m)
{
struct category
{
{NULL, NULL}, /* MSG_NOTE. */
};
- const struct category *category = &categories[e->category];
- const struct severity *severity = &severities[e->severity];
- struct string msg = DS_INITIALIZER;
+ const struct category *category = &categories[m->category];
+ const struct severity *severity = &severities[m->severity];
+ struct string string = DS_INITIALIZER;
- if (category->show_file_location && e->where.file_name)
+ if (category->show_file_location && m->where.file_name)
{
- ds_printf (&msg, "%s:", e->where.file_name);
- if (e->where.line_number != -1)
- ds_printf (&msg, "%d:", e->where.line_number);
- ds_putc (&msg, ' ');
+ ds_printf (&string, "%s:", m->where.file_name);
+ if (m->where.line_number != -1)
+ ds_printf (&string, "%d:", m->where.line_number);
+ ds_putc (&string, ' ');
}
if (severity->name != NULL)
- ds_printf (&msg, "%s: ", gettext (severity->name));
+ ds_printf (&string, "%s: ", gettext (severity->name));
if (severity->count != NULL)
++*severity->count;
if (category->show_command_name && command_name != NULL)
- ds_printf (&msg, "%s: ", command_name);
+ ds_printf (&string, "%s: ", command_name);
- ds_puts (&msg, e->text);
+ ds_puts (&string, m->text);
/* FIXME: Check set_messages and set_errors to determine where to
send errors and messages. */
- dump_message (ds_c_str (&msg), puts_stdout, get_viewwidth (), 8);
+ dump_message (ds_c_str (&string), puts_stdout, get_viewwidth (), 8);
- ds_destroy (&msg);
- free (e->text);
+ ds_destroy (&string);
+ free (m->text);
}
\f
/* Private functions. */
/* Sets COMMAND_NAME as the command name included in some kinds
of error messages. */
void
-err_set_command_name (const char *command_name_)
+msg_set_command_name (const char *command_name_)
{
free (command_name);
command_name = command_name_ ? xstrdup (command_name_) : NULL;
}
void
-err_assert_fail(const char *expr, const char *file, int line)
+msg_assert_fail(const char *expr, const char *file, int line)
{
char msg[256];
snprintf(msg,256,"Assertion failed: %s:%d; (%s)",file,line,expr);
void
-err_msg (const struct error *e)
+msg_emit (const struct msg *m)
{
- vmsg(msg_class_from_category_and_severity (e->category, e->severity),
- "%s", e->text);
+ vmsg (msg_class_from_category_and_severity (m->category, m->severity),
+ "%s", m->text);
}
void
-err_assert_fail(const char *expr, const char *file, int line)
+msg_assert_fail(const char *expr, const char *file, int line)
{
msg(ME, "Assertion failed: %s:%d; (%s)\n",file,line,expr);
}
* A temporary workaround until getl.c is rearranged
*/
void
-err_location (struct file_locator *f)
+msg_location (struct msg_locator *loc)
{
- f->file_name = 0;
- f->line_number = -1;
+ loc->file_name = 0;
+ loc->line_number = -1;
}
return;
terminating = true;
- err_done ();
+ msg_done ();
outp_done ();
cancel_transformations ();