Make casewriters keep track of the number of `union value's in each
[pspp-builds.git] / src / language / data-io / get.c
index 2cf07be8ca31955ce265b325ecc7fe7a1aa6b9aa..383513e632f0aadb5640d17e4cb81411fd312711 100644 (file)
@@ -1,20 +1,18 @@
-/* PSPP - computes sample statistics.
+/* PSPP - a program for statistical analysis.
    Copyright (C) 1997-9, 2000, 2006, 2007 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>
 
@@ -56,6 +54,7 @@ static struct case_map *finish_case_map (struct dictionary *);
 static void map_case (const struct case_map *,
                       const struct ccase *, struct ccase *);
 static void destroy_case_map (struct case_map *);
+static size_t case_map_get_value_cnt (const struct case_map *);
 
 static bool parse_dict_trim (struct lexer *, struct dictionary *);
 \f
@@ -360,6 +359,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds,
   map = finish_case_map (dict);
   if (map != NULL)
     writer = casewriter_create_translator (writer,
+                                           case_map_get_value_cnt (map),
                                            get_translate_case,
                                            get_destroy_case_map,
                                            map);
@@ -1425,6 +1425,7 @@ map_case (const struct case_map *map,
 {
   size_t dst_idx;
 
+  case_create (dst, map->value_cnt);
   for (dst_idx = 0; dst_idx < map->value_cnt; dst_idx++)
     {
       int src_idx = map->map[dst_idx];
@@ -1443,3 +1444,11 @@ destroy_case_map (struct case_map *map)
       free (map);
     }
 }
+
+/* Returns the number of `union value's in cases created by
+   MAP. */
+static size_t
+case_map_get_value_cnt (const struct case_map *map)
+{
+  return map->value_cnt;
+}