X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Ftitle.c;h=fe826db155dadb8ad1b5cd97d2df7709399171ba;hb=dfd1972f7bcb550a4fc3b05dbe7e71d12334b0a7;hp=1bdb0e9a0db6487467d51aa958452cf91ef13637;hpb=c9a3c45e44c1c03d13d4eb186e3817bc836f75f8;p=pspp-builds.git diff --git a/src/language/utilities/title.c b/src/language/utilities/title.c index 1bdb0e9a..fe826db1 100644 --- a/src/language/utilities/title.c +++ b/src/language/utilities/title.c @@ -27,29 +27,30 @@ #include #include #include -#include +#include #include "xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) -static int get_title (struct lexer *, const char *cmd, char **title); +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 get_title (lexer, "TITLE", &outp_title); + return parse_title (lexer, TEXT_ITEM_TITLE); } int cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED) { - return get_title (lexer, "SUBTITLE", &outp_subtitle); + return parse_title (lexer, TEXT_ITEM_SUBTITLE); } static int -get_title (struct lexer *lexer, const char *cmd, char **title) +parse_title (struct lexer *lexer, enum text_item_type type) { int c; @@ -59,30 +60,24 @@ get_title (struct lexer *lexer, const char *cmd, char **title) lex_get (lexer); if (!lex_force_string (lexer)) return CMD_FAILURE; - if (*title) - free (*title); - *title = ds_xstrdup (lex_tokstr (lexer)); + set_title (ds_cstr (lex_tokstr (lexer)), type); lex_get (lexer); - if (lex_token (lexer) != '.') - { - msg (SE, _("%s: `.' expected after string."), cmd); - return CMD_FAILURE; - } + return lex_end_of_command (lexer); } else { - char *cp; - - if (*title) - free (*title); - *title = xstrdup (lex_rest_of_line (lexer)); + set_title (lex_rest_of_line (lexer), type); lex_discard_line (lexer); - for (cp = *title; *cp; cp++) - *cp = toupper ((unsigned char) (*cp)); } return CMD_SUCCESS; } +static void +set_title (const char *title, enum text_item_type type) +{ + text_item_submit (text_item_create (type, title)); +} + /* Performs the FILE LABEL command. */ int cmd_file_label (struct lexer *lexer, struct dataset *ds)