+ return _("note");
+ }
+}
+
+/* Duplicate a message */
+struct msg *
+msg_dup (const struct msg *src)
+{
+ struct msg_stack **ms = xmalloc (src->n_stack * sizeof *ms);
+ for (size_t i = 0; i < src->n_stack; i++)
+ ms[i] = msg_stack_dup (src->stack[i]);
+
+ struct msg *dst = xmalloc (sizeof *dst);
+ *dst = (struct msg) {
+ .category = src->category,
+ .severity = src->severity,
+ .stack = ms,
+ .n_stack = src->n_stack,
+ .location = msg_location_dup (src->location),
+ .command_name = xstrdup_if_nonnull (src->command_name),
+ .text = xstrdup (src->text),
+ };
+ return dst;
+}
+
+/* Frees a message created by msg_dup().
+
+ (Messages not created by msg_dup(), as well as their file_name
+ members, are typically not dynamically allocated, so this function should
+ not be used to destroy them.) */
+void
+msg_destroy (struct msg *m)
+{
+ if (m)
+ {
+ for (size_t i = 0; i < m->n_stack; i++)
+ msg_stack_destroy (m->stack[i]);
+ free (m->stack);
+ msg_location_destroy (m->location);
+ free (m->text);
+ free (m->command_name);
+ free (m);
+ }
+}
+
+char *
+msg_to_string (const struct msg *m)
+{
+ struct string s;
+
+ ds_init_empty (&s);
+
+ for (size_t i = 0; i < m->n_stack; i++)
+ {
+ const struct msg_stack *ms = m->stack[i];
+ if (!msg_location_is_empty (ms->location))
+ {
+ msg_location_format (ms->location, &s);
+ ds_put_cstr (&s, ": ");
+ }
+ ds_put_format (&s, "%s\n", ms->description);