magic-elimination.patch from patch #6230.
[pspp-builds.git] / src / language / stats / descriptives.c
index 4b1ea6e2fa8bc0974fd8252b1bc233cc05597665..70751495024e6f9767943a25d8349449ee981273 100644 (file)
@@ -1,20 +1,18 @@
-/* PSPP - computes sample statistics.
+/* PSPP - a program for statistical analysis.
    Copyright (C) 1997-9, 2000 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 the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 
@@ -35,7 +33,6 @@
 #include <libpspp/alloc.h>
 #include <libpspp/array.h>
 #include <libpspp/compiler.h>
-#include <libpspp/magic.h>
 #include <libpspp/message.h>
 #include <libpspp/assertion.h>
 #include <math/moments.h>
@@ -412,7 +409,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds)
     for (i = 0; i < dsc->var_cnt; i++)
       dsc->vars[i].moments = moments_create (dsc->max_moment);
 
-  /* Data pass.  FIXME: error handling. */
+  /* Data pass. */
   grouper = casegrouper_create_splits (proc_open (ds), dict);
   while (casegrouper_get_next_group (grouper, &group))
     calc_descriptives (dsc, group, ds);
@@ -701,16 +698,18 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group,
   size_t i;
 
   if (!casereader_peek (group, 0, &c))
-    return;
+    {
+      casereader_destroy (group);
+      return;
+    }
   output_split_file_values (ds, &c);
   case_destroy (&c);
 
   group = casereader_create_filter_weight (group, dataset_dict (ds),
                                            NULL, NULL);
 
-  casereader_split (group, &pass1, &pass2);
-  if (dsc->max_moment <= MOMENT_MEAN)
-    casereader_destroy (pass2);
+  pass1 = group;
+  pass2 = dsc->max_moment <= MOMENT_MEAN ? NULL : casereader_clone (pass1);
 
   for (i = 0; i < dsc->var_cnt; i++)
     {
@@ -760,7 +759,10 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group,
         }
     }
   if (!casereader_destroy (pass1))
-    return;
+    {
+      casereader_destroy (pass2);
+      return;
+    }
 
   /* Second pass for higher-order moments. */
   if (dsc->max_moment > MOMENT_MEAN)