X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Frename-variables.c;h=28af671e8752c87ab7ab812c5df334ecac0070f8;hb=94c6018eaec4ea23eaad0819ca0c3f1b2c15f504;hp=7c3f8bdf996059397fa798938b6f53ccfe038907;hpb=0df9cdd3df66caf4353128feff3008289cda8115;p=pspp diff --git a/src/language/dictionary/rename-variables.c b/src/language/dictionary/rename-variables.c index 7c3f8bdf99..28af671e87 100644 --- a/src/language/dictionary/rename-variables.c +++ b/src/language/dictionary/rename-variables.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2010, 2011, 2015 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2010, 2011, 2015, 2016 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,74 +32,81 @@ #include "gettext.h" #define _(msgid) gettext (msgid) -/* The code for this function is very similar to the code for the - RENAME subcommand of MODIFY VARS. */ int cmd_rename_variables (struct lexer *lexer, struct dataset *ds) { - struct variable **rename_vars = NULL; - char **rename_new_names = NULL; - size_t rename_cnt = 0; + struct variable **vars_to_be_renamed = NULL; + size_t n_vars_to_be_renamed = 0; + + char **new_names = NULL; + size_t n_new_names = 0; + char *err_name; int status = CMD_CASCADING_FAILURE; if (proc_make_temporary_transformations_permanent (ds)) - msg (SE, _("%s may not be used after %s. " - "Temporary transformations will be made permanent."), "RENAME VARS", "TEMPORARY"); + lex_ofs_error (lexer, 0, lex_ofs (lexer) - 1, + _("%s may not be used after %s. " + "Temporary transformations will be made permanent."), + "RENAME VARS", "TEMPORARY"); do { - size_t prev_nv_1 = rename_cnt; - size_t prev_nv_2 = rename_cnt; int opts = PV_APPEND | PV_NO_DUPLICATE; if (!lex_match (lexer, T_LPAREN)) opts |= PV_SINGLE; + int start_ofs = lex_ofs (lexer); if (!parse_variables (lexer, dataset_dict (ds), - &rename_vars, &rename_cnt, opts)) - goto lossage; + &vars_to_be_renamed, &n_vars_to_be_renamed, opts)) + { + goto lossage; + } if (!lex_force_match (lexer, T_EQUALS)) - goto lossage; + { + goto lossage; + } if (!parse_DATA_LIST_vars (lexer, dataset_dict (ds), - &rename_new_names, &prev_nv_1, opts)) - goto lossage; - if (prev_nv_1 != rename_cnt) + &new_names, &n_new_names, opts)) + { + goto lossage; + } + int end_ofs = lex_ofs (lexer) - 1; + if (n_new_names != n_vars_to_be_renamed) { - size_t i; - - msg (SE, _("Differing number of variables in old name list " - "(%zu) and in new name list (%zu)."), - rename_cnt - prev_nv_2, prev_nv_1 - prev_nv_2); - for (i = 0; i < prev_nv_1; i++) - free (rename_new_names[i]); - free (rename_new_names); - rename_new_names = NULL; + lex_ofs_error (lexer, start_ofs, end_ofs, + _("Differing number of variables in old name list " + "(%zu) and in new name list (%zu)."), + n_vars_to_be_renamed, n_new_names); goto lossage; } if (!(opts & PV_SINGLE) && !lex_force_match (lexer, T_RPAREN)) - goto lossage; + { + goto lossage; + } } while (lex_token (lexer) != T_ENDCMD); if (!dict_rename_vars (dataset_dict (ds), - rename_vars, rename_new_names, rename_cnt, + vars_to_be_renamed, new_names, n_new_names, &err_name)) { - msg (SE, _("Renaming would duplicate variable name %s."), err_name); + lex_ofs_error (lexer, 2, lex_ofs (lexer) - 1, + _("Renaming would duplicate variable name %s."), err_name); goto lossage; } status = CMD_SUCCESS; lossage: - free (rename_vars); - if (rename_new_names != NULL) + free (vars_to_be_renamed); + if (new_names != NULL) { size_t i; - for (i = 0; i < rename_cnt; i++) - free (rename_new_names[i]); - free (rename_new_names); + for (i = 0; i < n_new_names; ++i) + free (new_names[i]); + free (new_names); } return status; }