X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Ftitle.c;h=9d5b8261619c0a39c3d318bf8134933c4008422c;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=f33c8a99bf24f257da001ac520b04aa477a840f2;hpb=8021cf8974a46fe82af7b8952e448c0ea6858a48;p=pspp-builds.git diff --git a/src/language/utilities/title.c b/src/language/utilities/title.c index f33c8a99..9d5b8261 100644 --- a/src/language/utilities/title.c +++ b/src/language/utilities/title.c @@ -1,89 +1,80 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2007, 2010, 2011 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "data/dictionary.h" +#include "data/procedure.h" +#include "data/variable.h" +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "libpspp/message.h" +#include "libpspp/start-date.h" +#include "libpspp/version.h" +#include "output/text-item.h" + +#include "gl/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; - - c = lex_look_ahead (lexer); - if (c == '"' || c == '\'') + if (lex_look_ahead (lexer) == T_STRING) { lex_get (lexer); if (!lex_force_string (lexer)) return CMD_FAILURE; - if (*title) - free (*title); - *title = ds_xstrdup (lex_tokstr (lexer)); + set_title (lex_tokcstr (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) @@ -102,10 +93,10 @@ cmd_file_label (struct lexer *lexer, struct dataset *ds) /* Add entry date line to DICT's documents. */ static void -add_document_trailer (struct dictionary *dict) +add_document_trailer (struct dictionary *dict) { char buf[64]; - + sprintf (buf, _(" (Entered %s)"), get_start_date ()); dict_add_document_line (dict, buf); } @@ -123,7 +114,7 @@ cmd_document (struct lexer *lexer, struct dataset *ds) end_dot = lex_end_dot (lexer); ds_assign_string (&line, lex_entire_line_ds (lexer)); if (end_dot) - ds_put_char (&line, '.'); + ds_put_byte (&line, '.'); dict_add_document_line (dict, ds_cstr (&line)); lex_discard_line (lexer); @@ -132,6 +123,7 @@ cmd_document (struct lexer *lexer, struct dataset *ds) while (!end_dot); add_document_trailer (dict); + ds_destroy (&line); return CMD_SUCCESS; } @@ -157,7 +149,7 @@ cmd_add_documents (struct lexer *lexer, struct dataset *ds) while ( lex_is_string (lexer)) { - dict_add_document_line (dict, ds_cstr (lex_tokstr (lexer))); + dict_add_document_line (dict, lex_tokcstr (lexer)); lex_get (lexer); }