Make dictionary compacting functions a little more general.
[pspp-builds.git] / src / data / sys-file-writer.c
index fe2c27c8102c71f23852d9d9ada4abd44b78f2b4..11ca1ef9fe032f398054dd3348ec96c6bb333f13 100644 (file)
@@ -103,7 +103,6 @@ static void write_variable_display_parameters (struct sfm_writer *w,
                                                const struct dictionary *dict);
 
 static void write_documents (struct sfm_writer *, const struct dictionary *);
-static int does_dict_need_translation (const struct dictionary *);
 
 static inline int
 var_flt64_cnt (const struct variable *v) 
@@ -194,7 +193,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d,
   w->fh = fh;
   w->file = fdopen (fd, "w");
 
-  w->needs_translation = does_dict_need_translation (d);
+  w->needs_translation = dict_compacting_would_change (d);
   w->compress = opts.compress;
   w->case_cnt = 0;
   w->flt64_cnt = 0;
@@ -328,27 +327,6 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d,
   goto error;
 }
 
-/* Returns zero if dictionary D's cases are ordered in the
-   natural manner, with the first variable followed by the
-   second, and so on,
-   nonzero otherwise. */
-static int
-does_dict_need_translation (const struct dictionary *d)
-{
-  size_t case_idx;
-  size_t i;
-
-  case_idx = 0;
-  for (i = 0; i < dict_get_var_cnt (d); i++) 
-    {
-      struct variable *v = dict_get_var (d, i);
-      if (v->fv != case_idx)
-        return 1;
-      case_idx += v->nv;
-    }
-  return 0;
-}
-
 /* Returns value of X truncated to two least-significant digits. */
 static int
 rerange (int x)