From 16420b87c39a3a27071fde7727db49bd577ea58e Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@cs.stanford.edu>
Date: Sun, 10 Jan 2021 17:46:48 -0800
Subject: [PATCH] output: Change command names from uppercase to title case.

This is compatible and easier to read.
---
 src/output/driver.c             | 17 +++++++++++------
 src/output/driver.h             |  3 ++-
 src/output/pivot-table.c        |  2 +-
 src/output/spv/spv-writer.c     |  8 ++------
 src/ui/gui/psppire.c            |  2 +-
 src/ui/terminal/main.c          |  2 +-
 tests/output/pivot-table-test.c |  2 +-
 7 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/output/driver.c b/src/output/driver.c
index 824a1ee211..95dcbfd94a 100644
--- a/src/output/driver.c
+++ b/src/output/driver.c
@@ -257,11 +257,9 @@ output_submit (struct output_item *item)
   output_submit__ (e, item);
 }
 
-/* Returns the name of the command currently being parsed, in all uppercase.
-   The caller must free the returned value.
-
-   Returns NULL if no command is being parsed. */
-char *
+/* Returns the name of the command currently being parsed, or NULL if no
+   command is being parsed. */
+const char *
 output_get_command_name (void)
 {
   struct output_engine *e = engine_stack_top ();
@@ -270,11 +268,18 @@ output_get_command_name (void)
 
   for (size_t i = e->n_groups; i-- > 0;)
     if (e->groups[i])
-      return utf8_to_upper (e->groups[i]);
+      return e->groups[i];
 
   return NULL;
 }
 
+char *
+output_get_uppercase_command_name (void)
+{
+  const char *command_name = output_get_command_name ();
+  return command_name ? utf8_to_upper (command_name) : NULL;
+}
+
 /* Flushes output to screen devices, so that the user can see
    output that doesn't fill up an entire page. */
 void
diff --git a/src/output/driver.h b/src/output/driver.h
index acf052aeb2..32c0f87c44 100644
--- a/src/output/driver.h
+++ b/src/output/driver.h
@@ -36,7 +36,8 @@ void output_set_title (const char *);
 void output_set_subtitle (const char *);
 void output_set_filename (const char *);
 
-char *output_get_command_name (void);
+const char *output_get_command_name (void);
+char *output_get_uppercase_command_name (void);
 
 size_t output_get_group_level (void);
 
diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c
index 3698b78559..55559773c8 100644
--- a/src/output/pivot-table.c
+++ b/src/output/pivot-table.c
@@ -872,7 +872,7 @@ pivot_table_create__ (struct pivot_value *title, const char *subtype)
   table->weight_format = (struct fmt_spec) { FMT_F, 40, 0 };
   table->title = title;
   table->subtype = subtype ? pivot_value_new_text (subtype) : NULL;
-  table->command_c = output_get_command_name ();
+  table->command_c = xstrdup_if_nonempty (output_get_command_name ());
   table->look = pivot_table_look_ref (pivot_table_look_get_default ());
   table->settings = fmt_settings_copy (settings_get_fmt_settings ());
   table->small = settings_get_small ();
diff --git a/src/output/spv/spv-writer.c b/src/output/spv/spv-writer.c
index 6256b32f12..4bdac19d7b 100644
--- a/src/output/spv/spv-writer.c
+++ b/src/output/spv/spv-writer.c
@@ -1113,12 +1113,8 @@ spv_writer_write (struct spv_writer *w, const struct output_item *item)
   else if (is_image_item (item))
     spv_writer_put_image (w, item, to_image_item (item)->image);
   else if (is_text_item (item))
-    {
-      char *command_id = output_get_command_name ();
-      spv_writer_put_text (w, to_text_item (item),
-                           command_id);
-      free (command_id);
-    }
+    spv_writer_put_text (w, to_text_item (item),
+                         output_get_command_name ());
   else if (is_page_break_item (item))
     w->need_page_break = true;
   else if (is_page_setup_item (item))
diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c
index 9181d7e571..240cca178d 100644
--- a/src/ui/gui/psppire.c
+++ b/src/ui/gui/psppire.c
@@ -160,7 +160,7 @@ handle_msg (const struct msg *m_, void *lexer_)
       m.first_column = lex_get_first_column (lexer, 0);
       m.last_column = lex_get_last_column (lexer, 0);
     }
-  m.command_name = output_get_command_name ();
+  m.command_name = output_get_uppercase_command_name ();
 
   message_item_submit (message_item_create (&m));
 
diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c
index 26a6a316e0..06677668f4 100644
--- a/src/ui/terminal/main.c
+++ b/src/ui/terminal/main.c
@@ -227,7 +227,7 @@ output_msg (const struct msg *m_, void *lexer_)
       m.last_line = lex_get_last_line_number (lexer, 0);
     }
 
-  m.command_name = output_get_command_name ();
+  m.command_name = output_get_uppercase_command_name ();
 
   message_item_submit (message_item_create (&m));
 
diff --git a/tests/output/pivot-table-test.c b/tests/output/pivot-table-test.c
index 976abcd0d0..d7d63fd394 100644
--- a/tests/output/pivot-table-test.c
+++ b/tests/output/pivot-table-test.c
@@ -1237,7 +1237,7 @@ output_msg (const struct msg *m_, void *lexer_)
       m.last_line = lex_get_last_line_number (lexer, 0);
     }
 
-  m.command_name = output_get_command_name ();
+  m.command_name = output_get_uppercase_command_name ();
 
   message_item_submit (message_item_create (&m));
 
-- 
2.30.2