1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "dictionary.h"
32 /* The code for this function is very similar to the code for the
33 RENAME subcommand of MODIFY VARS. */
35 cmd_rename_variables (void)
37 struct variable **rename_vars = NULL;
38 char **rename_new_names = NULL;
42 int status = CMD_FAILURE;
48 msg (SE, _("RENAME VARS may not be used after TEMPORARY. "
49 "Temporary transformations will be made permanent."));
55 int prev_nv_1 = rename_cnt;
56 int prev_nv_2 = rename_cnt;
60 msg (SE, _("`(' expected."));
63 if (!parse_variables (default_dict, &rename_vars, &rename_cnt,
64 PV_APPEND | PV_NO_DUPLICATE))
68 msg (SE, _("`=' expected between lists of new and old variable names."));
71 if (!parse_DATA_LIST_vars (&rename_new_names, &prev_nv_1, PV_APPEND))
73 if (prev_nv_1 != rename_cnt)
75 msg (SE, _("Differing number of variables in old name list "
76 "(%d) and in new name list (%d)."),
77 rename_cnt - prev_nv_2, prev_nv_1 - prev_nv_2);
78 for (i = 0; i < prev_nv_1; i++)
79 free (rename_new_names[i]);
80 free (rename_new_names);
81 rename_new_names = NULL;
86 msg (SE, _("`)' expected after variable names."));
92 if (!dict_rename_vars (default_dict,
93 rename_vars, rename_new_names, rename_cnt,
96 msg (SE, _("Renaming would duplicate variable name %s."), err_name);
100 status = CMD_SUCCESS;
104 if (rename_new_names != NULL)
106 for (i = 0; i < rename_cnt; i++)
107 free (rename_new_names[i]);
108 free (rename_new_names);