250 |
assert (all_cnt >= keep_cnt); |
assert (all_cnt >= keep_cnt); |
251 |
|
|
252 |
drop_cnt = all_cnt - keep_cnt; |
drop_cnt = all_cnt - keep_cnt; |
253 |
drop_vars = xmalloc (drop_cnt * sizeof *keep_vars); |
drop_vars = xnmalloc (drop_cnt, sizeof *keep_vars); |
254 |
if (set_difference (all_vars, all_cnt, |
if (set_difference (all_vars, all_cnt, |
255 |
keep_vars, keep_cnt, |
keep_vars, keep_cnt, |
256 |
sizeof *all_vars, |
sizeof *all_vars, |
403 |
|
|
404 |
/* Drop variables, in index order. */ |
/* Drop variables, in index order. */ |
405 |
drop_cnt = vm->drop_cnt; |
drop_cnt = vm->drop_cnt; |
406 |
drop_vars = xmalloc (drop_cnt * sizeof *drop_vars); |
drop_vars = xnmalloc (drop_cnt, sizeof *drop_vars); |
407 |
memcpy (drop_vars, vm->drop_vars, drop_cnt * sizeof *drop_vars); |
memcpy (drop_vars, vm->drop_vars, drop_cnt * sizeof *drop_vars); |
408 |
sort (drop_vars, drop_cnt, sizeof *drop_vars, |
sort (drop_vars, drop_cnt, sizeof *drop_vars, |
409 |
compare_variables_given_ordering, &forward_positional_ordering); |
compare_variables_given_ordering, &forward_positional_ordering); |
411 |
/* Keep variables, in index order. */ |
/* Keep variables, in index order. */ |
412 |
assert (all_cnt >= drop_cnt); |
assert (all_cnt >= drop_cnt); |
413 |
keep_cnt = all_cnt - drop_cnt; |
keep_cnt = all_cnt - drop_cnt; |
414 |
keep_vars = xmalloc (keep_cnt * sizeof *keep_vars); |
keep_vars = xnmalloc (keep_cnt, sizeof *keep_vars); |
415 |
if (set_difference (all_vars, all_cnt, |
if (set_difference (all_vars, all_cnt, |
416 |
drop_vars, drop_cnt, |
drop_vars, drop_cnt, |
417 |
sizeof *all_vars, |
sizeof *all_vars, |
421 |
assert (0); |
assert (0); |
422 |
|
|
423 |
/* Copy variables into var_renaming array. */ |
/* Copy variables into var_renaming array. */ |
424 |
var_renaming = xmalloc (keep_cnt * sizeof *var_renaming); |
var_renaming = xnmalloc (keep_cnt, sizeof *var_renaming); |
425 |
for (i = 0; i < keep_cnt; i++) |
for (i = 0; i < keep_cnt; i++) |
426 |
{ |
{ |
427 |
var_renaming[i].var = keep_vars[i]; |
var_renaming[i].var = keep_vars[i]; |
486 |
/* Record the old names of variables to rename. After |
/* Record the old names of variables to rename. After |
487 |
variables are deleted, we can't depend on the variables to |
variables are deleted, we can't depend on the variables to |
488 |
still exist, but we can still look them up by name. */ |
still exist, but we can still look them up by name. */ |
489 |
rename_old_names = xmalloc (vm->rename_cnt * sizeof *rename_old_names); |
rename_old_names = xnmalloc (vm->rename_cnt, sizeof *rename_old_names); |
490 |
for (i = 0; i < vm->rename_cnt; i++) |
for (i = 0; i < vm->rename_cnt; i++) |
491 |
rename_old_names[i] = xstrdup (vm->rename_vars[i]->name); |
rename_old_names[i] = xstrdup (vm->rename_vars[i]->name); |
492 |
|
|
495 |
dict_delete_vars (d, vm->drop_vars, vm->drop_cnt); |
dict_delete_vars (d, vm->drop_vars, vm->drop_cnt); |
496 |
|
|
497 |
/* Compose lists of variables to rename and their new names. */ |
/* Compose lists of variables to rename and their new names. */ |
498 |
rename_vars = xmalloc (vm->rename_cnt * sizeof *rename_vars); |
rename_vars = xnmalloc (vm->rename_cnt, sizeof *rename_vars); |
499 |
rename_new_names = xmalloc (vm->rename_cnt * sizeof *rename_new_names); |
rename_new_names = xnmalloc (vm->rename_cnt, sizeof *rename_new_names); |
500 |
rename_cnt = 0; |
rename_cnt = 0; |
501 |
for (i = 0; i < vm->rename_cnt; i++) |
for (i = 0; i < vm->rename_cnt; i++) |
502 |
{ |
{ |