From: Ben Pfaff Date: Sun, 19 Sep 2010 18:07:09 +0000 (-0700) Subject: message: Add column range to struct msg_locator. X-Git-Tag: v0.7.6~186 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d34380bb2fddca820a6f414564738cc2f70afc9;p=pspp-builds.git message: Add column range to struct msg_locator. data_in() can specify a range of columns for the messages that it outputs, but until now these were not output in the format specified by the GNU Coding Standards. This commit fixes that. --- diff --git a/src/data/data-in.c b/src/data/data-in.c index 480d335a..35a725d5 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1187,15 +1187,6 @@ vdata_warning (const struct data_in *i, const char *format, va_list args) ds_init_empty (&text); ds_put_char (&text, '('); - if (i->first_column != 0) - { - if (i->first_column == i->last_column - 1) - ds_put_format (&text, _("column %d"), i->first_column); - else - ds_put_format (&text, _("columns %d-%d"), - i->first_column, i->last_column - 1); - ds_put_cstr (&text, ", "); - } ds_put_format (&text, _("%s field) "), fmt_name (i->format)); ds_put_vformat (&text, format, args); @@ -1204,6 +1195,8 @@ vdata_warning (const struct data_in *i, const char *format, va_list args) m.text = ds_cstr (&text); m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = i->first_column; + m.where.last_column = i->last_column; msg_emit (&m); } diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index f3b78b15..adf177be 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -105,6 +105,8 @@ error (struct pfm_reader *r, const char *msg, ...) m.severity = MSG_S_ERROR; m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = 0; + m.where.last_column = 0; m.text = ds_cstr (&text); msg_emit (&m); @@ -134,6 +136,8 @@ warning (struct pfm_reader *r, const char *msg, ...) m.severity = MSG_S_WARNING; m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = 0; + m.where.last_column = 0; m.text = ds_cstr (&text); msg_emit (&m); diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 5ad5eabc..36a2cb7a 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -2298,6 +2298,8 @@ sys_msg (struct sfm_reader *r, int class, const char *format, va_list args) m.severity = msg_class_to_severity (class); m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = 0; + m.where.last_column = 0; m.text = ds_cstr (&text); msg_emit (&m); diff --git a/src/language/expressions/helpers.c b/src/language/expressions/helpers.c index 2d707e99..08f787fe 100644 --- a/src/language/expressions/helpers.c +++ b/src/language/expressions/helpers.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,6 +36,8 @@ expr_error (void *aux UNUSED, const char *format, ...) m.text = xvasprintf (format, args); m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = 0; + m.where.last_column = 0; va_end (args); msg_emit (&m); diff --git a/src/libpspp/message.c b/src/libpspp/message.c index e0f9bf17..8bd6af95 100644 --- a/src/libpspp/message.c +++ b/src/libpspp/message.c @@ -59,6 +59,8 @@ msg (enum msg_class class, const char *format, ...) m.text = xvasprintf (format, args); m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = 0; + m.where.last_column = 0; va_end (args); msg_emit (&m); @@ -116,13 +118,25 @@ msg_to_string (const struct msg *m, const char *command_name) ds_init_empty (&s); if (m->category != MSG_C_GENERAL - && (m->where.file_name || m->where.line_number != -1)) + && (m->where.file_name + || m->where.line_number > 0 + || m->where.first_column > 0)) { if (m->where.file_name) - ds_put_format (&s, "%s:", m->where.file_name); + ds_put_format (&s, "%s", m->where.file_name); if (m->where.line_number > 0) - ds_put_format (&s, "%d:", m->where.line_number); - ds_put_char (&s, ' '); + { + if (!ds_is_empty (&s)) + ds_put_char (&s, ':'); + ds_put_format (&s, "%d", m->where.line_number); + } + if (m->where.first_column > 0) + { + ds_put_format (&s, ".%d", m->where.first_column); + if (m->where.last_column > m->where.first_column + 1) + ds_put_format (&s, "-%d", m->where.last_column - 1); + } + ds_put_cstr (&s, ": "); } switch (m->severity) @@ -202,6 +216,8 @@ submit_note (char *s) m.severity = MSG_S_NOTE; m.where.file_name = NULL; m.where.line_number = 0; + m.where.first_column = 0; + m.where.last_column = 0; m.text = s; msg_handler (&m); free (s); @@ -256,7 +272,13 @@ void msg_emit (struct msg *m) { if ( s_stream ) - get_msg_location (s_stream, &m->where); + { + struct msg_locator loc; + + get_msg_location (s_stream, &loc); + m->where.file_name = loc.file_name; + m->where.line_number = loc.line_number; + } else { m->where.file_name = NULL; diff --git a/src/libpspp/message.h b/src/libpspp/message.h index 6cdf6e87..7c111017 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -72,6 +72,8 @@ struct msg_locator { char *file_name; /* File name (NULL if none). */ int line_number; /* Line number (0 if none). */ + int first_column; /* 1-based column number (0 if none). */ + int last_column; /* 1-based exclusive last column (0 if none). */ }; /* A message. */ diff --git a/tests/language/data-io/data-list.at b/tests/language/data-io/data-list.at index 7683b9c5..544b020a 100644 --- a/tests/language/data-io/data-list.at +++ b/tests/language/data-io/data-list.at @@ -49,7 +49,7 @@ B,F8.0 C,F8.0 D,F8.0 -"data-list.pspp:3: warning: (columns 9-13, F field) Number followed by garbage." +data-list.pspp:3.9-13: warning: Data for variable D is not valid as format F: Number followed by garbage. Table: Data List A,B,C,D @@ -80,7 +80,7 @@ end data. list. ]) AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl -"data-list.pspp:4: warning: (column 6, F field) Field contents are not numeric." +data-list.pspp:4.6: warning: Data for variable D is not valid as format F: Field contents are not numeric. Table: Data List A,B,C,D @@ -160,9 +160,9 @@ end data. list. ]) AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl -"data-list.pspp:8: warning: (columns 1-3, F field) Field contents are not numeric." +data-list.pspp:8.1-3: warning: Data for variable count is not valid as format F: Field contents are not numeric. -"data-list.pspp:11: warning: (columns 1-3, F field) Field contents are not numeric." +data-list.pspp:11.1-3: warning: Data for variable count is not valid as format F: Field contents are not numeric. Table: Data List start,end,count diff --git a/tests/language/utilities/set.at b/tests/language/utilities/set.at index e84b44d9..b281ae4e 100644 --- a/tests/language/utilities/set.at +++ b/tests/language/utilities/set.at @@ -45,11 +45,11 @@ list. ]) AT_CHECK([pspp -O format=csv set.pspp], [0], [dnl -"set.pspp:5: warning: (column 3, F field) Field contents are not numeric." +set.pspp:5.3: warning: Data for variable y is not valid as format F: Field contents are not numeric. -"set.pspp:6: warning: (column 3, F field) Field contents are not numeric." +set.pspp:6.3: warning: Data for variable y is not valid as format F: Field contents are not numeric. -"set.pspp:7: warning: (column 1, F field) Field contents are not numeric." +set.pspp:7.1: warning: Data for variable x is not valid as format F: Field contents are not numeric. note: Warnings (3) exceed limit (2). Syntax processing will be halted. ])