output-item: Make command name part of every output_item.
[pspp] / src / output / group-item.c
index 3bfb44cd096146d9b97af5c9958d9741fc457296..c0aad17d9f9bc2e0d85432e41cc4a18989f47d83 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 
 #include "libpspp/compiler.h"
+#include "libpspp/str.h"
 #include "output/driver.h"
 #include "output/output-item-provider.h"
 
@@ -33,8 +34,8 @@ struct group_open_item *
 group_open_item_create (const char *command_name, const char *label)
 {
   return group_open_item_create_nocopy (
-    command_name ? xstrdup (command_name) : NULL,
-    label ? xstrdup (label) : NULL);
+    xstrdup_if_nonnull (command_name),
+    xstrdup_if_nonnull (label));
 }
 
 struct group_open_item *
@@ -44,7 +45,7 @@ group_open_item_create_nocopy (char *command_name, char *label)
   *item = (struct group_open_item) {
     .output_item = OUTPUT_ITEM_INITIALIZER (&group_open_item_class),
     .output_item.label = label,
-    .command_name = command_name,
+    .output_item.command_name = command_name,
   };
   return item;
 }
@@ -62,7 +63,9 @@ group_open_item_get_label (const struct output_item *output_item)
 {
   struct group_open_item *item = to_group_open_item (output_item);
 
-  return item->command_name ? item->command_name : _("Group");
+  return (item->output_item.command_name
+          ? item->output_item.command_name
+          : _("Group"));
 }
 
 static void
@@ -70,7 +73,6 @@ group_open_item_destroy (struct output_item *output_item)
 {
   struct group_open_item *item = to_group_open_item (output_item);
 
-  free (item->command_name);
   free (item);
 }