From: Ben Pfaff Date: Tue, 25 Apr 2006 00:41:12 +0000 (+0000) Subject: Continue reforming error message support. In this phase, rename X-Git-Tag: v0.6.0~955 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fdf428d72c5695c1bc21a7158f75a542d96df8b;p=pspp-builds.git 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index 75c21188..30a56517 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +Mon Apr 24 17:40:08 2006 Ben Pfaff + + 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 * message.c: Use exit.h from gnulib instead of checking for and diff --git a/src/data/casefile.c b/src/data/casefile.c index 66baba96..229f2ab9 100644 --- a/src/data/casefile.c +++ b/src/data/casefile.c @@ -733,18 +733,18 @@ io_error (struct casefile *cf, const char *format, ...) { 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; } diff --git a/src/data/data-in.c b/src/data/data-in.c index 9da8db80..45b20a0c 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -48,7 +48,7 @@ static void dls_error (const struct data_in *, const char *format, ...) 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) @@ -62,12 +62,12 @@ vdls_error (const struct data_in *i, const char *format, va_list args) 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 diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index c137a050..a4e3b0cb 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -85,7 +85,7 @@ error (struct pfm_reader *r, const char *msg,...) static void error (struct pfm_reader *r, const char *msg, ...) { - struct error e; + struct msg m; struct string text; va_list args; @@ -96,13 +96,13 @@ error (struct pfm_reader *r, const char *msg, ...) 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; diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 6c104cb3..4c69d2bf 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -123,7 +123,7 @@ corrupt_msg (int class, const char *format,...) static void corrupt_msg (int class, const char *format,...) { - struct error e; + struct msg m; va_list args; struct string text; @@ -132,13 +132,13 @@ corrupt_msg (int class, const char *format,...) 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. */ diff --git a/src/language/command.c b/src/language/command.c index a85547ca..c9e93cc9 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -241,10 +241,10 @@ cmd_parse (void) 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 diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index 04c9319a..6002b1e9 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -2065,7 +2065,7 @@ repeating_data_set_write_case (struct transformation *trns_, static void rpd_msg (enum msg_class class, const char *format, ...) { - struct error e; + struct msg m; va_list args; struct string text; @@ -2074,11 +2074,11 @@ rpd_msg (enum msg_class class, const char *format, ...) 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); } diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index 988735dd..8fc7a80a 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -50,7 +50,7 @@ enum dfm_reader_flags 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_*. */ @@ -392,7 +392,7 @@ void 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. */ @@ -400,7 +400,7 @@ void dfm_pop (struct dfm_reader *r) { if (r->fh != fh_inline_file ()) - err_pop_file_locator (&r->where); + msg_pop_msg_locator (&r->where); } /* BEGIN DATA...END DATA procedure. */ diff --git a/src/language/expressions/helpers.c b/src/language/expressions/helpers.c index 3e28d8fe..4dd3cf3d 100644 --- a/src/language/expressions/helpers.c +++ b/src/language/expressions/helpers.c @@ -10,19 +10,19 @@ const struct fixed_string empty_string = {NULL, 0}; 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 diff --git a/src/language/line-buffer.c b/src/language/line-buffer.c index 24b09b8c..ce0160c5 100644 --- a/src/language/line-buffer.c +++ b/src/language/line-buffer.c @@ -372,7 +372,7 @@ getl_location (const char **fn, int *ln) } /* File locator stack. */ -static const struct file_locator **file_loc; +static const struct msg_locator **file_loc; static int nfile_loc, mfile_loc; /* Close getl. */ @@ -394,7 +394,7 @@ getl_uninitialize (void) /* 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) { @@ -406,28 +406,28 @@ err_push_file_locator (const struct file_locator *f) 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. diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index 2e2cad22..1b634fc9 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,15 @@ +Mon Apr 24 17:26:47 2006 Ben Pfaff + + 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 Continue reforming error message support. In this phase, get rid diff --git a/src/libpspp/message.h b/src/libpspp/message.h index 56ded21c..0cf67399 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -1,5 +1,5 @@ /* 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 . This program is free software; you can redistribute it and/or @@ -17,21 +17,12 @@ 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 #include -#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 /* What kind of message is this? */ enum msg_category @@ -49,6 +40,16 @@ enum msg_severity 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) { @@ -69,18 +70,18 @@ msg_class_from_category_and_severity (enum msg_category category, } /* 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. */ }; @@ -96,37 +97,34 @@ extern int err_already_flagged; /* 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 */ diff --git a/src/message.c b/src/message.c index a7f226a8..974347e0 100644 --- a/src/message.c +++ b/src/message.c @@ -54,17 +54,17 @@ static char *command_name; 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 @@ -110,7 +110,7 @@ static void dump_message (char *msg, unsigned width, unsigned indent); void -err_done (void) +msg_done (void) { lex_done(); getl_uninitialize (); @@ -120,7 +120,7 @@ err_done (void) /* 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 { @@ -148,35 +148,35 @@ err_msg (const struct error *e) {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); } /* Private functions. */ @@ -261,7 +261,7 @@ dump_message (char *msg, /* 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; @@ -318,7 +318,7 @@ request_bug_report_and_abort(const char *msg ) } 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); diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index 0af76936..f1a18baf 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -113,15 +113,15 @@ msg(enum msg_class klass, const char *fmt, ...) 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); } @@ -138,9 +138,9 @@ verbose_msg (int level, const char *format, ...) * 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; } diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index 746fb160..e66035d4 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -253,7 +253,7 @@ terminate (bool success) return; terminating = true; - err_done (); + msg_done (); outp_done (); cancel_transformations ();