warnings: refactoring

The code here was too confusing, this seems more natural.

* src/complain.c (error_message): Move the indentation check and the category
output to complains. Also, no longer take a 'warnings' argument.
(complains): Factor calls to error_message.

Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
This commit is contained in:
Theophile Ranquet
2012-10-01 15:01:02 +00:00
committed by Akim Demaille
parent 46b7d74cb5
commit a686f6cdc0

View File

@@ -84,7 +84,6 @@ void
error_message (const location *loc, warnings flags, const char *prefix, error_message (const location *loc, warnings flags, const char *prefix,
const char *message, va_list args) const char *message, va_list args)
{ {
(void) flags;
unsigned pos = 0; unsigned pos = 0;
if (loc) if (loc)
@@ -95,6 +94,8 @@ error_message (const location *loc, warnings flags, const char *prefix,
if (indent_ptr) if (indent_ptr)
{ {
if (*indent_ptr)
prefix = NULL;
if (!*indent_ptr) if (!*indent_ptr)
*indent_ptr = pos; *indent_ptr = pos;
else if (*indent_ptr > pos) else if (*indent_ptr > pos)
@@ -124,22 +125,17 @@ static inline void
complains (const location *loc, warnings flags, const char *message, complains (const location *loc, warnings flags, const char *message,
va_list args) va_list args)
{
if (flags & fatal)
{
error_message (loc, fatal, _("fatal error"), message, args);
exit (EXIT_FAILURE);
}
else if (flags & (complaint | warnings_flag | silent))
{ {
const char* prefix = const char* prefix =
flags & (errors_flag | complaint) ? _("error") : _("warning"); flags & fatal ? _("fatal error")
if (flags & (complaint | errors_flag)) : flags & (errors_flag | complaint) ? _("error")
complaint_issued = true; : _("warning");
error_message (loc, flags,
indent_ptr && *indent_ptr ? NULL : prefix, complaint_issued |= flags & (complaint | errors_flag);
message, args); if (flags & (warnings_flag | silent | fatal | complaint))
} error_message (loc, flags, prefix, message, args);
if (flags & fatal)
exit (EXIT_FAILURE);
} }
void void