From 547d9160972dc6e986e1b4b1f29517f9c072410a Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 22 Aug 2010 12:36:37 +0200 Subject: [PATCH] SET MXWARNS = 0 to be interpreted as unlimited. This change introduces a special meaning to the value of zero for the MXWARNS settings. When a zero value is set. A single warning will be emitted informing the user that the setting is in effect. Thereafter no warning will be emitted. All warning situations will be ignored. --- doc/utilities.texi | 6 ++- src/data/settings.c | 22 +++++++++- src/libpspp/message.c | 21 ++++++++-- src/libpspp/message.h | 8 ++-- tests/language/utilities/set.at | 72 +++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 8 deletions(-) diff --git a/doc/utilities.texi b/doc/utilities.texi index fabec248b6..6b248e621f 100644 --- a/doc/utilities.texi +++ b/doc/utilities.texi @@ -525,7 +525,11 @@ command file. The default is 50. @item MXWARNS The maximum number of warnings + errors before PSPP halts processing the -current command file. The default is 100. +current command file. +The special value of zero means that all warning situations should be ignored. +No warnings will be issued, except a single initial warning advising the user +that warnings will not be given. +The default value is 100. @item PROMPT The command prompt. The default is @samp{PSPP> }. diff --git a/src/data/settings.c b/src/data/settings.c index d95e3a1407..10b20f8a35 100644 --- a/src/data/settings.c +++ b/src/data/settings.c @@ -364,11 +364,31 @@ settings_get_max_messages (enum msg_severity severity) /* Sets the maximum number of messages to show of the given SEVERITY before aborting to MAX. (The value for MSG_S_WARNING is interpreted as maximum - number of warnings and errors combined.) */ + number of warnings and errors combined.) In addition, in the case of + warnings the special value of zero indicates that no warnings are to be + issued. +*/ void settings_set_max_messages (enum msg_severity severity, int max) { assert (severity < MSG_N_SEVERITIES); + + if (severity == MSG_S_WARNING) + { + if ( max == 0) + { + msg (MW, + _("MXWARNS set to zero. No further warnings will be given even when potentially problematic situations are encountered.")); + msg_ui_disable_warnings (true); + } + else if ( the_settings.max_messages [MSG_S_WARNING] == 0) + { + msg_ui_disable_warnings (false); + the_settings.max_messages[MSG_S_WARNING] = max; + msg (MW, _("Warnings re-enabled. %d warnings will be issued before aborting syntax processing."), max); + } + } + the_settings.max_messages[severity] = max; } diff --git a/src/libpspp/message.c b/src/libpspp/message.c index 0d226a1732..4ba8a8f7ac 100644 --- a/src/libpspp/message.c +++ b/src/libpspp/message.c @@ -156,6 +156,9 @@ static bool too_many_errors; /* True after the maximum number of notes has been exceeded. */ static bool too_many_notes; +/* True iff warnings have been explicitly disabled (MXWARNS = 0) */ +static bool warnings_off = false; + /* Checks whether we've had so many errors that it's time to quit processing this syntax file. */ bool @@ -164,6 +167,13 @@ msg_ui_too_many_errors (void) return too_many_errors; } +void +msg_ui_disable_warnings (bool x) +{ + warnings_off = x; +} + + void msg_ui_reset_counts (void) { @@ -195,12 +205,17 @@ submit_note (char *s) free (s); } + + static void process_msg (const struct msg *m) { int n_msgs, max_msgs; - if (too_many_errors || (too_many_notes && m->severity == MSG_S_NOTE)) + + if (too_many_errors + || (too_many_notes && m->severity == MSG_S_NOTE) + || (warnings_off && m->severity == MSG_S_WARNING) ) return; msg_handler (m); @@ -223,10 +238,10 @@ process_msg (const struct msg *m) { too_many_errors = true; if (m->severity == MSG_S_WARNING) - submit_note (xasprintf (_("Warnings (%d) exceed limit (%d)."), + submit_note (xasprintf (_("Warnings (%d) exceed limit (%d). Syntax processing will be halted."), n_msgs, max_msgs)); else - submit_note (xasprintf (_("Errors (%d) exceed limit (%d)."), + submit_note (xasprintf (_("Errors (%d) exceed limit (%d). Syntax processing will be halted."), n_msgs, max_msgs)); } } diff --git a/src/libpspp/message.h b/src/libpspp/message.h index cf297ae324..bdd27a5e72 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -108,12 +108,14 @@ void msg_disable (void); void msg_push_msg_locator (const struct msg_locator *); void msg_pop_msg_locator (const struct msg_locator *); +bool msg_ui_too_many_errors (void); +void msg_ui_reset_counts (void); +bool msg_ui_any_errors (void); +void msg_ui_disable_warnings (bool); + /* Used in panic situations only. */ void request_bug_report_and_abort (const char *msg) NO_RETURN; -bool msg_ui_too_many_errors (void); -void msg_ui_reset_counts (void); -bool msg_ui_any_errors (void); #endif /* message.h */ diff --git a/tests/language/utilities/set.at b/tests/language/utilities/set.at index 851642ebdc..e1b92573f3 100644 --- a/tests/language/utilities/set.at +++ b/tests/language/utilities/set.at @@ -20,3 +20,75 @@ Variable,N,Mean,Std Dev,Minimum,Maximum x,3,2.00,1.00,1.00,3.00 ]) AT_CLEANUP + + + +AT_SETUP([SET MXWARNS]) +dnl Make sure that syntax processing stops and that +dnl a warning is issued when the MXWARNS figure is +dnl exceeded. +AT_DATA([set.pspp], [dnl +set mxwarns=2. +data list notable list /x (f8.2) y (f8.2). +begin data +1 2 +3 r +5 x +q 8 +9 9 +3 x +w w +end data. + +comment The following line should not be executed. +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:6: warning: (column 3, F field) Field contents are not numeric." + +"set.pspp:7: warning: (column 1, F field) Field contents are not numeric." + +note: Warnings (3) exceed limit (2). Syntax processing will be halted. +]) + +AT_CLEANUP + + + + +AT_SETUP([SET MXWARNS special case zero]) +dnl Make sure that MXWARNS interprets zero as infinity. +AT_DATA([mxwarns.pspp], [dnl +set mxwarns=0. +data list notable list /x (f8.2) y (f8.2) z *. +begin data +1 2 3 +3 r 3 +5 x 3 +q 8 4 +9 9 4 +3 x 4 +w w 4 +end data. + +list. +]) + +AT_CHECK([pspp -O format=csv mxwarns.pspp], [0], +[warning: MXWARNS set to zero. No further warnings will be given even when potentially problematic situations are encountered. + +Table: Data List +x,y,z +1.00,2.00,3.00 +3.00,. ,3.00 +5.00,. ,3.00 +. ,8.00,4.00 +9.00,9.00,4.00 +3.00,. ,4.00 +. ,. ,4.00 +]) + +AT_CLEANUP -- 2.30.2