+ const struct macro *const *ap = a_;
+ const struct macro *const *bp = b_;
+ const struct macro *a = *ap;
+ const struct macro *b = *bp;
+
+ return utf8_strcasecmp (a->name, b->name);
+}
+
+int
+cmd_display_macros (struct lexer *lexer, struct dataset *ds UNUSED)
+{
+ const struct macro_set *set = lex_get_macros (lexer);
+
+ if (hmap_is_empty (&set->macros))
+ {
+ msg (SN, _("No macros to display."));
+ return CMD_SUCCESS;
+ }
+
+ const struct macro **macros = xnmalloc (hmap_count (&set->macros),
+ sizeof *macros);
+ size_t n = 0;
+ const struct macro *m;
+ HMAP_FOR_EACH (m, struct macro, hmap_node, &set->macros)
+ macros[n++] = m;
+ assert (n == hmap_count (&set->macros));
+ sort (macros, n, sizeof *macros, compare_macros_by_name, NULL);
+
+ struct pivot_table *table = pivot_table_create (N_("Macros"));
+
+ struct pivot_dimension *attributes = pivot_dimension_create (
+ table, PIVOT_AXIS_COLUMN, N_("Attributes"));
+ pivot_category_create_leaf (attributes->root,
+ pivot_value_new_text (N_("Source Location")));
+
+ struct pivot_dimension *names = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Name"));
+ names->root->show_label = true;
+
+ for (size_t i = 0; i < n; i++)
+ {
+ const struct macro *m = macros[i];
+
+ pivot_category_create_leaf (names->root,
+ pivot_value_new_user_text (m->name, -1));
+
+ struct string location = DS_EMPTY_INITIALIZER;
+ msg_location_format (m->location, &location);
+ pivot_table_put2 (
+ table, 0, i,
+ pivot_value_new_user_text_nocopy (ds_steal_cstr (&location)));
+ }
+
+ pivot_table_submit (table);
+
+ free (macros);
+
+ return CMD_SUCCESS;