the classification of messages along "category" and "severity" axes.
+Sun Apr 16 20:41:10 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we
+ divide the classification of messages along "category" and
+ "severity" axes.
+
+ * message.c: (err_vmsg) Rewrite to deal with categories and
+ severities in a straightforward manner instead of mixing them into
+ classes.
+ [0] (puts_stderr) Removed (dead code).
+ (msg) Changed first argument from `int' to `enum msg_class'.
+ (tmsg) Ditto.
+
Sun Apr 16 18:53:12 2006 Ben Pfaff <blp@gnu.org>
GNU standards require "file name" instead of "filename" in
struct error e;
va_list args;
- e.class = ME;
+ e.category = MSG_GENERAL;
+ e.severity = MSG_ERROR;
e.where.file_name = NULL;
e.where.line_number = -1;
e.title = NULL;
else
ds_printf (&title, _("(columns %d-%d"), i->f1, i->f2);
ds_printf (&title, _(", field type %s) "), fmt_to_string (&i->format));
-
- e.class = DE;
+
+ e.category = MSG_DATA;
+ e.severity = MSG_ERROR;
err_location (&e.where);
e.title = ds_c_str (&title);
char *title;
va_list args;
- e.class = ME;
+ e.category = MSG_GENERAL;
+ e.severity = MSG_ERROR;
e.where.file_name = NULL;
e.where.line_number = 0;
file_name = fh_get_file_name (r->fh);
struct error e;
va_list args;
- e.class = class;
+ 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.title = _("corrupt system file: ");
/* FIXME: we can do better about saying where the error
occurred. */
- e.class = SE;
+ e.category = MSG_SYNTAX;
+ e.severity = MSG_ERROR;
err_location (&e.where);
e.title = NULL;
if (temporary != 0)
{
- msg (SM, _("FLIP ignores TEMPORARY. "
+ msg (SW, _("FLIP ignores TEMPORARY. "
"Temporary transformations will be made permanent."));
cancel_temporary ();
}
show_blanks (void)
{
if (get_blanks () == SYSMIS)
- msg (MM, _("BLANKS is SYSMIS."));
+ msg (MN, _("BLANKS is SYSMIS."));
else
- msg (MM, _("BLANKS is %g."), get_blanks ());
+ msg (MN, _("BLANKS is %g."), get_blanks ());
}
out = format_cc (cc->neg_suffix, cc->grouping, out);
*out = '\0';
- msg (MM, _("CC%c is \"%s\"."), "ABCDE"[idx], cc_string);
+ msg (MN, _("CC%c is \"%s\"."), "ABCDE"[idx], cc_string);
}
static void
show_decimals (void)
{
- msg (MM, _("DECIMAL is \"%c\"."), get_decimal ());
+ msg (MN, _("DECIMAL is \"%c\"."), get_decimal ());
}
static void
show_endcmd (void)
{
- msg (MM, _("ENDCMD is \"%c\"."), get_endcmd ());
+ msg (MN, _("ENDCMD is \"%c\"."), get_endcmd ());
}
static void
show_format (void)
{
- msg (MM, _("FORMAT is %s."), fmt_to_string (get_format ()));
+ msg (MN, _("FORMAT is %s."), fmt_to_string (get_format ()));
}
static void
show_length (void)
{
- msg (MM, _("LENGTH is %d."), get_viewlength ());
+ msg (MN, _("LENGTH is %d."), get_viewlength ());
}
static void
show_mxerrs (void)
{
- msg (MM, _("MXERRS is %d."), get_mxerrs ());
+ msg (MN, _("MXERRS is %d."), get_mxerrs ());
}
static void
show_mxloops (void)
{
- msg (MM, _("MXLOOPS is %d."), get_mxloops ());
+ msg (MN, _("MXLOOPS is %d."), get_mxloops ());
}
static void
show_mxwarns (void)
{
- msg (MM, _("MXWARNS is %d."), get_mxwarns ());
+ msg (MN, _("MXWARNS is %d."), get_mxwarns ());
}
static void
show_scompression (void)
{
if (get_scompression ())
- msg (MM, _("SCOMPRESSION is ON."));
+ msg (MN, _("SCOMPRESSION is ON."));
else
- msg (MM, _("SCOMPRESSION is OFF."));
+ msg (MN, _("SCOMPRESSION is OFF."));
}
static void
show_undefined (void)
{
if (get_undefined ())
- msg (MM, _("UNDEFINED is WARN."));
+ msg (MN, _("UNDEFINED is WARN."));
else
- msg (MM, _("UNDEFINED is NOWARN."));
+ msg (MN, _("UNDEFINED is NOWARN."));
}
static void
{
struct variable *var = dict_get_weight (default_dict);
if (var == NULL)
- msg (MM, _("WEIGHT is off."));
+ msg (MN, _("WEIGHT is off."));
else
- msg (MM, _("WEIGHT is variable %s."), var->name);
+ msg (MN, _("WEIGHT is variable %s."), var->name);
}
static void
show_width (void)
{
- msg (MM, _("WIDTH is %d."), get_viewwidth ());
+ msg (MN, _("WIDTH is %d."), get_viewwidth ());
}
struct show_sbc
static void
show_warranty (void)
{
- msg (MM, lack_of_warranty);
+ msg (MN, lack_of_warranty);
}
static void
show_copying (void)
{
- msg (MM, copyleft);
+ msg (MN, copyleft);
}
int
+Sun Apr 16 20:43:35 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we
+ divide the classification of messages along "category" and
+ "severity" axes.
+
+ * message.h: (enum msg_class) Named this set of enumerations.
+ (enum msg_category) New enum: MSG_GENERAL, MSG_SYNTAX, MSG_DATA.
+ (enum msg_severity) New enum: MSG_ERROR, MSG_WARNING, MSG_NOTE.
+ (msg_class_to_category) New inline function.
+ (msg_class_to_severity) New inline function.
+ (msg_class_from_category_and_severity) New inline function.
+ (struct error) Removed `class' member, added `category',
+ `severity'. Updated all users of this struct to use the new
+ members.
+
Sun Apr 16 20:33:19 2006 Ben Pfaff <blp@gnu.org>
* str.c (ds_vprintf): Don't try to write into the string if it is
#include "compiler.h"
/* Message classes. */
-enum
+enum msg_class
{
- SE, SW, SM, /* Script error/warning/message. */
- DE, DW, /* Data-file error/warning. */
- ME, MW, MM, /* General error/warning/message. */
+ ME, MW, MN, /* General error/warning/note. */
+ SE, SW, SN, /* Script error/warning/note. */
+ DE, DW, DN, /* Data-file error/note. */
MSG_CLASS_CNT,
};
+/* What kind of message is this? */
+enum msg_category
+ {
+ MSG_GENERAL, /* General info. */
+ MSG_SYNTAX, /* Messages that relate to syntax files. */
+ MSG_DATA /* Messages that relate to data files. */
+ };
+
+/* How important a condition is it? */
+enum msg_severity
+ {
+ MSG_ERROR,
+ MSG_WARNING,
+ MSG_NOTE
+ };
+
+static inline enum msg_category
+msg_class_to_category (enum msg_class class)
+{
+ return class / 3;
+}
+
+static inline enum msg_severity
+msg_class_to_severity (enum msg_class class)
+{
+ return class % 3;
+}
+
+static inline enum msg_class
+msg_class_from_category_and_severity (enum msg_category category,
+ enum msg_severity severity)
+{
+ return category * 3 + severity;
+}
+
/* A file location. */
struct file_locator
{
/* An error message. */
struct error
{
- int class; /* One of the classes above. */
+ enum msg_category category; /* Message category. */
+ enum msg_severity severity; /* Message severity. */
struct file_locator where; /* File location, or (NULL, -1). */
const char *title; /* Special text inserted if not null. */
};
extern int err_verbosity;
/* Functions. */
-void msg (int class, const char *format, ...)
+void msg (enum msg_class, const char *format, ...)
PRINTF_FORMAT (2, 3);
-void tmsg (int class, const char *title, const char *format, ...)
+void tmsg (enum msg_class, const char *title, const char *format, ...)
PRINTF_FORMAT (3, 4);
void verbose_msg (int level, const char *format, ...)
static char *command_name;
\f
-/* Fairly common public functions. */
+/* Public functions. */
/* Writes error message in CLASS, with title TITLE and text FORMAT,
formatted with printf, to the standard places. */
void
-tmsg (int class, const char *title, const char *format, ...)
+tmsg (enum msg_class class, const char *title, const char *format, ...)
{
struct error e;
va_list args;
- e.class = class;
+ e.category = msg_class_to_category (class);
+ e.severity = msg_class_to_severity (class);
err_location (&e.where);
e.title = title;
/* Writes error message in CLASS, with text FORMAT, formatted with
printf, to the standard places. */
void
-msg (int class, const char *format, ...)
+msg (enum msg_class class, const char *format, ...)
{
struct error e;
va_list args;
- e.class = class;
+ e.category = msg_class_to_category (class);
+ e.severity = msg_class_to_severity (class);
err_location (&e.where);
e.title = NULL;
err_check_count (void)
{
if (get_errorbreak() && err_error_count)
- msg (MM, _("Terminating execution of syntax file due to error."));
+ msg (MN, _("Terminating execution of syntax file due to error."));
else if (err_error_count > get_mxerrs() )
- msg (MM, _("Errors (%d) exceeds limit (%d)."),
+ msg (MN, _("Errors (%d) exceeds limit (%d)."),
err_error_count, get_mxerrs());
else if (err_error_count + err_warning_count > get_mxwarns() )
- msg (MM, _("Warnings (%d) exceed limit (%d)."),
+ msg (MN, _("Warnings (%d) exceed limit (%d)."),
err_error_count + err_warning_count, get_mxwarns() );
else
return;
void
err_vmsg (const struct error *e, const char *format, va_list args)
{
- /* Class flags. */
- enum
+ struct category
{
- ERR_IN_PROCEDURE = 01, /* 1=Display name of current procedure. */
- ERR_WITH_FILE = 02, /* 1=Display file name and line number. */
+ bool show_command_name; /* Show command name with error? */
+ bool show_file_location; /* Show syntax file location? */
};
- /* Describes one class of error. */
- struct error_class
+ static const struct category categories[] =
{
- int flags; /* Zero or more of ERR_*. */
- int *count; /* Counting category. */
- const char *banner; /* Banner. */
+ {false, false}, /* MSG_GENERAL. */
+ {true, true}, /* MSG_SYNTAX. */
+ {false, true}, /* MSG_DATA. */
};
- static const struct error_class error_classes[MSG_CLASS_CNT] =
+ struct severity
{
- {3, &err_error_count, N_("error")}, /* SE */
- {3, &err_warning_count, N_("warning")}, /* SW */
- {3, NULL, N_("note")}, /* SM */
-
- {2, &err_error_count, N_("error")}, /* DE */
- {2, &err_warning_count, N_("warning")}, /* DW */
-
- {0, &err_error_count, N_("error")}, /* ME */
- {0, &err_warning_count, N_("warning")}, /* MW */
- {0, NULL, N_("note")}, /* MM */
+ const char *name; /* How to identify this severity. */
+ int *count; /* Number of msgs with this severity so far. */
+ };
+
+ static struct severity severities[] =
+ {
+ {N_("error"), &err_error_count}, /* MSG_ERROR. */
+ {N_("warning"), &err_warning_count}, /* MSG_WARNING. */
+ {NULL, NULL}, /* MSG_NOTE. */
};
- struct string msg;
+ const struct category *category = &categories[e->category];
+ const struct severity *severity = &severities[e->severity];
+ struct string msg = DS_INITIALIZER;
- assert (e->class >= 0 && e->class < MSG_CLASS_CNT);
- assert (format != NULL);
-
- ds_init (&msg, 64);
- if (e->where.file_name && (error_classes[e->class].flags & ERR_WITH_FILE))
+ if (category->show_file_location && e->where.file_name)
{
ds_printf (&msg, "%s:", e->where.file_name);
if (e->where.line_number != -1)
ds_putc (&msg, ' ');
}
- ds_printf (&msg, "%s: ", gettext (error_classes[e->class].banner));
+ if (severity->name != NULL)
+ ds_printf (&msg, "%s: ", gettext (severity->name));
- {
- int *count = error_classes[e->class].count;
- if (count)
- (*count)++;
- }
+ if (severity->count != NULL)
+ ++*severity->count;
- if (command_name != NULL
- && (error_classes[e->class].flags & ERR_IN_PROCEDURE))
+ if (category->show_command_name && command_name != NULL)
ds_printf (&msg, "%s: ", command_name);
if (e->title)
ds_vprintf (&msg, format, args);
/* FIXME: Check set_messages and set_errors to determine where to
- send errors and messages.
-
- Please note that this is not trivial. We have to avoid an
- infinite loop in reporting errors that originate in the output
- section. */
+ send errors and messages. */
dump_message (ds_c_str (&msg), 8, puts_stdout, get_viewwidth());
ds_destroy (&msg);
\f
/* Private functions. */
-#if 0
-/* Write S followed by a newline to stderr. */
-static void
-puts_stderr (const char *s)
-{
- fputs (s, stderr);
- fputc ('\n', stderr);
-}
-#endif
-
/* Write S followed by a newline to stdout. */
static void
puts_stdout (const char *s)
+Sun Apr 16 20:45:35 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we
+ divide the classification of messages along "category" and
+ "severity" axes.
+
+ * message-dialog.c: (vmsg) Use severity and category in
+ straightforward fashion instead of the less obvious "class".
+ (err_vmsg) Construct class before passing along to vmsg().
+
Sun Apr 16 16:06:54 2006 Ben Pfaff <blp@gnu.org>
Continue reforming error message support. In this phase, we get
gint message_type;
- switch (klass)
+ switch (msg_class_to_severity (klass))
{
- case SE:
- case DE:
- case ME:
+ case MSG_ERROR:
message_type = GTK_MESSAGE_ERROR;
break;
- case SW:
- case DW:
- case MW:
+ case MSG_WARNING:
message_type = GTK_MESSAGE_WARNING;
break;
- case SM:
- case MM:
+ case MSG_NOTE:
default:
message_type = GTK_MESSAGE_INFO;
break;
};
- switch (klass)
+ switch (msg_class_to_category (klass))
{
- case SE:
- case SW:
- case SM:
+ case MSG_SYNTAX:
msg = g_strdup(_("Script Error"));
break;
- case DE:
- case DW:
+ case MSG_DATA:
msg = g_strdup(_("Data File Error"));
break;
- case ME:
- case MW:
- case MM:
+ case MSG_GENERAL:
default:
msg = g_strdup(_("PSPP Error"));
break;
void
-msg(int klass, const char *fmt, ...)
+msg(enum msg_class klass, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
void
err_vmsg (const struct error *e, const char *format, va_list args)
{
- vmsg(e->class, format, args);
+ vmsg(msg_class_from_category_and_severity (e->category, e->severity),
+ format, args);
}
#include <libpspp/message.h>
-void vmsg(int klass, const char *fmt, va_list args);
-void msg(int klass, const char *fmt, ...);
-
-
#endif