/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 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
#define _(msgid) gettext (msgid)
#define N_(msgid) (msgid)
-static struct spreadsheet_read_info *parse_spreadsheet (struct lexer *lexer);
-static void destroy_spreadsheet_read_info (struct spreadsheet_read_info *);
+static bool parse_spreadsheet (struct lexer *lexer, struct spreadsheet_read_info *sri,
+ struct spreadsheet_read_options *opts);
+
+static void destroy_spreadsheet_read_info (struct spreadsheet_read_info *, struct spreadsheet_read_options *);
static int parse_get_txt (struct lexer *lexer, struct dataset *);
static int parse_get_psql (struct lexer *lexer, struct dataset *);
tok = strdup (lex_tokcstr (lexer));
if (lex_match_id (lexer, "TXT"))
{
+ free (tok);
return parse_get_txt (lexer, ds);
}
else if (lex_match_id (lexer, "PSQL"))
{
+ free (tok);
return parse_get_psql (lexer, ds);
}
else if (lex_match_id (lexer, "GNM") ||
{
struct casereader *reader = NULL;
struct dictionary *dict = NULL;
- struct spreadsheet_read_info *sri = parse_spreadsheet (lexer);
- if (NULL == sri)
+ struct spreadsheet_read_info sri;
+ struct spreadsheet_read_options opts;
+ if (!parse_spreadsheet (lexer, &sri, &opts))
goto error;
if ( 0 == strncasecmp (tok, "GNM", 3))
- reader = gnumeric_open_reader (sri, &dict);
+ reader = gnumeric_open_reader (&sri, &opts, &dict);
else if (0 == strncasecmp (tok, "ODS", 3))
- reader = ods_open_reader (sri, &dict);
+ reader = ods_open_reader (&sri, &opts, &dict);
if (reader)
{
dataset_set_dict (ds, dict);
dataset_set_source (ds, reader);
- destroy_spreadsheet_read_info (sri);
+ destroy_spreadsheet_read_info (&sri, &opts);
free (tok);
return CMD_SUCCESS;
}
- destroy_spreadsheet_read_info (sri);
+ destroy_spreadsheet_read_info (&sri, &opts);
}
else
msg (SE, _("Unsupported TYPE %s."), tok);
return CMD_FAILURE;
}
-static struct spreadsheet_read_info *
-parse_spreadsheet (struct lexer *lexer)
+static bool
+parse_spreadsheet (struct lexer *lexer, struct spreadsheet_read_info *sri,
+ struct spreadsheet_read_options *opts)
{
- struct spreadsheet_read_info *sri = xzalloc (sizeof *sri);
- sri->sheet_index = 1;
+ opts->sheet_index = 1;
+ opts->sheet_name = NULL;
+ opts->cell_range = NULL;
sri->read_names = true;
sri->asw = -1;
+ sri->file_name = NULL;
lex_force_match (lexer, T_SLASH);
if ( ! lex_force_string (lexer) )
goto error;
- sri->sheet_name = ss_xstrdup (lex_tokss (lexer));
- sri->sheet_index = -1;
+ opts->sheet_name = ss_xstrdup (lex_tokss (lexer));
+ opts->sheet_index = -1;
lex_get (lexer);
}
else if (lex_match_id (lexer, "INDEX"))
{
sri->sheet_index = lex_integer (lexer);
+ if (sri->sheet_index <= 0)
+ {
+ msg (SE, _("The sheet index must be greater than or equal to 1"));
+ goto error;
+ }
lex_get (lexer);
}
else
- goto error;
+ {
+ msg (SE, _("%s must be followed by either \"%s\" or \"%s\"."),
+ "/SHEET", "NAME", "INDEX");
+ goto error;
+ }
}
else if (lex_match_id (lexer, "CELLRANGE"))
{
if (lex_match_id (lexer, "FULL"))
{
- sri->cell_range = NULL;
+ opts->cell_range = NULL;
}
else if (lex_match_id (lexer, "RANGE"))
{
if ( ! lex_force_string (lexer) )
goto error;
- sri->cell_range = ss_xstrdup (lex_tokss (lexer));
+ opts->cell_range = ss_xstrdup (lex_tokss (lexer));
lex_get (lexer);
}
else
- goto error;
+ {
+ msg (SE, _("%s must be followed by either \"%s\" or \"%s\"."),
+ "/CELLRANGE", "FULL", "RANGE");
+ goto error;
+ }
}
else if (lex_match_id (lexer, "READNAMES"))
{
sri->read_names = false;
}
else
- goto error;
+ {
+ msg (SE, _("%s must be followed by either \"%s\" or \"%s\"."),
+ "/READNAMES", "ON", "OFF");
+ goto error;
+ }
}
else
{
}
}
- return sri;
+ return true;
error:
- destroy_spreadsheet_read_info (sri);
- return NULL;
+ destroy_spreadsheet_read_info (sri, opts);
+ return false;
}
struct dictionary *dict = dict_create (get_default_encoding ());
struct file_handle *fh = NULL;
struct dfm_reader *reader = NULL;
+ char *encoding = NULL;
char *name = NULL;
int record;
if (!lex_force_match (lexer, T_SLASH))
goto error;
- if (lex_match_id (lexer, "ARRANGEMENT"))
+ if (lex_match_id (lexer, "ENCODING"))
+ {
+ lex_match (lexer, T_EQUALS);
+ if (!lex_force_string (lexer))
+ goto error;
+
+ free (encoding);
+ encoding = ss_xstrdup (lex_tokss (lexer));
+
+ lex_get (lexer);
+ }
+ else if (lex_match_id (lexer, "ARRANGEMENT"))
{
bool ok;
}
while (lex_token (lexer) != T_ENDCMD);
- reader = dfm_open_reader (fh, lexer);
+ reader = dfm_open_reader (fh, lexer, encoding);
if (reader == NULL)
goto error;
data_parser_make_active_file (parser, ds, reader, dict);
fh_unref (fh);
+ free (encoding);
return CMD_SUCCESS;
error:
dict_destroy (dict);
fh_unref (fh);
free (name);
+ free (encoding);
return CMD_CASCADING_FAILURE;
}
static void
-destroy_spreadsheet_read_info (struct spreadsheet_read_info *sri)
+destroy_spreadsheet_read_info (struct spreadsheet_read_info *sri,
+ struct spreadsheet_read_options *opts)
{
- if ( NULL == sri)
- return;
-
- free (sri->sheet_name);
- free (sri->cell_range);
+ free (opts->sheet_name);
+ free (opts->cell_range);
free (sri->file_name);
- free (sri);
}