/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
- Written by Ben Pfaff <blp@gnu.org>.
+ Copyright (C) 1997-9, 2000, 2007 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
#include "gettext.h"
#define _(msgid) gettext (msgid)
-static int get_title (const char *cmd, char **title);
+static int get_title (struct lexer *, const char *cmd, char **title);
int
-cmd_title (struct dataset *ds UNUSED)
+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 (struct dataset *ds UNUSED)
+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 ();
+ 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 = ds_xstrdup (&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;
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 = '.';
}
return CMD_SUCCESS;
}
/* Performs the FILE LABEL command. */
int
-cmd_file_label (struct dataset *ds)
+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 (dataset_dict (ds), label);
- token = '.';
return CMD_SUCCESS;
}
/* Performs the DOCUMENT command. */
int
-cmd_document (struct dataset *ds)
+cmd_document (struct lexer *lexer, struct dataset *ds)
{
struct dictionary *dict = dataset_dict (ds);
/* Add a few header lines for reference. */
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++;
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 (struct dataset *ds)
+cmd_drop_documents (struct lexer *lexer, struct dataset *ds)
{
dict_set_documents (dataset_dict (ds), NULL);
- return lex_end_of_command ();
+ return lex_end_of_command (lexer);
+}
+
+
+/* Performs the ADD DOCUMENTS command. */
+int
+cmd_add_documents (struct lexer *lexer, struct dataset *ds)
+{
+ int i;
+ int n_lines = 0;
+ char buf[256];
+ struct string *lines = NULL;
+
+ sprintf (buf, _("(Entered %s)"), get_start_date ());
+
+ if ( ! lex_force_string (lexer) )
+ return CMD_FAILURE;
+
+ while ( lex_is_string (lexer))
+ {
+ const struct string *s = lex_tokstr (lexer);
+ if ( ds_length (s) > 80)
+ {
+ /* Note to translators: "bytes" is correct, not characters */
+ msg (SE, _("Document lines may not be more than 80 bytes long."));
+ goto failure;
+
+ }
+ lines = xrealloc (lines, (n_lines + 1) * sizeof (*lines));
+ ds_init_string (&lines[n_lines++], s);
+
+ lex_get (lexer);
+ }
+
+ for ( i = 0 ; i < n_lines ; ++i)
+ {
+ add_document_line (dataset_dict (ds), ds_cstr (&lines[i]), 0);
+ ds_destroy (&lines[i]);
+ }
+
+ free (lines);
+
+ add_document_line (dataset_dict (ds), buf, 3);
+
+ return lex_end_of_command (lexer) ;
+
+ failure:
+ for ( i = 0 ; i < n_lines ; ++i)
+ ds_destroy (&lines[i]);
+
+ free (lines);
+
+ return CMD_FAILURE;
}