X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Ftitle.c;h=d7943126601f80881d62085173e3affd3d26fcfc;hb=e5675aa578a919a051f4de276d5f7e4df5ea8819;hp=759208d35122f38405fbe4e5529f780aa50260c4;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp-builds.git diff --git a/src/language/utilities/title.c b/src/language/utilities/title.c index 759208d3..d7943126 100644 --- a/src/language/utilities/title.c +++ b/src/language/utilities/title.c @@ -18,55 +18,54 @@ 02110-1301, USA. */ #include + #include #include -#include "alloc.h" -#include "command.h" -#include "dictionary.h" -#include "message.h" -#include "lexer.h" -#include "output.h" -#include "start-date.h" -#include "variable.h" -#include "version.h" -#include "procedure.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) -#include "debug-print.h" - -static int get_title (const char *cmd, char **title); +static int get_title (struct lexer *, const char *cmd, char **title); int -cmd_title (void) +cmd_title (struct lexer *lexer, struct dataset *ds UNUSED) { - return get_title ("TITLE", &outp_title); + return get_title (lexer, "TITLE", &outp_title); } int -cmd_subtitle (void) +cmd_subtitle (struct lexer *lexer, struct dataset *ds UNUSED) { - return get_title ("SUBTITLE", &outp_subtitle); + return get_title (lexer, "SUBTITLE", &outp_subtitle); } static int -get_title (const char *cmd, char **title) +get_title (struct lexer *lexer, const char *cmd, char **title) { int c; - c = lex_look_ahead (); - debug_printf ((_("%s before: %s\n"), cmd, *title ? *title : _(""))); + c = lex_look_ahead (lexer); if (c == '"' || c == '\'') { - lex_get (); - if (!lex_force_string ()) + lex_get (lexer); + if (!lex_force_string (lexer)) return CMD_FAILURE; if (*title) free (*title); - *title = xstrdup (ds_c_str (&tokstr)); - lex_get (); - if (token != '.') + *title = ds_xstrdup (lex_tokstr (lexer)); + lex_get (lexer); + if (lex_token (lexer) != '.') { msg (SE, _("%s: `.' expected after string."), cmd); return CMD_FAILURE; @@ -78,43 +77,40 @@ get_title (const char *cmd, char **title) if (*title) free (*title); - *title = xstrdup (lex_rest_of_line (NULL)); - lex_discard_line (); + *title = xstrdup (lex_rest_of_line (lexer, NULL)); + lex_discard_line (lexer); for (cp = *title; *cp; cp++) *cp = toupper ((unsigned char) (*cp)); - token = '.'; } - debug_printf ((_("%s after: %s\n"), cmd, *title)); return CMD_SUCCESS; } /* Performs the FILE LABEL command. */ int -cmd_file_label (void) +cmd_file_label (struct lexer *lexer, struct dataset *ds) { const char *label; - label = lex_rest_of_line (NULL); - lex_discard_line (); + label = lex_rest_of_line (lexer, NULL); + lex_discard_line (lexer); while (isspace ((unsigned char) *label)) label++; - dict_set_label (default_dict, label); - token = '.'; + dict_set_label (dataset_dict (ds), label); return CMD_SUCCESS; } -/* Add LINE as a line of document information to default_dict, +/* Add LINE as a line of document information to dictionary indented by INDENT spaces. */ static void -add_document_line (const char *line, int indent) +add_document_line (struct dictionary *dict, const char *line, int indent) { const char *old_documents; size_t old_len; char *new_documents; - old_documents = dict_get_documents (default_dict); + old_documents = dict_get_documents (dict); old_len = old_documents != NULL ? strlen (old_documents) : 0; new_documents = xmalloc (old_len + 81); @@ -123,24 +119,25 @@ add_document_line (const char *line, int indent) buf_copy_str_rpad (new_documents + old_len + indent, 80 - indent, line); new_documents[old_len + 80] = '\0'; - dict_set_documents (default_dict, new_documents); + dict_set_documents (dict, new_documents); free (new_documents); } /* Performs the DOCUMENT command. */ int -cmd_document (void) +cmd_document (struct lexer *lexer, struct dataset *ds) { + struct dictionary *dict = dataset_dict (ds); /* Add a few header lines for reference. */ { char buf[256]; - if (dict_get_documents (default_dict) != NULL) - add_document_line ("", 0); + if (dict && dict_get_documents (dict)) + add_document_line (dict, "", 0); sprintf (buf, _("Document entered %s by %s:"), get_start_date (), version); - add_document_line (buf, 1); + add_document_line (dict, buf, 1); } for (;;) @@ -149,8 +146,8 @@ cmd_document (void) const char *orig_line; char *copy_line; - orig_line = lex_rest_of_line (&had_dot); - lex_discard_line (); + orig_line = lex_rest_of_line (lexer, &had_dot); + lex_discard_line (lexer); while (isspace ((unsigned char) *orig_line)) orig_line++; @@ -159,23 +156,22 @@ cmd_document (void) if (had_dot) strcat (copy_line, "."); - add_document_line (copy_line, 3); + add_document_line (dict, copy_line, 3); free (copy_line); - lex_get_line (); + lex_get_line (lexer); if (had_dot) break; } - token = '.'; return CMD_SUCCESS; } /* Performs the DROP DOCUMENTS command. */ int -cmd_drop_documents (void) +cmd_drop_documents (struct lexer *lexer, struct dataset *ds) { - dict_set_documents (default_dict, NULL); + dict_set_documents (dataset_dict (ds), NULL); - return lex_end_of_command (); + return lex_end_of_command (lexer); }