X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fmodify-variables.c;h=ab73bbb8990d7ded61c0701988b07c47f24b3873;hb=b078357653b9eebbba49a088c81c3dd935b58698;hp=90296b7bb09fbfb1867ff1bea15cd650b9c2dc54;hpb=25956c20603b69ef9147bab328b5281ce76c798b;p=pspp diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index 90296b7bb0..ab73bbb899 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -26,7 +26,6 @@ #include "language/lexer/variable-parser.h" #include "libpspp/array.h" #include "libpspp/assertion.h" -#include "libpspp/bit-vector.h" #include "libpspp/compiler.h" #include "libpspp/i18n.h" #include "libpspp/message.h" @@ -154,7 +153,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) { if (!lex_match (lexer, T_LPAREN)) { - lex_error_expecting (lexer, "`('", NULL_SENTINEL); + lex_error_expecting (lexer, "`('"); free (v); goto done; } @@ -166,13 +165,17 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) } if (!lex_match (lexer, T_RPAREN)) { - lex_error_expecting (lexer, "`)'", NULL_SENTINEL); + lex_error_expecting (lexer, "`)'"); free (v); goto done; } } - sort (&v[prev_nv], nv - prev_nv, sizeof *v, - compare_variables_given_ordering, &ordering); + + if (!ordering.positional) + sort (&v[prev_nv], nv - prev_nv, sizeof *v, + compare_variables_given_ordering, &ordering); + else if (!ordering.forward) + reverse_array(&v[prev_nv], nv - prev_nv, sizeof *v); } while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD); @@ -197,7 +200,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) if (!lex_match (lexer, T_LPAREN)) { - lex_error_expecting (lexer, "`('", NULL_SENTINEL); + lex_error_expecting (lexer, "`('"); goto done; } if (!parse_variables (lexer, dataset_dict (ds), @@ -206,7 +209,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) goto done; if (!lex_match (lexer, T_EQUALS)) { - lex_error_expecting (lexer, "`='", NULL_SENTINEL); + lex_error_expecting (lexer, "`='"); goto done; } @@ -226,7 +229,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) } if (!lex_match (lexer, T_RPAREN)) { - lex_error_expecting (lexer, "`)'", NULL_SENTINEL); + lex_error_expecting (lexer, "`)'"); goto done; } } @@ -292,7 +295,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) "not be given in conjunction with the %s " "subcommand."), "DROP", "KEEP" - ); + ); goto done; } already_encountered |= 4; @@ -303,6 +306,14 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) goto done; vm.drop_vars = drop_vars; vm.n_drop = n_drop; + + if (n_drop == dict_get_var_cnt (dataset_dict (ds))) + { + msg (SE, _("%s may not be used to delete all variables " + "from the active dataset dictionary. " + "Use %s instead."), "MODIFY VARS", "NEW FILE"); + goto done; + } } else if (lex_match_id (lexer, "MAP")) { @@ -328,7 +339,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) break; if (lex_token (lexer) != T_SLASH) { - lex_error_expecting (lexer, "`/'", "`.'", NULL_SENTINEL); + lex_error_expecting (lexer, "`/'", "`.'"); goto done; } lex_get (lexer); @@ -349,8 +360,9 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) done: free (vm.reorder_vars); free (vm.rename_vars); - for (size_t i = 0; i < vm.n_rename; i++) - free (vm.new_names[i]); + if (vm.new_names) + for (size_t i = 0; i < vm.n_rename; i++) + free (vm.new_names[i]); free (vm.new_names); free (vm.drop_vars); return ret_code;