From 1b5c2d8fe129a5f8db76c42250a9c199deccb773 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 3 Jan 2016 10:28:04 -0800 Subject: [PATCH] GET DATA /TYPE=TXT: Remove obsolete IMPORTCASES subcommand. For compatibility. Reported by Charles Johnson. --- NEWS | 5 +- doc/files.texi | 22 +- src/language/data-io/data-parser.c | 30 +-- src/language/data-io/data-parser.h | 4 +- src/language/data-io/data-reader.c | 33 +-- src/language/data-io/data-reader.h | 3 +- src/language/data-io/get-data.c | 19 +- src/ui/gui/psppire-import-assistant.c | 14 +- tests/language/data-io/get-data-txt.at | 271 +------------------------ 9 files changed, 31 insertions(+), 370 deletions(-) diff --git a/NEWS b/NEWS index b7188b133d..ad18b3f1ca 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ PSPP NEWS -- history of user-visible changes. -Copyright (C) 1996-2000, 2008-2015 Free Software Foundation, Inc. +Copyright (C) 1996-2000, 2008-2016 Free Software Foundation, Inc. See the end for copying conditions. Please send PSPP bug reports to bug-gnu-pspp@gnu.org. @@ -43,6 +43,9 @@ Changes from 0.8.5 to 0.9.0: - Rendering of the variable and data sheets in right-to-left locales now works properly. + * The IMPORTCASES subcommand on GET DATA is now ignored, for + compatibility. + Changes from 0.8.4 to 0.8.5: * The FREQUENCIES and CROSSTABS commands can now generate barcharts. diff --git a/doc/files.texi b/doc/files.texi index 6b3a78c75b..617f4faadb 100644 --- a/doc/files.texi +++ b/doc/files.texi @@ -370,7 +370,7 @@ GET DATA /TYPE=TXT [ENCODING='@var{encoding}'] [/ARRANGEMENT=@{DELIMITED,FIXED@}] [/FIRSTCASE=@{@var{first_case}@}] - [/IMPORTCASE=@{ALL,FIRST @var{max_cases},PERCENT @var{percent}@}] + [/IMPORTCASES=...] @dots{}additional subcommands depending on ARRANGEMENT@dots{} @end display @@ -398,19 +398,13 @@ line. To skip lines at the beginning of an input file, set @subcmd{FIRSTCASE} to the number of the first line to read: 2 to skip the first line, 3 to skip the first two lines, and so on. -@subcmd{IMPORTCASE} can be used to limit the number of cases read from the -input file. With the default setting, ALL, all cases in the file are -read. Specify FIRST @var{max_cases} to read at most @var{max_cases} cases -from the file. Use @subcmd{PERCENT @var{percent}} to read only @var{percent} -percent, approximately, of the cases contained in the file. (The -percentage is approximate, because there is no way to accurately count -the number of cases in the file without reading the entire file. The -number of cases in some kinds of unusual files cannot be estimated; -@pspp{} will read all cases in such files.) - -@subcmd{FIRSTCASE} and @subcmd{IMPORTCASE} may be used with delimited and fixed-format -data. The remaining subcommands, which apply only to one of the two file -arrangements, are described below. +@subcmd{IMPORTCASES} is ignored, for compatibility. Use @cmd{N OF +CASES} to limit the number of cases read from a file (@pxref{N OF +CASES}), or @cmd{SAMPLE} to obtain a random sample of cases +(@pxref{SAMPLE}). + +The remaining subcommands apply only to one of the two file +arrangements, described below. @menu * GET DATA /TYPE=TXT /ARRANGEMENT=DELIMITED:: diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c index b85d1b1720..960505a5ce 100644 --- a/src/language/data-io/data-parser.c +++ b/src/language/data-io/data-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013, 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 @@ -44,8 +44,6 @@ struct data_parser const struct dictionary *dict; /*Dictionary of destination */ enum data_parser_type type; /* Type of data to parse. */ int skip_records; /* Records to skip before first real data. */ - casenumber max_cases; /* Max number of cases to read. */ - int percent_cases; /* Approximate percent of cases to read. */ struct field *fields; /* Fields to parse. */ size_t field_cnt; /* Number of fields. */ @@ -86,8 +84,6 @@ data_parser_create (const struct dictionary *dict) parser->type = DP_FIXED; parser->skip_records = 0; - parser->max_cases = -1; - parser->percent_cases = 100; parser->fields = NULL; parser->field_cnt = 0; @@ -154,24 +150,6 @@ data_parser_set_skip (struct data_parser *parser, int initial_records_to_skip) parser->skip_records = initial_records_to_skip; } -/* Sets the maximum number of cases parsed by PARSER to - MAX_CASES. The default is -1, meaning no limit. */ -void -data_parser_set_case_limit (struct data_parser *parser, casenumber max_cases) -{ - parser->max_cases = max_cases; -} - -/* Sets the percentage of cases that PARSER should read from the - input file to PERCENT_CASES. By default, all cases are - read. */ -void -data_parser_set_case_percent (struct data_parser *parser, int percent_cases) -{ - assert (percent_cases >= 0 && percent_cases <= 100); - parser->percent_cases = percent_cases; -} - /* Returns true if PARSER is configured to allow cases to span multiple records. */ bool @@ -389,12 +367,6 @@ data_parser_parse (struct data_parser *parser, struct dfm_reader *reader, } /* Limit cases. */ - if (parser->max_cases != -1 && parser->max_cases-- == 0) - return false; - if (parser->percent_cases < 100 - && dfm_get_percent_read (reader) >= parser->percent_cases) - return false; - if (parser->type == DP_DELIMITED) { if (parser->span) diff --git a/src/language/data-io/data-parser.h b/src/language/data-io/data-parser.h index 013e707858..560eed30a2 100644 --- a/src/language/data-io/data-parser.h +++ b/src/language/data-io/data-parser.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2011 Free Software Foundation, Inc. + Copyright (C) 2007, 2011, 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 @@ -45,8 +45,6 @@ enum data_parser_type data_parser_get_type (const struct data_parser *); void data_parser_set_type (struct data_parser *, enum data_parser_type); void data_parser_set_skip (struct data_parser *, int initial_records_to_skip); -void data_parser_set_case_limit (struct data_parser *, casenumber max_cases); -void data_parser_set_case_percent (struct data_parser *, int case_percent); /* For configuring delimited parsers only. */ bool data_parser_get_span (const struct data_parser *); diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index 0a00619e84..1e06d28773 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-2004, 2006, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-2004, 2006, 2010, 2011, 2012, 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 @@ -23,7 +23,6 @@ #include #include #include -#include #include "data/casereader.h" #include "data/dataset.h" @@ -67,7 +66,6 @@ struct dfm_reader struct string scratch; /* Extra line buffer. */ enum dfm_reader_flags flags; /* Zero or more of DFM_*. */ FILE *file; /* Associated file. */ - off_t file_size; /* File size, or -1 if unavailable. */ size_t pos; /* Offset in line of current character. */ unsigned eof_cnt; /* # of attempts to advance past EOF. */ struct lexer *lexer; /* The lexer reading the file */ @@ -155,7 +153,6 @@ dfm_open_reader (struct file_handle *fh, struct lexer *lexer, r->block_left = 0; if (fh_get_referent (fh) != FH_REF_INLINE) { - struct stat s; r->line_number = 0; r->file = fn_open (fh, "rb"); if (r->file == NULL) @@ -164,10 +161,7 @@ dfm_open_reader (struct file_handle *fh, struct lexer *lexer, fh_get_file_name (r->fh), strerror (errno)); goto error; } - r->file_size = fstat (fileno (r->file), &s) == 0 ? s.st_size : -1; } - else - r->file_size = -1; fh_lock_set_aux (lock, r); if (encoding == NULL) @@ -658,31 +652,6 @@ dfm_reader_get_encoding (const struct dfm_reader *reader) return reader->encoding; } -/* Returns a number between 0 and 100 that approximates the - percentage of the data in READER that has already been read, - or -1 if this value cannot be estimated. - - ftello is slow in glibc (it flushes the read buffer), so don't - call this function unless you need to. */ -int -dfm_get_percent_read (const struct dfm_reader *reader) -{ - if (reader->file_size >= 0) - { - off_t position; - - position = (reader->line_reader != NULL - ? line_reader_tell (reader->line_reader) - : ftello (reader->file)); - if (position >= 0) - { - double p = 100.0 * position / reader->file_size; - return p < 0 ? 0 : p > 100 ? 100 : p; - } - } - return -1; -} - /* Causes dfm_get_record() or dfm_get_whole_record() to read in the next record the next time it is executed on file HANDLE. */ diff --git a/src/language/data-io/data-reader.h b/src/language/data-io/data-reader.h index a199f015af..27e03b1639 100644 --- a/src/language/data-io/data-reader.h +++ b/src/language/data-io/data-reader.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2010, 2011, 2012, 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 @@ -39,7 +39,6 @@ unsigned dfm_eof (struct dfm_reader *); struct substring dfm_get_record (struct dfm_reader *); void dfm_expand_tabs (struct dfm_reader *); const char *dfm_reader_get_encoding (const struct dfm_reader *); -int dfm_get_percent_read (const struct dfm_reader *); /* Line control. */ void dfm_forward_record (struct dfm_reader *); diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c index 8ad0d80fa7..2bf419659d 100644 --- 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, - 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 @@ -492,33 +492,22 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) 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; - 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; - 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); } + 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)) { diff --git a/src/ui/gui/psppire-import-assistant.c b/src/ui/gui/psppire-import-assistant.c index ad32d1f5d3..3d7ba0468a 100644 --- a/src/ui/gui/psppire-import-assistant.c +++ b/src/ui/gui/psppire-import-assistant.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2015 Free Software Foundation + Copyright (C) 2015, 2016 Free Software Foundation 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 @@ -2233,13 +2233,11 @@ static void intro_append_syntax (const PsppireImportAssistant *ia, struct string *s) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ia->n_cases_button))) - ds_put_format (s, " /IMPORTCASE=FIRST %d\n", + ds_put_format (s, "N OF CASES %d.\n", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ia->n_cases_spin))); else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ia->percent_button))) - ds_put_format (s, " /IMPORTCASE=PERCENT %d\n", - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ia->percent_spin))); - else - ds_put_cstr (s, " /IMPORTCASE=ALL\n"); + ds_put_format (s, "SAMPLE %.4g.\n", + gtk_spin_button_get_value (GTK_SPIN_BUTTON (ia->percent_spin)) / 100.0); } @@ -2386,9 +2384,6 @@ psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia) if (ia->encoding && strcmp (ia->encoding, "Auto")) syntax_gen_pspp (&s, " /ENCODING=%sq\n", ia->encoding); - intro_append_syntax (ia, &s); - - ds_put_cstr (&s, " /ARRANGEMENT=DELIMITED\n" " /DELCASE=LINE\n"); @@ -2398,6 +2393,7 @@ psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia) formats_append_syntax (ia, &s); apply_dict (ia->dict, &s); + intro_append_syntax (ia, &s); } else { diff --git a/tests/language/data-io/get-data-txt.at b/tests/language/data-io/get-data-txt.at index df814f0027..9e01aae374 100644 --- a/tests/language/data-io/get-data-txt.at +++ b/tests/language/data-io/get-data-txt.at @@ -295,280 +295,21 @@ EOF ]) AT_DATA([get-data.sps], [dnl get data /type=txt /file='test.data' /importcase=first 10 /variables x f8.0. -list. - get data /type=txt /file='test.data' /importcase=percent 1 /variables x f8.0. -list. - get data /type=txt /file='test.data' /importcase=percent 35 /variables x f8.0. -list. - get data /type=txt /file='test.data' /importcase=percent 95 /variables x f8.0. -list. - get data /type=txt /file='test.data' /importcase=percent 100 /variables x f8.0. -list. ]) -AT_CHECK([pspp -o pspp.csv get-data.sps]) -AT_CHECK([cat pspp.csv], [0], [dnl -Table: Data List -x -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 +AT_CHECK([pspp -O format=csv get-data.sps], [0], [dnl +get-data.sps:1: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.) -Table: Data List -x -1 -2 +get-data.sps:2: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.) -Table: Data List -x -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 +get-data.sps:3: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.) -Table: Data List -x -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 +get-data.sps:4: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.) -Table: Data List -x -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 +get-data.sps:5: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.) ]) AT_CLEANUP -- 2.30.2