pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src data/ChangeLog data/automake.mk langua...


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src data/ChangeLog data/automake.mk langua...
Date: Mon, 13 Aug 2007 04:13:49 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 07/08/13 04:13:49

Modified files:
        src/data       : ChangeLog automake.mk 
        src/language/data-io: ChangeLog get.c 
Added files:
        src/language/data-io: case-map.c case-map.h 

Log message:
        * get.c (struct case_map): Move into new file src/data/case-map.c.
        (start_case_map): Ditto, and rename case_map_prepare_dict.
        (finish_case_map): Ditto, and rename case_map_from_dict.
        (map_case): Ditto, and rename case_map_execute.
        (destroy_case_map): Ditto, and rename case_map_destroy.
        (case_map_get_value_cnt): Ditto.
        
        * automake.mk: Add case-map.c, case-map.h.
        
        * case-map.c: New file.
        
        * case-map.h: New file.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.151&r2=1.152
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/automake.mk?cvsroot=pspp&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/ChangeLog?cvsroot=pspp&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/get.c?cvsroot=pspp&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/case-map.c?cvsroot=pspp&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/case-map.h?cvsroot=pspp&rev=1.1

Patches:
Index: data/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.151
retrieving revision 1.152
diff -u -b -r1.151 -r1.152
--- data/ChangeLog      13 Aug 2007 03:44:45 -0000      1.151
+++ data/ChangeLog      13 Aug 2007 04:13:48 -0000      1.152
@@ -1,5 +1,13 @@
 2007-08-12  Ben Pfaff  <address@hidden>
 
+       * automake.mk: Add case-map.c, case-map.h.
+
+       * case-map.c: New file.
+
+       * case-map.h: New file.
+
+2007-08-12  Ben Pfaff  <address@hidden>
+
        * dictionary.c (dict_compact_values): Don't delete scratch
        variables as well as compacting case indexes.  Update all callers.
        (dict_get_compacted_value_cnt): Rename dict_count_values and

Index: data/automake.mk
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/automake.mk,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- data/automake.mk    23 Jul 2007 05:05:45 -0000      1.27
+++ data/automake.mk    13 Aug 2007 04:13:48 -0000      1.28
@@ -8,6 +8,8 @@
        src/data/any-writer.h \
        src/data/calendar.c \
        src/data/calendar.h \
+       src/data/case-map.c \
+       src/data/case-map.h \
        src/data/case-ordering.c \
        src/data/case-ordering.h \
        src/data/case.c \

Index: language/data-io/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/ChangeLog,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- language/data-io/ChangeLog  13 Aug 2007 00:41:35 -0000      1.43
+++ language/data-io/ChangeLog  13 Aug 2007 04:13:48 -0000      1.44
@@ -1,5 +1,14 @@
 2007-08-12  Ben Pfaff  <address@hidden>
 
+       * get.c (struct case_map): Move into new file src/data/case-map.c.
+       (start_case_map): Ditto, and rename case_map_prepare_dict.
+       (finish_case_map): Ditto, and rename case_map_from_dict.
+       (map_case): Ditto, and rename case_map_execute.
+       (destroy_case_map): Ditto, and rename case_map_destroy.
+       (case_map_get_value_cnt): Ditto.
+
+2007-08-12  Ben Pfaff  <address@hidden>
+
        * get.c (case_map_get_value_cnt): New function.
 
 2007-07-25  Ben Pfaff  <address@hidden>

Index: language/data-io/get.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/get.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- language/data-io/get.c      13 Aug 2007 03:44:46 -0000      1.39
+++ language/data-io/get.c      13 Aug 2007 04:13:49 -0000      1.40
@@ -21,6 +21,7 @@
 #include <data/any-reader.h>
 #include <data/any-writer.h>
 #include <data/case.h>
+#include <data/case-map.h>
 #include <data/casereader.h>
 #include <data/casewriter.h>
 #include <data/format.h>
@@ -48,14 +49,6 @@
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-/* Rearranging and reducing a dictionary. */
-static void start_case_map (struct dictionary *);
-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 *);
 
 /* Reading system and portable files. */
@@ -120,7 +113,7 @@
   if (reader == NULL)
     goto error;
 
-  start_case_map (dict);
+  case_map_prepare_dict (dict);
 
   while (lex_token (lexer) != '.')
     {
@@ -129,7 +122,7 @@
         goto error;
     }
 
-  map = finish_case_map (dict);
+  map = case_map_from_dict (dict);
   if (map != NULL)
     reader = casereader_create_translator (reader,
                                            dict_get_next_value_idx (dict),
@@ -153,14 +146,14 @@
                     void *map_)
 {
   struct case_map *map = map_;
-  map_case (map, input, output);
+  case_map_execute (map, input, output);
 }
 
 static bool
 get_destroy_case_map (void *map_)
 {
   struct case_map *map = map_;
-  destroy_case_map (map);
+  case_map_destroy (map);
   return true;
 }
 
