Made BSD diff compatible
[pspp] / src / dictionary.c
index 3f1177d35f4f3f54ca827c47a68d659b4c012fe3..758f199763facd24f20513520bc934508c86d457 100644 (file)
@@ -223,7 +223,7 @@ dict_get_var (const struct dictionary *d, size_t idx)
    exclude ordinary, system, and/or scratch variables. */
 void
 dict_get_vars (const struct dictionary *d, struct variable ***vars,
-               size_t *cnt, unsigned exclude_classes)
+               int *cnt, unsigned exclude_classes)
 {
   size_t count;
   size_t i;
@@ -491,6 +491,23 @@ dict_delete_vars (struct dictionary *d,
     dict_delete_var (d, *vars++);
 }
 
+/* Deletes scratch variables from dictionary D. */
+void
+dict_delete_scratch_vars (struct dictionary *d)
+{
+  int i;
+
+  /* FIXME: this can be done in O(count) time, but this algorithm
+     is O(count**2). */
+  assert (d != NULL);
+
+  for (i = 0; i < d->var_cnt; )
+    if (dict_class_from_id (d->var[i]->name) == DC_SCRATCH)
+      dict_delete_var (d, d->var[i]);
+    else
+      i++;
+}
+
 /* Moves V to 0-based position IDX in D.  Other variables in D,
    if any, retain their relative positions.  Runs in time linear
    in the distance moved. */