+/** Report an error message.
+ *
+ * \param loc the location, defaulting to the current file,
+ * or the program name.
+ * \param prefix put before the message (e.g., "warning").
+ * \param message the error message, a printf format string. Iff it
+ * ends with ": ", then no trailing newline is printed,
+ * and the caller should print the remaining
+ * newline-terminated message to stderr.
+ * \param args the arguments of the format string.
+ */
+static
+void
+error_message (location *loc,
+ const char *prefix,
+ const char *message, va_list args)
+{
+ unsigned pos = 0;
+
+ if (loc)
+ pos += location_print (stderr, *loc);
+ else
+ pos += fprintf(stderr, "%s", current_file ? current_file : program_name);
+ pos += fprintf(stderr, ": ");
+
+ if (indent_ptr)
+ {
+ if (!*indent_ptr)
+ *indent_ptr = pos;
+ else if (*indent_ptr > pos)
+ fprintf (stderr, "%*s", *indent_ptr - pos, "");
+ indent_ptr = 0;
+ }
+
+ if (prefix)
+ fprintf (stderr, "%s: ", prefix);
+
+ vfprintf (stderr, message, args);
+ {
+ size_t l = strlen (message);
+ if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ')
+ {
+ putc ('\n', stderr);
+ fflush (stderr);
+ if (loc && feature_flag & feature_caret)
+ location_caret (stderr, *loc);
+ }
+ }
+ fflush (stderr);
+}
+
+/** Wrap error_message() with varargs handling. */
+#define ERROR_MESSAGE(Loc, Prefix, Message) \
+{ \
+ va_list args; \
+ va_start (args, Message); \
+ error_message (Loc, Prefix, Message, args); \
+ va_end (args); \
+}