projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'origin/master' into sheet
[pspp]
/
src
/
language
/
data-io
/
get-data.c
diff --git
a/src/language/data-io/get-data.c
b/src/language/data-io/get-data.c
index 3458b39e413fa0c205746977223d5023e86b3b45..13eebe6c3aaabe840a155c4e405fa797e99af295 100644
(file)
--- a/
src/language/data-io/get-data.c
+++ b/
src/language/data-io/get-data.c
@@
-1,6
+1,6
@@
/* PSPP - a program for statistical analysis.
Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012,
/* PSPP - a program for statistical analysis.
Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012,
- 2013, 2015 Free Software Foundation, Inc.
+ 2013, 2015
, 2016
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
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
@@
-51,12
+51,14
@@
static const bool odf_read_support = true;
#else
static const bool odf_read_support = false;
static const bool odf_read_support = true;
#else
static const bool odf_read_support = false;
+struct spreadsheet *ods_probe (const char *filename, bool report_errors){}
#endif
#ifdef GNM_READ_SUPPORT
static const bool gnm_read_support = true;
#else
static const bool gnm_read_support = false;
#endif
#ifdef GNM_READ_SUPPORT
static const bool gnm_read_support = true;
#else
static const bool gnm_read_support = false;
+struct spreadsheet *gnumeric_probe (const char *filename, bool report_errors){}
#endif
static bool parse_spreadsheet (struct lexer *lexer, char **filename,
#endif
static bool parse_spreadsheet (struct lexer *lexer, char **filename,
@@
-79,14
+81,20
@@
cmd_get_data (struct lexer *lexer, struct dataset *ds)
opts.read_names = false;
opts.asw = -1;
opts.read_names = false;
opts.asw = -1;
- lex_force_match (lexer, T_SLASH);
+ if (! lex_force_match (lexer, T_SLASH))
+ goto error;
if (!lex_force_match_id (lexer, "TYPE"))
goto error;
if (!lex_force_match_id (lexer, "TYPE"))
goto error;
- lex_force_match (lexer, T_EQUALS);
+ if (!lex_force_match (lexer, T_EQUALS))
+ goto error;
+
+ const char *s = lex_tokcstr (lexer);
- tok = strdup (lex_tokcstr (lexer));
+ if (s)
+ tok = strdup (s);
+
if (lex_match_id (lexer, "TXT"))
{
free (tok);
if (lex_match_id (lexer, "TXT"))
{
free (tok);
@@
-101,41
+109,30
@@
cmd_get_data (struct lexer *lexer, struct dataset *ds)
lex_match_id (lexer, "ODS"))
{
char *filename = NULL;
lex_match_id (lexer, "ODS"))
{
char *filename = NULL;
- struct casereader *reader = NULL;
- struct dictionary *dict = NULL;
-
if (!parse_spreadsheet (lexer, &filename, &opts))
goto error;
if (!parse_spreadsheet (lexer, &filename, &opts))
goto error;
+ struct spreadsheet *spreadsheet = NULL;
if ( gnm_read_support && 0 == strncasecmp (tok, "GNM", 3))
if ( gnm_read_support && 0 == strncasecmp (tok, "GNM", 3))
- {
- struct spreadsheet *spreadsheet = gnumeric_probe (filename, true);
- if (spreadsheet == NULL)
- goto error;
- reader = gnumeric_make_reader (spreadsheet, &opts);
- dict = spreadsheet->dict;
- gnumeric_unref (spreadsheet);
- }
+ spreadsheet = gnumeric_probe (filename, true);
else if ( odf_read_support && 0 == strncasecmp (tok, "ODS", 3))
else if ( odf_read_support && 0 == strncasecmp (tok, "ODS", 3))
- {
- struct spreadsheet *spreadsheet = ods_probe (filename, true);
- if (spreadsheet == NULL)
- goto error;
- reader = ods_make_reader (spreadsheet, &opts);
- dict = spreadsheet->dict;
- ods_unref (spreadsheet);
- }
+ spreadsheet = ods_probe (filename, true);
free (filename);
free (filename);
+ if (spreadsheet == NULL)
+ goto error;
+ struct casereader *reader = spreadsheet_make_reader (spreadsheet, &opts);
if (reader)
{
if (reader)
{
- dataset_set_dict (ds, dict);
+ dataset_set_dict (ds, dict
_clone (spreadsheet->dict)
);
dataset_set_source (ds, reader);
free (tok);
destroy_spreadsheet_read_info (&opts);
dataset_set_source (ds, reader);
free (tok);
destroy_spreadsheet_read_info (&opts);
+ spreadsheet_unref (spreadsheet);
return CMD_SUCCESS;
}
return CMD_SUCCESS;
}
+ spreadsheet_unref (spreadsheet);
}
else
msg (SE, _("Unsupported TYPE %s."), tok);
}
else
msg (SE, _("Unsupported TYPE %s."), tok);
@@
-157,12
+154,14
@@
parse_get_psql (struct lexer *lexer, struct dataset *ds)
psql.bsize = -1;
ds_init_empty (&psql.sql);
psql.bsize = -1;
ds_init_empty (&psql.sql);
- lex_force_match (lexer, T_SLASH);
+ if (! lex_force_match (lexer, T_SLASH))
+ goto error;
if (!lex_force_match_id (lexer, "CONNECT"))
goto error;
if (!lex_force_match_id (lexer, "CONNECT"))
goto error;
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (!lex_force_string (lexer))
goto error;
if (!lex_force_string (lexer))
goto error;
@@
-176,14
+175,20
@@
parse_get_psql (struct lexer *lexer, struct dataset *ds)
if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
{
lex_match (lexer, T_EQUALS);
if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
{
lex_match (lexer, T_EQUALS);
- psql.str_width = lex_integer (lexer);
- lex_get (lexer);
+ if (lex_force_int (lexer))
+ {
+ psql.str_width = lex_integer (lexer);
+ lex_get (lexer);
+ }
}
else if ( lex_match_id (lexer, "BSIZE"))
{
lex_match (lexer, T_EQUALS);
}
else if ( lex_match_id (lexer, "BSIZE"))
{
lex_match (lexer, T_EQUALS);
- psql.bsize = lex_integer (lexer);
- lex_get (lexer);
+ if (lex_force_int (lexer))
+ {
+ psql.bsize = lex_integer (lexer);
+ lex_get (lexer);
+ }
}
else if ( lex_match_id (lexer, "UNENCRYPTED"))
{
}
else if ( lex_match_id (lexer, "UNENCRYPTED"))
{
@@
-233,12
+238,14
@@
parse_spreadsheet (struct lexer *lexer, char **filename,
opts->read_names = true;
opts->asw = -1;
opts->read_names = true;
opts->asw = -1;
- lex_force_match (lexer, T_SLASH);
+ if (! lex_force_match (lexer, T_SLASH))
+ goto error;
if (!lex_force_match_id (lexer, "FILE"))
goto error;
if (!lex_force_match_id (lexer, "FILE"))
goto error;
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
if (!lex_force_string (lexer))
goto error;
if (!lex_force_string (lexer))
goto error;
@@
-252,8
+259,11
@@
parse_spreadsheet (struct lexer *lexer, char **filename,
if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
{
lex_match (lexer, T_EQUALS);
if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
{
lex_match (lexer, T_EQUALS);
- opts->asw = lex_integer (lexer);
- lex_get (lexer);
+ if (lex_force_int (lexer))
+ {
+ opts->asw = lex_integer (lexer);
+ lex_get (lexer);
+ }
}
else if (lex_match_id (lexer, "SHEET"))
{
}
else if (lex_match_id (lexer, "SHEET"))
{
@@
-270,6
+280,9
@@
parse_spreadsheet (struct lexer *lexer, char **filename,
}
else if (lex_match_id (lexer, "INDEX"))
{
}
else if (lex_match_id (lexer, "INDEX"))
{
+ if (!lex_force_int (lexer))
+ goto error;
+
opts->sheet_index = lex_integer (lexer);
if (opts->sheet_index <= 0)
{
opts->sheet_index = lex_integer (lexer);
if (opts->sheet_index <= 0)
{
@@
-376,11
+389,13
@@
parse_get_txt (struct lexer *lexer, struct dataset *ds)
enum data_parser_type type;
bool has_type;
enum data_parser_type type;
bool has_type;
- lex_force_match (lexer, T_SLASH);
+ if (! lex_force_match (lexer, T_SLASH))
+ goto error;
if (!lex_force_match_id (lexer, "FILE"))
goto error;
if (!lex_force_match_id (lexer, "FILE"))
goto error;
- lex_force_match (lexer, T_EQUALS);
+ if (! lex_force_match (lexer, T_EQUALS))
+ goto error;
fh = fh_parse (lexer, FH_REF_FILE | FH_REF_INLINE, NULL);
if (fh == NULL)
goto error;
fh = fh_parse (lexer, FH_REF_FILE | FH_REF_INLINE, NULL);
if (fh == NULL)
goto error;
@@
-483,33
+498,22
@@
parse_get_txt (struct lexer *lexer, struct dataset *ds)
lex_match (lexer, T_EQUALS);
if (lex_match (lexer, T_ALL))
{
lex_match (lexer, T_EQUALS);
if (lex_match (lexer, T_ALL))
{
- data_parser_set_case_limit (parser, -1);
- data_parser_set_case_percent (parser, 100);
+ /* Nothing to do. */
}
else if (lex_match_id (lexer, "FIRST"))
{
if (!lex_force_int (lexer))
goto error;
}
else if (lex_match_id (lexer, "FIRST"))
{
if (!lex_force_int (lexer))
goto error;
- if (lex_integer (lexer) < 1)
- {
- msg (SE, _("Value of %s must be 1 or greater."), "FIRST");
- goto error;
- }
- data_parser_set_case_limit (parser, lex_integer (lexer));
lex_get (lexer);
}
else if (lex_match_id (lexer, "PERCENT"))
{
if (!lex_force_int (lexer))
goto error;
lex_get (lexer);
}
else if (lex_match_id (lexer, "PERCENT"))
{
if (!lex_force_int (lexer))
goto error;
- if (lex_integer (lexer) < 1 || lex_integer (lexer) > 100)
- {
- msg (SE, _("Value of %s must be between 1 and 100."), "PERCENT");
- goto error;
- }
- data_parser_set_case_percent (parser, lex_integer (lexer));
lex_get (lexer);
}
lex_get (lexer);
}
+ msg (SW, _("Ignoring obsolete IMPORTCASES subcommand. (N OF CASES "
+ "or SAMPLE may be used to substitute.)"));
}
else if (lex_match_id_n (lexer, "DELIMITERS", 4))
{
}
else if (lex_match_id_n (lexer, "DELIMITERS", 4))
{
@@
-606,18
+610,20
@@
parse_get_txt (struct lexer *lexer, struct dataset *ds)
lex_get (lexer);
}
lex_get (lexer);
}
- if (!lex_force_id (lexer)
- || !dict_id_is_valid (dict, lex_tokcstr (lexer), true))
- goto error;
name = xstrdup (lex_tokcstr (lexer));
name = xstrdup (lex_tokcstr (lexer));
+ if (!lex_force_id (lexer)
+ || !dict_id_is_valid (dict, name, true))
+ {
+ goto error;
+ }
lex_get (lexer);
lex_get (lexer);
-
if (type == DP_DELIMITED)
{
if (!parse_format_specifier (lexer, &input)
if (type == DP_DELIMITED)
{
if (!parse_format_specifier (lexer, &input)
- || !fmt_check_input (&input))
- goto error;
-
+ || !fmt_check_input (&input))
+ {
+ goto error;
+ }
output = fmt_for_output_from_input (&input);
}
else
output = fmt_for_output_from_input (&input);
}
else
@@
-637,14
+643,12
@@
parse_get_txt (struct lexer *lexer, struct dataset *ds)
msg (SE, _("Unknown format type `%s'."), fmt_type_name);
goto error;
}
msg (SE, _("Unknown format type `%s'."), fmt_type_name);
goto error;
}
-
/* Compose input format. */
input.type = fmt_type;
input.w = lc - fc + 1;
input.d = 0;
if (!fmt_check_input (&input))
goto error;
/* Compose input format. */
input.type = fmt_type;
input.w = lc - fc + 1;
input.d = 0;
if (!fmt_check_input (&input))
goto error;
-
/* Compose output format. */
if (w != 0)
{
/* Compose output format. */
if (w != 0)
{
@@
-657,7
+661,6
@@
parse_get_txt (struct lexer *lexer, struct dataset *ds)
else
output = fmt_for_output_from_input (&input);
}
else
output = fmt_for_output_from_input (&input);
}
-
v = dict_create_var (dict, name, fmt_var_width (&input));
if (v == NULL)
{
v = dict_create_var (dict, name, fmt_var_width (&input));
if (v == NULL)
{
@@
-665,7
+668,6
@@
parse_get_txt (struct lexer *lexer, struct dataset *ds)
goto error;
}
var_set_both_formats (v, &output);
goto error;
}
var_set_both_formats (v, &output);
-
if (type == DP_DELIMITED)
data_parser_add_delimited_field (parser, &input,
var_get_case_index (v),
if (type == DP_DELIMITED)
data_parser_add_delimited_field (parser, &input,
var_get_case_index (v),