GET DATA /TYPE=TXT: Remove obsolete IMPORTCASES subcommand.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 3 Jan 2016 18:28:04 +0000 (10:28 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 3 Jan 2016 18:28:04 +0000 (10:28 -0800)
For compatibility.

Reported by Charles Johnson.

NEWS
doc/files.texi
src/language/data-io/data-parser.c
src/language/data-io/data-parser.h
src/language/data-io/data-reader.c
src/language/data-io/data-reader.h
src/language/data-io/get-data.c
src/ui/gui/psppire-import-assistant.c
tests/language/data-io/get-data-txt.at

diff --git a/NEWS b/NEWS
index b7188b133d8622770df5e94a78f4b513547eebc6..ad18b3f1caf58d3a7b816a6944e05f276daf1bab 100644 (file)
--- 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.
index 6b3a78c75b6d6f5c0aa25943830d8320956f62b0..617f4faadb00513d656202e283358417fe69dc45 100644 (file)
@@ -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::
index b85d1b172012e44dcaf540d60902adcf63518973..960505a5ce25f322931f1e8050161f72f0698ede 100644 (file)
@@ -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)
index 013e707858e5a9ee60bf6c7692654d95270512ac..560eed30a22ec4e384e6f244199f80d3e01f8f41 100644 (file)
@@ -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 *);
index 0a00619e84b3cbac356c9b5094101ab7a06d3001..1e06d287735db834a3527893bbba298fea2de282 100644 (file)
@@ -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 <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 
 #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. */
index a199f015af79a5749dddfe6d99aa5ece5a537baa..27e03b1639f34edb13cbb9cf13f923b9c8560d26 100644 (file)
@@ -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 *);
index 8ad0d80fa7ff4e7bfc2731d83eae5a6b0287a260..2bf419659d18e52ae99a91455c05dcd8a5b698df 100644 (file)
@@ -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))
         {
index ad32d1f5d3c5c80b1ba305293b2315314b26d642..3d7ba0468a6312a748e0c9fcacec9ee9a16a58ba 100644 (file)
@@ -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
     {
index df814f00279a6876d05e81d09e7a7009814aa5a6..9e01aae3744f921ac26b304e78b8bd62a6b6bfc9 100644 (file)
@@ -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