X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Ftitle.c;h=323bdf3fa51e79d35c375e8fc6a4dde22431a979;hb=f5711a3a6d3f28e53513269e774bfa1e8274c1c5;hp=398288b812c9d966c6e6de13a76edeffbb784f06;hpb=9ade26c8349b4434008c46cf09bc7473ec743972;p=pspp diff --git a/src/language/utilities/title.c b/src/language/utilities/title.c index 398288b812..323bdf3fa5 100644 --- a/src/language/utilities/title.c +++ b/src/language/utilities/title.c @@ -19,50 +19,67 @@ #include #include +#include "data/dataset.h" #include "data/dictionary.h" -#include "data/procedure.h" #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 if (lex_token (lexer) == T_ENDCMD) + { + /* This would be a bad special case below because n-1 would be + SIZE_MAX. */ + set_title (""); + } + else + { + /* Count the tokens in the title. */ + size_t n = 0; + while (lex_next (lexer, n)->type != T_ENDCMD) + n++; + + /* Get the raw representation of all the tokens, including any space + between them, and use it as the title. */ + char *title = lex_next_representation (lexer, 0, n - 1); + set_title (title); + free (title); + + /* Skip past the tokens. */ + for (size_t i = 0; i < n; i++) + lex_get (lexer); + } + 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. */