diff options
-rw-r--r-- | src/error.h | 10 | ||||
-rw-r--r-- | src/pyinterp.cc | 4 | ||||
-rw-r--r-- | src/textual.cc | 20 | ||||
-rw-r--r-- | src/utils.cc | 6 |
4 files changed, 19 insertions, 21 deletions
diff --git a/src/error.h b/src/error.h index 1b4c7e12..45c0cc68 100644 --- a/src/error.h +++ b/src/error.h @@ -64,6 +64,16 @@ inline void throw_func(const string& message) { _desc_accum.clear(), \ throw_func<cls>(_desc_buffer.str())) +inline void warning_func(const string& message) { + std::cerr << "Warning: " << message << std::endl; + _desc_buffer.str(""); +} + +#define warning_(msg) \ + ((_desc_buffer << ACCUM(_desc_accum << msg)), \ + _desc_accum.clear(), \ + warning_func(_desc_buffer.str())) + extern straccstream _ctxt_accum; extern std::ostringstream _ctxt_buffer; diff --git a/src/pyinterp.cc b/src/pyinterp.cc index ad6f0e07..7125a18b 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -152,9 +152,7 @@ void python_interpreter_t::initialize() } } if (! path_initialized) - std::cerr - << _("Warning: Ledger failed to find 'ledger/__init__.py' on the PYTHONPATH") - << std::endl; + warning_(_("Ledger failed to find 'ledger/__init__.py' on the PYTHONPATH")); } catch (const error_already_set&) { PyErr_Print(); diff --git a/src/textual.cc b/src/textual.cc index da686ec9..fb03f04d 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -810,13 +810,9 @@ post_t * instance_t::parse_post(char * line, post->account = account->find_account(name); if (honor_strict && strict && ! post->account->known) { - if (post->_state == item_t::UNCLEARED) { - straccstream accum; - std::cerr - << ACCUM(accum << _("Warning: \"%1\", line %2: Unknown account '%3'") - << pathname << linenum << post->account->fullname()) - << std::endl; - } + if (post->_state == item_t::UNCLEARED) + warning_(_("\"%1\", line %2: Unknown account '%3'") + << pathname << linenum << post->account->fullname()); post->account->known = true; } @@ -840,13 +836,9 @@ post_t * instance_t::parse_post(char * line, if (! post->amount.is_null() && honor_strict && strict && post->amount.has_commodity() && ! post->amount.commodity().has_flags(COMMODITY_KNOWN)) { - if (post->_state == item_t::UNCLEARED) { - straccstream accum; - std::cerr - << ACCUM(accum << _("Warning: \"%1\", line %2: Unknown commodity '%3'") - << pathname << linenum << post->amount.commodity()) - << std::endl; - } + if (post->_state == item_t::UNCLEARED) + warning_(_("\"%1\", line %2: Unknown commodity '%3'") + << pathname << linenum << post->amount.commodity()); post->amount.commodity().add_flags(COMMODITY_KNOWN); } diff --git a/src/utils.cc b/src/utils.cc index 70c6d5f8..0e208b45 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -300,8 +300,7 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size) live_objects_map::iterator i = live_objects->find(ptr); if (i == live_objects->end()) { - std::cerr << "Attempting to delete " << ptr << " a non-living " << cls_name - << std::endl; + warning_(_("Attempting to delete %1 a non-living %2") << ptr << cls_name); memory_tracing_active = true; return; } @@ -316,8 +315,7 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size) object_count_map::iterator k = live_object_count->find(cls_name); if (k == live_object_count->end()) { - std::cerr << "Failed to find " << cls_name << " in live object counts" - << std::endl; + warning_(_("Failed to find %1 in live object counts") << cls_name); memory_tracing_active = true; return; } |