- /* Reorder the dictionary so that the kept variables are at
- the beginning. */
- {
- int i1;
-
- for (i1 = 0; i1 < nv; i1++)
- {
- int i2 = v[i1]->index;
-
- /* Swap variables with indices i1 and i2. */
- struct variable *t = dict->var[i1];
- dict->var[i1] = dict->var[i2];
- dict->var[i2] = t;
- dict->var[i1]->index = i1;
- dict->var[i2]->index = i2;
- }
-
- free (v);
- }
-
- /* Delete all but the first NV variables from the
- dictionary. */
- {
- int i;
- for (i = nv; i < dict->nvar; i++)
- {
- clear_variable (dict, dict->var[i]);
- free (dict->var[i]);
- }
- }
- dict->var = xrealloc (dict->var, sizeof *dict->var * nv);
- dict->nvar = nv;
+ /* Move the specified variables to the beginning. */
+ dict_reorder_vars (dict, v, nv);
+
+ /* Delete the remaining variables. */
+ v = xrealloc (v, (dict_get_var_cnt (dict) - nv) * sizeof *v);
+ for (i = nv; i < dict_get_var_cnt (dict); i++)
+ v[i - nv] = dict_get_var (dict, i);
+ dict_delete_vars (dict, v, dict_get_var_cnt (dict) - nv);
+ free (v);