@@ -238,7 +231,7 @@
   sysfile_opts = sfm_writer_default_options ();
   porfile_opts = pfm_writer_default_options ();
 
-  start_case_map (dict);
+  case_map_prepare_dict (dict);
   dict_delete_scratch_vars (dict);
 
   lex_match (lexer, '/');
@@ -357,7 +350,7 @@
   if (writer == NULL)
     goto error;
 
-  map = finish_case_map (dict);
+  map = case_map_from_dict (dict);
   if (map != NULL)
     writer = casewriter_create_translator (writer,
                                            case_map_get_value_cnt (map),
@@ -371,7 +364,7 @@
  error:
   casewriter_destroy (writer);
   dict_destroy (dict);
-  destroy_case_map (map);
+  case_map_destroy (map);
   return NULL;
 }
 
@@ -1326,131 +1319,3 @@
 
   return true;
 }
-
-/* Case map.
-
-   A case map copies data from a case that corresponds for one
-   dictionary to a case that corresponds to a second dictionary
-   derived from the first by, optionally, deleting, reordering,
-   or renaming variables.  (No new variables may be created.)
-   */
-
-/* A case map. */
-struct case_map
-  {
-    size_t value_cnt;   /* Number of values in map. */
-    int *map;           /* For each destination index, the
-                           corresponding source index. */
-  };
-
-/* Prepares dictionary D for producing a case map.  Afterward,
-   the caller may delete, reorder, or rename variables within D
-   at will before using finish_case_map() to produce the case
-   map.
-
-   Uses D's aux members, which must otherwise not be in use. */
-static void
-start_case_map (struct dictionary *d)
-{
-  size_t var_cnt = dict_get_var_cnt (d);
-  size_t i;
-
-  for (i = 0; i < var_cnt; i++)
-    {
-      struct variable *v = dict_get_var (d, i);
-      int *src_fv = xmalloc (sizeof *src_fv);
-      *src_fv = var_get_case_index (v);
-      var_attach_aux (v, src_fv, var_dtor_free);
-    }
-}
-
-/* Produces a case map from dictionary D, which must have been
-   previously prepared with start_case_map().
-
-   Does not retain any reference to D, and clears the aux members
-   set up by start_case_map().
-
-   Returns the new case map, or a null pointer if no mapping is
-   required (that is, no data has changed position). */
-static struct case_map *
-finish_case_map (struct dictionary *d)
-{
-  struct case_map *map;
-  size_t var_cnt = dict_get_var_cnt (d);
-  size_t i;
-  int identity_map;
-
-  map = xmalloc (sizeof *map);
-  map->value_cnt = dict_get_next_value_idx (d);
-  map->map = xnmalloc (map->value_cnt, sizeof *map->map);
-  for (i = 0; i < map->value_cnt; i++)
-    map->map[i] = -1;
-
-  identity_map = 1;
-  for (i = 0; i < var_cnt; i++)
-    {
-      struct variable *v = dict_get_var (d, i);
-      size_t value_cnt = var_get_value_cnt (v);
-      int *src_fv = (int *) var_detach_aux (v);
-      size_t idx;
-
-      if (var_get_case_index (v) != *src_fv)
-        identity_map = 0;
-
-      for (idx = 0; idx < value_cnt; idx++)
-        {
-          int src_idx = *src_fv + idx;
-          int dst_idx = var_get_case_index (v) + idx;
-
-          assert (map->map[dst_idx] == -1);
-          map->map[dst_idx] = src_idx;
-        }
-      free (src_fv);
-    }
-
-  if (identity_map)
-    {
-      destroy_case_map (map);
-      return NULL;
-    }
-
-  while (map->value_cnt > 0 && map->map[map->value_cnt - 1] == -1)
-    map->value_cnt--;
-
-  return map;
-}
-
-/* Maps from SRC to DST, applying case map MAP. */
-static void
-map_case (const struct case_map *map,
-          const struct ccase *src, struct ccase *dst)
-{
-  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];
-      if (src_idx != -1)
-        *case_data_rw_idx (dst, dst_idx) = *case_data_idx (src, src_idx);
-    }
-}
-
-/* Destroys case map MAP. */
-static void
-destroy_case_map (struct case_map *map)
-{
-  if (map != NULL)
-    {
-      free (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;
-}

Index: language/data-io/case-map.c
===================================================================
RCS file: language/data-io/case-map.c
diff -N language/data-io/case-map.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ language/data-io/case-map.c 13 Aug 2007 04:13:49 -0000      1.1
@@ -0,0 +1,141 @@
+/* PSPP - computes sample statistics.
+   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 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. */
+
+#include <config.h>
+
+#include <language/data-io/case-map.h>
+
+#include <stdlib.h>
+
+#include <data/case.h>
+#include <data/dictionary.h>
+#include <data/variable.h>
+#include <libpspp/assertion.h>
+
+#include "xalloc.h"
+
+/* A case map. */
+struct case_map
+  {
+    size_t value_cnt;   /* Number of values in map. */
+    int *map;           /* For each destination index, the
+                           corresponding source index. */
+  };
+
+/* Prepares dictionary D for producing a case map.  Afterward,
+   the caller may delete, reorder, or rename variables within D
+   at will before using finish_case_map() to produce the case
+   map.
+
+   Uses D's aux members, which must otherwise not be in use. */
+void
+case_map_prepare (struct dictionary *d) 
+{
+  size_t var_cnt = dict_get_var_cnt (d);
+  size_t i;
+  
+  for (i = 0; i < var_cnt; i++)
+    {
+      struct variable *v = dict_get_var (d, i);
+      int *src_fv = xmalloc (sizeof *src_fv);
+      *src_fv = var_get_case_index (v);
+      var_attach_aux (v, src_fv, var_dtor_free);
+    }
+}
+
+/* Produces a case map from dictionary D, which must have been
+   previously prepared with start_case_map().
+
+   Does not retain any reference to D, and clears the aux members
+   set up by start_case_map().
+
+   Returns the new case map, or a null pointer if no mapping is
+   required (that is, no data has changed position). */
+struct case_map *
+case_map_finish (struct dictionary *d) 
+{
+  struct case_map *map;
+  size_t var_cnt = dict_get_var_cnt (d);
+  size_t i;
+  int identity_map;
+
+  map = xmalloc (sizeof *map);
+  map->value_cnt = dict_get_next_value_idx (d);
+  map->map = xnmalloc (map->value_cnt, sizeof *map->map);
+  for (i = 0; i < map->value_cnt; i++)
+    map->map[i] = -1;
+
+  identity_map = 1;
+  for (i = 0; i < var_cnt; i++) 
+    {
+      struct variable *v = dict_get_var (d, i);
+      size_t value_cnt = var_get_value_cnt (v);
+      int *src_fv = var_detach_aux (v);
+      size_t idx;
+
+      if (var_get_case_index (v) != *src_fv)
+        identity_map = 0;
+      
+      for (idx = 0; idx < value_cnt; idx++)
+        {
+          int src_idx = *src_fv + idx;
+          int dst_idx = var_get_case_index (v) + idx;
+          
+          assert (map->map[dst_idx] == -1);
+          map->map[dst_idx] = src_idx;
+        }
+      free (src_fv);
+    }
+
+  if (identity_map) 
+    {
+      case_map_destroy (map);
+      return NULL;
+    }
+
+  while (map->value_cnt > 0 && map->map[map->value_cnt - 1] == -1)
+    map->value_cnt--;
+
+  return map;
+}
+
+/* Maps from SRC to DST, applying case map MAP. */
+void
+case_map_execute (const struct case_map *map,
+                  const struct ccase *src, struct ccase *dst) 
+{
+  size_t dst_idx;
+
+  for (dst_idx = 0; dst_idx < map->value_cnt; dst_idx++)
+    {
+      int src_idx = map->map[dst_idx];
+      if (src_idx != -1)
+        *case_data_rw_idx (dst, dst_idx) = *case_data_idx (src, src_idx);
+    }
+}
+
+/* Destroys case map MAP. */
+void
+case_map_destroy (struct case_map *map) 
+{
+  if (map != NULL) 
+    {
+      free (map->map);
+      free (map);
+    }
+}

Index: language/data-io/case-map.h
===================================================================
RCS file: language/data-io/case-map.h
diff -N language/data-io/case-map.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ language/data-io/case-map.h 13 Aug 2007 04:13:49 -0000      1.1
@@ -0,0 +1,39 @@
+/* PSPP - computes sample statistics.
+   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 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. */
+
+#ifndef LANGUAGE_DATA_IO_CASE_MAP_H
+#define LANGUAGE_DATA_IO_CASE_MAP_H 1
+
+/* Case map.
+
+   A case map copies data from a case that corresponds for one
+   dictionary to a case that corresponds to a second dictionary
+   derived from the first by, optionally, deleting, reordering,
+   or renaming variables.  (No new variables may be created.)
+   */
+
+struct dictionary;
+struct ccase;
+
+void case_map_prepare (struct dictionary *);
+struct case_map *case_map_finish (struct dictionary *);
+void case_map_execute (const struct case_map *,
+                       const struct ccase *, struct ccase *);
+void case_map_destroy (struct case_map *);
+
+#endif /* language/data-io/case-map.h */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]