}
/* Creates and returns a (deep) copy of an existing
- dictionary. */
+ dictionary.
+
+ The new dictionary's case indexes are copied from the old
+ dictionary. If the new dictionary won't be used to access
+ cases produced with the old dictionary, then the new
+ dictionary's case indexes should be compacted with
+ dict_compact_values to save space. */
struct dictionary *
dict_clone (const struct dictionary *s)
{
for (i = 0; i < var_get_short_name_cnt (sv); i++)
var_set_short_name (dv, i, var_get_short_name (sv, i));
+
+ var_set_vardict (dv, var_get_vardict (sv));
}
d->next_value_idx = s->next_value_idx;
while (d->var_cnt > 0 )
{
- struct variable *v = d->var[d->var_cnt - 1];
- int dict_index = var_get_dict_index (v);
- int case_index = var_get_case_index (v);
- int val_cnt = var_get_value_cnt (v);
-
- var_clear_vardict (v);
- var_destroy (v);
-
- d->var_cnt--;
-
- if (d->callbacks && d->callbacks->var_deleted )
- d->callbacks->var_deleted (d,
- dict_index, case_index, val_cnt,
- d->cb_data);
+ dict_delete_var (d, d->var[d->var_cnt - 1]);
}
free (d->var);
struct variable *target ;
struct variable *result ;
- if ( ! var_is_valid_name (name, false))
+ if ( ! var_is_plausible_name (name, false))
return NULL;
target = var_create (name, 0);
var_clear_vardict (v);
var_destroy (v);
+
if (d->callbacks && d->callbacks->var_deleted )
d->callbacks->var_deleted (d, dict_index, case_index, val_cnt, d->cb_data);
}
assert (cnt == 0 || split != NULL);
d->split_cnt = cnt;
- d->split = cnt > 0 ? xnrealloc (d->split, cnt, sizeof *d->split) : NULL;
- memcpy (d->split, split, cnt * sizeof *d->split);
+ if ( cnt > 0 )
+ {
+ d->split = xnrealloc (d->split, cnt, sizeof *d->split) ;
+ memcpy (d->split, split, cnt * sizeof *d->split);
+ }
+ else
+ {
+ free (d->split);
+ d->split = NULL;
+ }
if ( d->callbacks && d->callbacks->split_changed )
d->callbacks->split_changed (d, d->cb_data);