output: Change command names from uppercase to title case.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 11 Jan 2021 01:46:48 +0000 (17:46 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 11 Jan 2021 01:53:54 +0000 (17:53 -0800)
This is compatible and easier to read.

src/output/driver.c
src/output/driver.h
src/output/pivot-table.c
src/output/spv/spv-writer.c
src/ui/gui/psppire.c
src/ui/terminal/main.c
tests/output/pivot-table-test.c

index 824a1ee2112a0810fe72fc83199cf8ca52015ed2..95dcbfd94a791943f15cc4999574f38ce995bded 100644 (file)
@@ -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
index acf052aeb20b4781cfdac37c1813211860eb3151..32c0f87c44619301d9c2da87b954e15b8b5e2da0 100644 (file)
@@ -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);
 
index 3698b78559037a955e949a2c56ce7201b03897da..55559773c87217cbdec3dbb2060e732f10175e4b 100644 (file)
@@ -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 ();
index 6256b32f12dff42a2698ed3686f6fabec3e7ba7d..4bdac19d7b0df300cbf8d3cca72ded7f03177612 100644 (file)
@@ -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))
index 9181d7e571b963575c2aea5ec00e4a6bf9beb2a6..240cca178d685459d93e7394fec5220eb0775806 100644 (file)
@@ -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));
 
index 26a6a316e0757c1947e44172702b3c304fb11630..06677668f44c520426e80c906cf50f37ff510a8b 100644 (file)
@@ -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));
 
index 976abcd0d0007994124d58441dd2174369fdad5c..d7d63fd39456d25d0ed8b0becc323eb020cf1673 100644 (file)
@@ -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));