lexer: New function lex_ofs_representation().
[pspp] / src / language / utilities / title.c
index cc5314c4e3dab6b69c36328e9f574d9d37332597..8ad6a4acb30b5723ea27e1ad0fc698f667c0b758 100644 (file)
 #include "data/variable.h"
 #include "language/command.h"
 #include "language/lexer/lexer.h"
+#include "language/lexer/token.h"
 #include "libpspp/message.h"
 #include "libpspp/start-date.h"
 #include "libpspp/version.h"
-#include "output/text-item.h"
+#include "output/driver.h"
 
+#include "gl/c-ctype.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);
+static int
+parse_title (struct lexer *lexer, void (*set_title) (const char *))
+{
+  if (lex_token (lexer) == T_STRING)
+    {
+      set_title (lex_tokcstr (lexer));
+      lex_get (lexer);
+    }
+  else
+    {
+      int start_ofs = lex_ofs (lexer);
+      while (lex_token (lexer) != T_ENDCMD)
+        lex_get (lexer);
+
+      /* Get the raw representation of all the tokens, including any space
+         between them, and use it as the title. */
+      char *title = lex_ofs_representation (lexer, start_ofs,
+                                            lex_ofs (lexer) - 1);
+      set_title (title);
+      free (title);
+    }
+  return CMD_SUCCESS;
+}
 
 int
 cmd_title (struct lexer *lexer, struct dataset *ds UNUSED)
 {
-  return parse_title (lexer, TEXT_ITEM_TITLE);
+  return parse_title (lexer, output_set_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)
-{
-  if (!lex_force_string (lexer))
-    return CMD_FAILURE;
-  set_title (lex_tokcstr (lexer), type);
-  lex_get (lexer);
-  return CMD_SUCCESS;
-}
-
-static void
-set_title (const char *title, enum text_item_type type)
-{
-  text_item_submit (text_item_create (type, title));
+  return parse_title (lexer, output_set_subtitle);
 }
 
 /* Performs the FILE LABEL command. */