X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Fwarn.cc;h=f17a36483fa4b91255309f5509bbcf5a160b10b2;hb=97a0169312a260933246ab224e4f8b0969871dd5;hp=af16f20bebe0dd347253e775493fe9b61bd82ba6;hpb=1ecdd56060e34a00b2be6b38029b286a601ea6f8;p=lilypond.git diff --git a/flower/warn.cc b/flower/warn.cc index af16f20beb..f17a36483f 100644 --- a/flower/warn.cc +++ b/flower/warn.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1997--2011 Han-Wen Nienhuys + Copyright (C) 1997--2015 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ using namespace std; /* Define the loglevel (default is INFO) */ int loglevel = LOGLEVEL_INFO; +bool warning_as_error = false; bool is_loglevel (int level) @@ -85,7 +86,7 @@ set_loglevel (string level) set_loglevel (l); else { - non_fatal_error (_f ("unknown log level `%s', using default (INFO)", + non_fatal_error (_f ("unknown log level `%s', using default (INFO)", level)); set_loglevel (LOGLEVEL_INFO); } @@ -98,46 +99,46 @@ set_loglevel (string level) * expected warnings again. */ vector expected_warnings; -void expect_warning (string msg) +void expect_warning (const string &msg) { expected_warnings.push_back (msg); } void check_expected_warnings () { - if (expected_warnings.size () > 0) + if (expected_warnings.size () > 0) { /* Some expected warning was not triggered, so print out a warning. */ - string msg = _f ("%d expected warning(s) not encountered: ", + string msg = _f ("%d expected warning(s) not encountered: ", expected_warnings.size ()); - for (vsize i = 0; i< expected_warnings.size (); i++) - msg += "\n " + expected_warnings[i]; - + for (vsize i = 0; i < expected_warnings.size (); i++) + msg += "\n " + expected_warnings[i]; + warning (msg); } expected_warnings.clear (); } -bool is_expected (string s) +bool is_expected (const string &s) { bool expected = false; - for (vsize i = 0; i< expected_warnings.size (); i++) + for (vsize i = 0; i < expected_warnings.size (); i++) { // Compare the msg with the suppressed string; If the beginning matches, // i.e. the msg can have additional content AFTER the full (exact) // suppressed message, suppress the warning. // This is needed for the Input class, where the message contains // the input file contents after the real message. - if (s.compare (0, expected_warnings[i].size (), expected_warnings[i]) == 0 ) { - expected = true; - expected_warnings.erase (expected_warnings.begin () + i); - break; - } + if (s.compare (0, expected_warnings[i].size (), expected_warnings[i]) == 0) + { + expected = true; + expected_warnings.erase (expected_warnings.begin () + i); + break; + } } return expected; } - /** * Helper functions: print_message_part (no newline prepended) * print_message (always starts on a new line) @@ -150,7 +151,7 @@ static bool message_newline = true; if newline is true, start the message on a new line. */ void -print_message (int level, string location, string s, bool newline) +print_message (int level, const string &location, string s, bool newline) { /* Only print the message if the current loglevel allows it: */ if (!is_loglevel (level)) @@ -170,7 +171,6 @@ print_message (int level, string location, string s, bool newline) message_newline = s[s.length () - 1] == '\n'; } - /** The actual output functions to be called in lilypond code. * Sorted in descending order of importance (errors, warnings, progress, info, * debug). Each prints a message on a separate line. @@ -178,7 +178,7 @@ print_message (int level, string location, string s, bool newline) /* Display a fatal error message. Also exits lilypond. */ void -error (string s, string location) +error (string s, const string &location) { print_message (LOG_ERROR, location, _f ("fatal error: %s", s) + "\n"); exit (1); @@ -186,56 +186,60 @@ error (string s, string location) /* Display a severe programming error message, but don't exit. */ void -programming_error (string s, string location) +programming_error (const string &s, const string &location) { - if (is_expected (s)) { + if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed programming error: %s", s) + "\n"); - } else { - print_message (LOG_ERROR, location, _f ("programming error: %s", s) + "\n"); - print_message (LOG_ERROR, location, _ ("continuing, cross fingers") + "\n"); - } + else if (warning_as_error) + error (s, location); + else + { + print_message (LOG_ERROR, location, _f ("programming error: %s", s) + "\n"); + print_message (LOG_ERROR, location, _ ("continuing, cross fingers") + "\n"); + } } /* Display a non-fatal error message, don't exit. */ void -non_fatal_error (string s, string location) +non_fatal_error (const string &s, const string &location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed error: %s", s) + "\n"); - else { + else if (warning_as_error) + error (s, location); + else print_message (LOG_ERROR, location, _f ("error: %s", s) + "\n"); - } } /* Display a warning message. */ void -warning (string s, string location) +warning (const string &s, const string &location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed warning: %s", s) + "\n"); - else { - // TODO: Add warning-as-error check here + else if (warning_as_error) + error (s, location); + else print_message (LOG_WARN, location, _f ("warning: %s", s) + "\n"); - } } /* Display a success message. */ void -basic_progress (string s, string location) +basic_progress (const string &s, const string &location) { print_message (LOG_BASIC, location, s + "\n", true); } /* Display information about the progress. */ void -progress_indication (string s, bool newline, string location) +progress_indication (const string &s, bool newline, const string &location) { print_message (LOG_PROGRESS, location, s, newline); } /* Display a single info message. */ void -message (string s, bool newline, string location) +message (const string &s, bool newline, const string &location) { // Use the progress loglevel for all normal messages (including progress msg) print_message (LOG_INFO, location, s, newline); @@ -243,7 +247,7 @@ message (string s, bool newline, string location) /* Display a debug information, not necessarily on a new line. */ void -debug_output (string s, bool newline, string location) +debug_output (const string &s, bool newline, const string &location) { print_message (LOG_DEBUG, location, s, newline); }