Added a warning_() macro

This commit is contained in:
John Wiegley 2009-02-26 05:30:48 -04:00
parent 87ec7bc34a
commit badea00584
4 changed files with 19 additions and 21 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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);
}

View file

@ -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;
}