text-item: Merge "title" and "subtitle" items into a new "page title".
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 30 Nov 2018 05:26:35 +0000 (21:26 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Dec 2018 21:12:34 +0000 (13:12 -0800)
This better matches SPSS behavior.

12 files changed:
src/language/utilities/title.c
src/output/ascii.c
src/output/cairo.c
src/output/csv.c
src/output/driver.c
src/output/driver.h
src/output/html.c
src/output/text-item.h
tests/language/data-io/data-reader.at
tests/language/dictionary/split-file.at
tests/language/stats/descriptives.at
tests/language/xforms/count.at

index cc5314c4e3dab6b69c36328e9f574d9d37332597..686774463eb952fd271f2807fdec54726b495ece 100644 (file)
 #include "libpspp/message.h"
 #include "libpspp/start-date.h"
 #include "libpspp/version.h"
-#include "output/text-item.h"
+#include "output/driver.h"
 
 #include "gl/xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-static int parse_title (struct lexer *, enum text_item_type);
-static void set_title (const char *title, enum text_item_type);
-
-int
-cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
-{
-  return parse_title (lexer, TEXT_ITEM_TITLE);
-}
-
-int
-cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
-{
-  return parse_title (lexer, TEXT_ITEM_SUBTITLE);
-}
-
 static int
-parse_title (struct lexer *lexer, enum text_item_type type)
+parse_title (struct lexer *lexer, void (*set_title) (const char *))
 {
   if (!lex_force_string (lexer))
     return CMD_FAILURE;
-  set_title (lex_tokcstr (lexer), type);
+  set_title (lex_tokcstr (lexer));
   lex_get (lexer);
   return CMD_SUCCESS;
 }
 
-static void
-set_title (const char *title, enum text_item_type type)
+int
+cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
+{
+  return parse_title (lexer, output_set_title);
+}
+
+int
+cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED)
 {
-  text_item_submit (text_item_create (type, title));
+  return parse_title (lexer, output_set_subtitle);
 }
 
 /* Performs the FILE LABEL command. */
index d4032483da7132c609370d4952d7901745525f9f..46ab98a95c41a7dab77b0ccd1145bd59ec8be794 100644 (file)
@@ -484,8 +484,7 @@ ascii_submit (struct output_driver *driver,
 
       switch (type)
         {
-        case TEXT_ITEM_TITLE:
-        case TEXT_ITEM_SUBTITLE:
+        case TEXT_ITEM_PAGE_TITLE:
         case TEXT_ITEM_COMMAND_OPEN:
         case TEXT_ITEM_COMMAND_CLOSE:
           break;
index 2e749e22a420f6e16b3bb188f761443726a0c163..4debc93d8e29c02e88afb2e587c248bd49952132 100644 (file)
@@ -1662,18 +1662,10 @@ static struct xr_render_fsm *
 xr_render_text (struct xr_driver *xr, const struct text_item *text_item)
 {
   enum text_item_type type = text_item_get_type (text_item);
-  const char *text = text_item_get_text (text_item);
 
   switch (type)
     {
-    case TEXT_ITEM_TITLE:
-      free (xr->title);
-      xr->title = xstrdup (text);
-      break;
-
-    case TEXT_ITEM_SUBTITLE:
-      free (xr->subtitle);
-      xr->subtitle = xstrdup (text);
+    case TEXT_ITEM_PAGE_TITLE:
       break;
 
     case TEXT_ITEM_COMMAND_CLOSE:
index 763d19137219c0aaa38a77ad0e41879e818a646d..c5d418293efcaa00a340efa8900701172037cae8 100644 (file)
@@ -150,20 +150,6 @@ csv_output_field (struct csv_driver *csv, const char *field)
     fputs (field, csv->file);
 }
 
-static void PRINTF_FORMAT (2, 3)
-csv_output_field_format (struct csv_driver *csv, const char *format, ...)
-{
-  va_list args;
-  char *s;
-
-  va_start (args, format);
-  s = xvasprintf (format, args);
-  va_end (args);
-
-  csv_output_field (csv, s);
-  free (s);
-}
-
 static void
 csv_format_footnotes (const struct footnote **f, size_t n, struct string *s)
 {
@@ -283,24 +269,11 @@ csv_submit (struct output_driver *driver,
       const char *text = text_item_get_text (text_item);
 
       if (type == TEXT_ITEM_COMMAND_OPEN || type == TEXT_ITEM_COMMAND_CLOSE
-          || type == TEXT_ITEM_SYNTAX)
+          || type == TEXT_ITEM_SYNTAX || type == TEXT_ITEM_PAGE_TITLE)
         return;
 
       csv_put_separator (csv);
-      switch (type)
-        {
-        case TEXT_ITEM_TITLE:
-          csv_output_field_format (csv, "Title: %s", text);
-          break;
-
-        case TEXT_ITEM_SUBTITLE:
-          csv_output_field_format (csv, "Subtitle: %s", text);
-          break;
-
-        default:
-          csv_output_field (csv, text);
-          break;
-        }
+      csv_output_field (csv, text);
       putc ('\n', csv->file);
     }
   else if (is_message_item (output_item))
index f2d581cfe4558d5e1171b937f7f7ad72eb12bbeb..b07330633386aff1d5854a318a602d14839bfa7e 100644 (file)
@@ -50,6 +50,7 @@ struct output_engine
     struct llx_list drivers;       /* Contains "struct output_driver"s. */
     struct string deferred_syntax; /* TEXT_ITEM_SYNTAX being accumulated. */
     char *command_name;            /* Name of command being processed. */
+    char *title, *subtitle;        /* Components of page title. */
   };
 
 static const struct output_driver_factory *factories[];
@@ -78,6 +79,8 @@ output_engine_push (void)
   llx_init (&e->drivers);
   ds_init_empty (&e->deferred_syntax);
   e->command_name = NULL;
+  e->title = NULL;
+  e->subtitle = NULL;
 }
 
 void
@@ -94,6 +97,8 @@ output_engine_pop (void)
     }
   ds_destroy (&e->deferred_syntax);
   free (e->command_name);
