+/* Frees a message created by msg_dup().
+
+ (Messages not created by msg_dup(), as well as their where.file_name
+ members, are typically not dynamically allocated, so this function should
+ not be used to destroy them.) */
+void
+msg_destroy (struct msg *m)
+{
+ free (m->where.file_name);
+ free (m->text);
+ free (m);
+}
+
+char *
+msg_to_string (const struct msg *m, const char *command_name)
+{
+ const char *label;
+ struct string s;
+
+ ds_init_empty (&s);
+
+ if (m->category != MSG_C_GENERAL
+ && (m->where.file_name
+ || m->where.line_number > 0
+ || m->where.first_column > 0))
+ {
+ if (m->where.file_name)
+ ds_put_format (&s, "%s", m->where.file_name);
+ if (m->where.line_number > 0)
+ {
+ if (!ds_is_empty (&s))
+ ds_put_char (&s, ':');
+ ds_put_format (&s, "%d", m->where.line_number);
+ }
+ if (m->where.first_column > 0)
+ {
+ ds_put_format (&s, ".%d", m->where.first_column);
+ if (m->where.last_column > m->where.first_column + 1)
+ ds_put_format (&s, "-%d", m->where.last_column - 1);
+ }
+ ds_put_cstr (&s, ": ");
+ }
+
+ switch (m->severity)
+ {
+ case MSG_S_ERROR:
+ label = _("error");
+ break;
+ case MSG_S_WARNING:
+ label = _("warning");
+ break;
+ case MSG_S_NOTE:
+ default:
+ label = _("note");
+ break;
+ }
+ ds_put_format (&s, "%s: ", label);
+
+ if (m->category == MSG_C_SYNTAX && command_name != NULL)
+ ds_put_format (&s, "%s: ", command_name);
+
+ ds_put_cstr (&s, m->text);
+
+ return ds_cstr (&s);
+}
+\f
+
+/* Number of messages reported, by severity level. */
+static int counts[MSG_N_SEVERITIES];
+
+/* True after the maximum number of errors or warnings has been exceeded. */
+static bool too_many_errors;
+
+/* True after the maximum number of notes has been exceeded. */
+static bool too_many_notes;
+
+/* True iff warnings have been explicitly disabled (MXWARNS = 0) */
+static bool warnings_off = false;
+
+/* Checks whether we've had so many errors that it's time to quit
+ processing this syntax file. */
+bool
+msg_ui_too_many_errors (void)
+{
+ return too_many_errors;
+}
+