From: Ben Pfaff Date: Mon, 24 Apr 2006 05:09:59 +0000 (+0000) Subject: Continue reforming error message support. In this phase, get rid of X-Git-Tag: v0.6.0~958 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c8c1170e3b3cb59f9bf8fe6b27ecba7067b8cfa;p=pspp-builds.git Continue reforming error message support. In this phase, get rid of message "titles" and put the message text in `struct error'. Now `struct error' encapsulates a message more properly. --- diff --git a/src/ChangeLog b/src/ChangeLog index 8f3b355f..2930c220 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +Sun Apr 23 22:00:23 2006 Ben Pfaff + + Continue reforming error message support. In this phase, get rid + of message "titles" and put the message text in `struct error'. + Now `struct error' encapsulates a message more properly. + + * message.c: (tmsg) Removed. + (msg) Use err_msg() instead of err_vmsg(). Format message + ourselves. + (err_vmsg) Renamed err_msg(). Changed interface, dropping message + and va_list args which are now in the error struct. + Sun Apr 23 20:35:28 2006 Ben Pfaff Continue reforming error message support. diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 2c0a6a66..38510757 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,18 @@ +Sun Apr 23 22:04:45 2006 Ben Pfaff + + Continue reforming error message support. In this phase, get rid + of message "titles" and put the message text in `struct error'. + Now `struct error' encapsulates a message more properly. + + * casefile.c: (io_error) Use err_msg() instead of err_vmsg(). + Format message ourselves. + + * data-in.c: (vdls_error) Ditto. + + * por-file-reader.c: (error) Ditto. + + * sys-file-reader.c: (corrupt_msg) Ditto. + Sun Apr 16 18:49:51 2006 Ben Pfaff GNU standards require "file name" instead of "filename" in diff --git a/src/data/casefile.c b/src/data/casefile.c index cf2d4f8d..66baba96 100644 --- a/src/data/casefile.c +++ b/src/data/casefile.c @@ -740,11 +740,11 @@ io_error (struct casefile *cf, const char *format, ...) e.severity = MSG_ERROR; e.where.file_name = NULL; e.where.line_number = -1; - e.title = NULL; - va_start (args, format); - err_vmsg (&e, format, args); + e.text = xvasprintf (format, args); va_end (args); + + err_msg (&e); } cf->ok = false; } diff --git a/src/data/data-in.c b/src/data/data-in.c index 1180b32b..9da8db80 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -49,26 +49,25 @@ static void vdls_error (const struct data_in *i, const char *format, va_list args) { struct error e; - struct string title; + struct string text; if (i->flags & DI_IGNORE_ERROR) return; - ds_init (&title, 64); + ds_init (&text, 64); if (i->f1 == i->f2) - ds_printf (&title, _("(column %d"), i->f1); + ds_printf (&text, _("(column %d"), i->f1); else - ds_printf (&title, _("(columns %d-%d"), i->f1, i->f2); - ds_printf (&title, _(", field type %s) "), fmt_to_string (&i->format)); + ds_printf (&text, _("(columns %d-%d"), i->f1, i->f2); + 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.title = ds_c_str (&title); + e.text = ds_c_str (&text); - err_vmsg (&e, format, args); - - ds_destroy (&title); + err_msg (&e); } static void diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index 5b49fa5a..c137a050 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -86,22 +86,23 @@ static void error (struct pfm_reader *r, const char *msg, ...) { struct error e; - const char *file_name; - char *title; + struct string text; va_list args; + ds_init (&text, 64); + ds_printf (&text, _("portable file %s corrupt at offset %ld: "), + fh_get_file_name (r->fh), ftell (r->file)); + va_start (args, 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; - file_name = fh_get_file_name (r->fh); - e.title = title = pool_alloc (r->pool, strlen (file_name) + 80); - sprintf (title, _("portable file %s corrupt at offset %ld: "), - file_name, ftell (r->file)); - - va_start (args, msg); - err_vmsg (&e, msg, args); - va_end (args); + e.text = ds_c_str (&text); + + err_msg (&e); r->ok = false; diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index ebf0a7b1..6c104cb3 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -125,16 +125,20 @@ corrupt_msg (int class, const char *format,...) { struct error e; va_list args; + struct string text; + + ds_create (&text, _("corrupt system file: ")); + va_start (args, 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.title = _("corrupt system file: "); + e.text = ds_c_str (&text); - va_start (args, format); - err_vmsg (&e, format, args); - va_end (args); + err_msg (&e); } /* Closes a system file after we're done with it. */ diff --git a/src/language/data-io/ChangeLog b/src/language/data-io/ChangeLog index bfbe4043..d6c0ba3c 100644 --- a/src/language/data-io/ChangeLog +++ b/src/language/data-io/ChangeLog @@ -1,3 +1,13 @@ +Sun Apr 23 22:05:58 2006 Ben Pfaff + + Continue reforming error message support. In this phase, get rid + of message "titles" and put the message text in `struct error'. + Now `struct error' encapsulates a message more properly. + + * data-list.c: (macro RPD_ERR) Removed. + (rpd_msg) New function. Updated all references to tmsg() to call + this function instead. + Sat Apr 15 19:38:13 2006 Ben Pfaff Remove last users of struct file_ext so we can get rid of it diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index 6609e32b..04c9319a 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -98,6 +98,7 @@ struct data_list_pgm static const struct case_source_class data_list_source_class; +static void rpd_msg (enum msg_class, const char *format, ...); static int parse_fixed (struct data_list_pgm *); static int parse_free (struct dls_var_spec **, struct dls_var_spec **); static void dump_fixed_table (const struct dls_var_spec *, @@ -108,9 +109,6 @@ static void destroy_dls_var_spec (struct dls_var_spec *); static trns_free_func data_list_trns_free; static trns_proc_func data_list_trns_proc; -/* Message title for REPEATING DATA. */ -#define RPD_ERR "REPEATING DATA: " - int cmd_data_list (void) { @@ -1814,9 +1812,10 @@ rpd_parse_record (const struct rpd_parse_info *info) data_out (actual_str, &t->id_var->print, id_temp); actual_str[t->id_var->print.w] = '\0'; - tmsg (SE, RPD_ERR, - _("Encountered mismatched record ID \"%s\" expecting \"%s\"."), - actual_str, expected_str); + rpd_msg (SE, + _("Encountered mismatched record ID \"%s\" " + "expecting \"%s\"."), + actual_str, expected_str); return 0; } @@ -1846,10 +1845,10 @@ rpd_parse_record (const struct rpd_parse_info *info) { warned = 1; - tmsg (SW, RPD_ERR, - _("Variable %s starting in column %d extends " - "beyond physical record length of %d."), - var_spec->v->name, fc, info->len); + rpd_msg (SW, + _("Variable %s starting in column %d extends " + "beyond physical record length of %d."), + var_spec->v->name, fc, info->len); } { @@ -1914,46 +1913,45 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) occurs_left = occurs = realize_value (&t->occurs, c); if (occurs <= 0) { - tmsg (SE, RPD_ERR, _("Invalid value %d for OCCURS."), occurs); + rpd_msg (SE, _("Invalid value %d for OCCURS."), occurs); return TRNS_NEXT_CASE; } starts_beg = realize_value (&t->starts_beg, c); if (starts_beg <= 0) { - tmsg (SE, RPD_ERR, _("Beginning column for STARTS (%d) must be " - "at least 1."), - starts_beg); + rpd_msg (SE, _("Beginning column for STARTS (%d) must be at least 1."), + starts_beg); return TRNS_NEXT_CASE; } starts_end = realize_value (&t->starts_end, c); if (starts_end < starts_beg) { - tmsg (SE, RPD_ERR, _("Ending column for STARTS (%d) is less than " - "beginning column (%d)."), - starts_end, starts_beg); + rpd_msg (SE, _("Ending column for STARTS (%d) is less than " + "beginning column (%d)."), + starts_end, starts_beg); skip_first_record = 1; } length = realize_value (&t->length, c); if (length < 0) { - tmsg (SE, RPD_ERR, _("Invalid value %d for LENGTH."), length); + rpd_msg (SE, _("Invalid value %d for LENGTH."), length); length = 1; occurs = occurs_left = 1; } cont_beg = realize_value (&t->cont_beg, c); if (cont_beg < 0) { - tmsg (SE, RPD_ERR, _("Beginning column for CONTINUED (%d) must be " - "at least 1."), - cont_beg); + rpd_msg (SE, _("Beginning column for CONTINUED (%d) must be " + "at least 1."), + cont_beg); return TRNS_DROP_CASE; } cont_end = realize_value (&t->cont_end, c); if (cont_end < cont_beg) { - tmsg (SE, RPD_ERR, _("Ending column for CONTINUED (%d) is less than " - "beginning column (%d)."), - cont_end, cont_beg); + rpd_msg (SE, _("Ending column for CONTINUED (%d) is less than " + "beginning column (%d)."), + cont_end, cont_beg); return TRNS_DROP_CASE; } @@ -1982,11 +1980,11 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) continuation records. */ if (occurs_left > 0 && cont_beg == 0) { - tmsg (SE, RPD_ERR, - _("Number of repetitions specified on OCCURS (%d) " - "exceed number of repetitions available in " - "space on STARTS (%d), and CONTINUED not specified."), - occurs, (starts_end - starts_beg + 1) / length); + rpd_msg (SE, + _("Number of repetitions specified on OCCURS (%d) " + "exceed number of repetitions available in " + "space on STARTS (%d), and CONTINUED not specified."), + occurs, (starts_end - starts_beg + 1) / length); return TRNS_DROP_CASE; } @@ -2000,10 +1998,10 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) /* Read in another record. */ if (dfm_eof (t->reader)) { - tmsg (SE, RPD_ERR, - _("Unexpected end of file with %d repetitions " - "remaining out of %d."), - occurs_left, occurs); + rpd_msg (SE, + _("Unexpected end of file with %d repetitions " + "remaining out of %d."), + occurs_left, occurs); return TRNS_DROP_CASE; } dfm_expand_tabs (t->reader); @@ -2060,3 +2058,27 @@ repeating_data_set_write_case (struct transformation *trns_, t->write_case = write_case; t->wc_data = wc_data; } + +/* Reports a message in CLASS with the given FORMAT as text, + prefixing the message with "REPEATING DATA: " to make the + cause clear. */ +static void +rpd_msg (enum msg_class class, const char *format, ...) +{ + struct error e; + va_list args; + struct string text; + + ds_create (&text, "REPEATING DATA: "); + va_start (args, 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); + + err_msg (&e); +} diff --git a/src/language/expressions/ChangeLog b/src/language/expressions/ChangeLog index 4a96aeb9..5b04f9ff 100644 --- a/src/language/expressions/ChangeLog +++ b/src/language/expressions/ChangeLog @@ -1,3 +1,12 @@ +Sun Apr 23 22:06:45 2006 Ben Pfaff + + Continue reforming error message support. In this phase, get rid + of message "titles" and put the message text in `struct error'. + Now `struct error' encapsulates a message more properly. + + * helpers.c: (expr_error) Use err_msg() instead of err_vmsg(). + Format message ourselves. + Thu Mar 2 08:40:33 WST 2006 John Darrington * Moved files from src directory diff --git a/src/language/expressions/helpers.c b/src/language/expressions/helpers.c index 9d0d18ca..3e28d8fe 100644 --- a/src/language/expressions/helpers.c +++ b/src/language/expressions/helpers.c @@ -18,11 +18,11 @@ expr_error (void *aux UNUSED, const char *format, ...) e.category = MSG_SYNTAX; e.severity = MSG_ERROR; err_location (&e.where); - e.title = NULL; - va_start (args, format); - err_vmsg (&e, format, args); + e.text = xvasprintf (format, args); va_end (args); + + err_msg (&e); } double diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index 88955ac4..2e2cad22 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,12 @@ +Sun Apr 23 22:07:06 2006 Ben Pfaff + + Continue reforming error message support. In this phase, get rid + of message "titles" and put the message text in `struct error'. + Now `struct error' encapsulates a message more properly. + + * message.h: (struct error) Remove `title' member. Add `text' + member. + Sun Apr 16 20:43:35 2006 Ben Pfaff Continue reforming error message support. In this phase, we diff --git a/src/libpspp/message.h b/src/libpspp/message.h index 9dae1e40..56ded21c 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -81,7 +81,7 @@ struct error 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. */ + char *text; /* Error text. */ }; /* Number of errors, warnings reported. */ @@ -96,11 +96,10 @@ extern int err_already_flagged; /* Nonnegative verbosity level. Higher value == more verbose. */ extern int err_verbosity; -/* Functions. */ +/* Emitting messages. */ void msg (enum msg_class, const char *format, ...) PRINTF_FORMAT (2, 3); -void tmsg (enum msg_class, const char *title, const char *format, ...) - PRINTF_FORMAT (3, 4); +void err_msg (const struct error *); void verbose_msg (int level, const char *format, ...) PRINTF_FORMAT (2, 3); @@ -114,7 +113,6 @@ void err_location (struct file_locator *); void err_set_command_name (const char *); void err_done (void); void err_check_count (void); -void err_vmsg (const struct error *, const char *, va_list); /* Used in panic situations only */ void request_bug_report_and_abort(const char *msg ); diff --git a/src/message.c b/src/message.c index 8c4c4473..35debc7f 100644 --- a/src/message.c +++ b/src/message.c @@ -48,24 +48,6 @@ static char *command_name; /* Public functions. */ -/* Writes error message in CLASS, with title TITLE and text FORMAT, - formatted with printf, to the standard places. */ -void -tmsg (enum msg_class class, const char *title, const char *format, ...) -{ - struct error e; - va_list args; - - e.category = msg_class_to_category (class); - e.severity = msg_class_to_severity (class); - err_location (&e.where); - e.title = title; - - va_start (args, format); - err_vmsg (&e, format, args); - va_end (args); -} - /* Writes error message in CLASS, with text FORMAT, formatted with printf, to the standard places. */ void @@ -77,11 +59,11 @@ msg (enum msg_class class, const char *format, ...) e.category = msg_class_to_category (class); e.severity = msg_class_to_severity (class); err_location (&e.where); - e.title = NULL; - va_start (args, format); - err_vmsg (&e, format, args); + e.text = xvasprintf (format, args); va_end (args); + + err_msg (&e); } /* Writes MESSAGE formatted with printf, to stderr, if the @@ -143,8 +125,10 @@ err_done (void) readln_uninitialize(); } +/* Emits E as an error message. + Frees `text' member in E. */ void -err_vmsg (const struct error *e, const char *format, va_list args) +err_msg (const struct error *e) { struct category { @@ -193,16 +177,14 @@ err_vmsg (const struct error *e, const char *format, va_list args) if (category->show_command_name && command_name != NULL) ds_printf (&msg, "%s: ", command_name); - if (e->title) - ds_puts (&msg, e->title); - - ds_vprintf (&msg, format, args); + ds_puts (&msg, e->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); ds_destroy (&msg); + free (e->text); } /* Private functions. */ diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index c60dee15..6692d9aa 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,12 @@ +Sun Apr 23 22:07:49 2006 Ben Pfaff + + Continue reforming error message support. In this phase, get rid + of message "titles" and put the message text in `struct error'. + Now `struct error' encapsulates a message more properly. + + * message-dialog.c: (err_vmsg) Rename err_msg(). Updated + interface. + Sun Apr 16 20:45:35 2006 Ben Pfaff Continue reforming error message support. In this phase, we diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index c5928d35..0af76936 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -113,10 +113,10 @@ msg(enum msg_class klass, const char *fmt, ...) void -err_vmsg (const struct error *e, const char *format, va_list args) +err_msg (const struct error *e) { vmsg(msg_class_from_category_and_severity (e->category, e->severity), - format, args); + "%s", e->text); }