+  free (e->title);
+  free (e->subtitle);
 }
 
 void
@@ -225,6 +230,37 @@ output_flush (void)
         d->class->flush (d);
     }
 }
+
+static void
+output_set_title__ (struct output_engine *e, char **dst, const char *src)
+{
+  free (*dst);
+  *dst = src ? xstrdup (src) : NULL;
+
+  char *page_title
+    = (e->title && e->subtitle ? xasprintf ("%s\n%s", e->title, e->subtitle)
+       : e->title ? xstrdup (e->title)
+       : e->subtitle ? xstrdup (e->subtitle)
+       : xzalloc (1));
+  text_item_submit (text_item_create_nocopy (TEXT_ITEM_PAGE_TITLE,
+                                             page_title));
+}
+
+void
+output_set_title (const char *title)
+{
+  struct output_engine *e = engine_stack_top ();
+
+  output_set_title__ (e, &e->title, title);
+}
+
+void
+output_set_subtitle (const char *subtitle)
+{
+  struct output_engine *e = engine_stack_top ();
+
+  output_set_title__ (e, &e->subtitle, subtitle);
+}
 \f
 void
 output_driver_init (struct output_driver *driver,
index 53dfde8b84128dec3c732eb0acab33678b48ef61..5849a06ac14f450505c66bd22090808730d1d761 100644 (file)
@@ -31,6 +31,9 @@ void output_engine_pop (void);
 void output_submit (struct output_item *);
 void output_flush (void);
 
+void output_set_title (const char *);
+void output_set_subtitle (const char *);
+
 void output_driver_parse_option (const char *option,
                                  struct string_map *options);
 struct output_driver *output_driver_create (struct string_map *options);
index 0b61486bd6e39200d2d371c31cd2e853a23ff39c..d75b13190948ee1896ede47bd0851f6e4490df4f 100644 (file)
@@ -261,12 +261,7 @@ html_submit (struct output_driver *driver,
 
       switch (text_item_get_type (text_item))
         {
-        case TEXT_ITEM_TITLE:
-          print_title_tag (html->file, "H1", s);
-          break;
-
-        case TEXT_ITEM_SUBTITLE:
-          print_title_tag (html->file, "H2", s);
+        case TEXT_ITEM_PAGE_TITLE:
           break;
 
         case TEXT_ITEM_COMMAND_OPEN:
index 3cfeb28b73e9e5ed08fdd8a33d1cefbec0f27a24..e09d06badc4da4f3ff11d8b626f72a393c9f4eee 100644 (file)
@@ -39,8 +39,7 @@ enum text_item_type
     TEXT_ITEM_COMMAND_CLOSE,    /* Command completed. */
 
     /* Headings. */
-    TEXT_ITEM_TITLE,            /* TITLE command. */
-    TEXT_ITEM_SUBTITLE,         /* SUBTITLE command. */
+    TEXT_ITEM_PAGE_TITLE,       /* TITLE and SUBTITLE commands. */
     TEXT_ITEM_SUBHEAD,          /* Heading within a command's output.*/
 
     /* Syntax. */
index 4ca00a6aa72822c53b98bd597c282bde3f7eb2ff..83d316aee39d1bdb0cd12a1c9755093e025f087c 100644 (file)
@@ -33,8 +33,6 @@ BEGIN DATA.
 END DATA.
 ])
 AT_CHECK([pspp -O format=csv begin-data.sps], [0], [dnl
-Title: Test BEGIN DATA ... END DATA
-
 Table: Reading 1 record from INLINE.
 Variable,Record,Columns,Format
 a,1,1-  1,F1.0
index 9538e714d89b652fd6b7c34d5c96b68c95c529d3..2dc9a2e5063f3d42b205cf6bbc8464cbe52ac772 100644 (file)
@@ -41,8 +41,6 @@ list.
 ])
 AT_CHECK([pspp -o pspp.csv split-file.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-Title: Test SPLIT FILE utility
-
 Variable,Value,Label
 X,1,
 
@@ -135,4 +133,4 @@ finish.
 
 AT_CHECK([pspp -O format=csv split-file.sps], [0],[ignore])
 
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
index bc3bbb66d1ced6322116a9625feb53d2d2e3aab7..508f954e12cc69cda8a40f17f356d392c1a2db82 100644 (file)
@@ -36,9 +36,7 @@ end data.
 
 descript all/stat=all/format=serial.
 ])
-AT_CHECK([pspp -O format=csv descriptives.sps], [0],
-  [Title: Test DESCRIPTIVES procedure
-
+AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
 Table: Reading 1 record from INLINE.
 Variable,Record,Columns,Format
 V0,1,1-  1,F1.0
index d6a1f67d5bf82faa3254e7e23197d84b6975845f..88d842d564636d5a3726162812a0fcf9b8b191ab 100644 (file)
@@ -73,8 +73,6 @@ COUNT c=v1 to v2('2',' 4','1').
 LIST.
 ])
 AT_CHECK([pspp -O format=csv count.sps], [0], [dnl
-Title: Test COUNT transformation
-
 Table: Reading 1 record from INLINE.
 Variable,Record,Columns,Format
 v1,1,1-  2,A2