From b09b3485e28fba1b07980fd5a5eb6466486b5c07 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 22 Dec 2006 04:38:22 +0000 Subject: [PATCH] Implement DELETE VARIABLES. --- doc/variables.texi | 22 +++++++- src/language/ChangeLog | 4 ++ src/language/command.def | 1 + src/language/dictionary/ChangeLog | 7 +++ src/language/dictionary/automake.mk | 1 + src/language/dictionary/delete-variables.c | 64 ++++++++++++++++++++++ src/language/lexer/ChangeLog | 5 ++ src/language/lexer/variable-parser.c | 8 ++- tests/ChangeLog | 5 ++ tests/command/rank.sh | 2 +- 10 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 src/language/dictionary/delete-variables.c diff --git a/doc/variables.texi b/doc/variables.texi index afca8cbf..c2952fbd 100644 --- a/doc/variables.texi +++ b/doc/variables.texi @@ -6,6 +6,7 @@ several utility functions for examining and adjusting them. @menu * ADD VALUE LABELS:: Add value labels to variables. +* DELETE VARIABLES:: Delete variables. * DISPLAY:: Display variable names & descriptions. * DISPLAY VECTORS:: Display a list of vectors. * FORMATS:: Set print and write formats. @@ -25,7 +26,7 @@ several utility functions for examining and adjusting them. * WRITE FORMATS:: Set variable write formats. @end menu -@node ADD VALUE LABELS, DISPLAY, Variable Attributes, Variable Attributes +@node ADD VALUE LABELS, DELETE VARIABLES, Variable Attributes, Variable Attributes @section ADD VALUE LABELS @vindex ADD VALUE LABELS @@ -38,7 +39,24 @@ ADD VALUE LABELS LABELS} (@pxref{VALUE LABELS}), but it does not clear value labels from the variables before adding the ones specified. -@node DISPLAY, DISPLAY VECTORS, ADD VALUE LABELS, Variable Attributes +@node DELETE VARIABLES, DISPLAY, ADD VALUE LABELS, Variable Attributes +@section DELETE VARIABLES +@vindex DELETE VARIABLES + +@display +DELETE VARIABLES var_list. +@end display + +@cmd{DELETE VARIABLES} deletes the specified variables from the +dictionary. It may not be used to delete all variables from the +dictionary; use @cmd{NEW FILE} to do that (@pxref{NEW FILE}). + +@cmd{DELETE VARIABLES} should not used after defining transformations +and before executing a procedure. If it is used in such a context, it +causes the data to be read. If it is used while @cmd{TEMPORARY} is in +effect, it causes the temporary transformations to become permanent. + +@node DISPLAY, DISPLAY VECTORS, DELETE VARIABLES, Variable Attributes @section DISPLAY @vindex DISPLAY diff --git a/src/language/ChangeLog b/src/language/ChangeLog index 215740fa..47d3f375 100644 --- a/src/language/ChangeLog +++ b/src/language/ChangeLog @@ -1,3 +1,7 @@ +Wed Dec 13 21:02:51 2006 Ben Pfaff + + * command.def: Add DELETE VARS. + Sat Dec 16 22:15:55 2006 Ben Pfaff Make it possible to pull cases from the active file with a diff --git a/src/language/command.def b/src/language/command.def index 98909044..a8d835ed 100644 --- a/src/language/command.def +++ b/src/language/command.def @@ -94,6 +94,7 @@ DEF_CMD (S_DATA, F_KEEP_FINAL_TOKEN, "BEGIN DATA", cmd_begin_data) DEF_CMD (S_DATA, 0, "CORRELATIONS", cmd_correlations) DEF_CMD (S_DATA, 0, "COUNT", cmd_count) DEF_CMD (S_DATA, 0, "CROSSTABS", cmd_crosstabs) +DEF_CMD (S_DATA, 0, "DELETE VARIABLES", cmd_delete_variables) DEF_CMD (S_DATA, 0, "DESCRIPTIVES", cmd_descriptives) DEF_CMD (S_DATA, 0, "EXAMINE", cmd_examine) DEF_CMD (S_DATA, 0, "EXECUTE", cmd_execute) diff --git a/src/language/dictionary/ChangeLog b/src/language/dictionary/ChangeLog index 0d6bf8d3..3d7d0baf 100644 --- a/src/language/dictionary/ChangeLog +++ b/src/language/dictionary/ChangeLog @@ -1,3 +1,10 @@ +Wed Dec 13 20:59:54 2006 Ben Pfaff + + * automake.mk: Add delete-variables.c + + * delete-variables.c (cmd_delete_variables): New function, in new + file. + Sun Dec 10 13:55:58 2006 Ben Pfaff * sys-file-info.c (cmd_sysfile_info): Report floating-point format diff --git a/src/language/dictionary/automake.mk b/src/language/dictionary/automake.mk index 92e5fddd..a33a84f9 100644 --- a/src/language/dictionary/automake.mk +++ b/src/language/dictionary/automake.mk @@ -2,6 +2,7 @@ language_dictionary_sources = \ src/language/dictionary/apply-dictionary.c \ + src/language/dictionary/delete-variables.c \ src/language/dictionary/formats.c \ src/language/dictionary/missing-values.c \ src/language/dictionary/modify-variables.c \ diff --git a/src/language/dictionary/delete-variables.c b/src/language/dictionary/delete-variables.c new file mode 100644 index 00000000..b9cbe70d --- /dev/null +++ b/src/language/dictionary/delete-variables.c @@ -0,0 +1,64 @@ +/* PSPP - computes sample statistics. + Copyright (C) 2006 Free Software Foundation, Inc. + Written by Ben Pfaff . + + 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 the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#include + +#include + +#include +#include +#include +#include +#include + +#include "gettext.h" +#define _(msgid) gettext (msgid) + +/* Performs DELETE VARIABLES command. */ +int +cmd_delete_variables (struct lexer *lexer, struct dataset *ds) +{ + struct variable **vars; + size_t var_cnt; + + if (proc_make_temporary_transformations_permanent (ds)) + msg (SE, _("DELETE VARIABLES may not be used after TEMPORARY. " + "Temporary transformations will be made permanent.")); + + if (!parse_variables (lexer, dataset_dict (ds), &vars, &var_cnt, PV_NONE)) + goto error; + if (var_cnt == dict_get_var_cnt (dataset_dict (ds))) + { + msg (SE, _("DELETE VARIABLES may not be used to delete all variables " + "from the active file dictionary. Use NEW FILE instead.")); + goto error; + } + + if (!procedure (ds, NULL, NULL)) + goto error; + + dict_delete_vars (dataset_dict (ds), vars, var_cnt); + free (vars); + + return CMD_SUCCESS; + + error: + free (vars); + return CMD_CASCADING_FAILURE; +} diff --git a/src/language/lexer/ChangeLog b/src/language/lexer/ChangeLog index cfa344d2..a49c2fa9 100644 --- a/src/language/lexer/ChangeLog +++ b/src/language/lexer/ChangeLog @@ -1,3 +1,8 @@ +Wed Dec 13 21:00:24 2006 Ben Pfaff + + * variable-parser.c (parse_variables): If not successful, set + output pointer to NULL and output count to 0. + Sat Dec 9 18:46:11 2006 Ben Pfaff * variable-parser.h: New PV_SAME_WIDTH variable parsing option. diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 60a5539f..731873dc 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -106,8 +106,12 @@ parse_variables (struct lexer *lexer, const struct dictionary *d, vs = var_set_create_from_dict (d); success = parse_var_set_vars (lexer, vs, var, cnt, opts); - if ( success == 0 ) - free ( *var ) ; + if ( success == 0 ) + { + free ( *var ) ; + *var = NULL; + *cnt = 0; + } var_set_destroy (vs); return success; } diff --git a/tests/ChangeLog b/tests/ChangeLog index 2e677919..238e2c35 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +Wed Dec 13 21:00:46 2006 Ben Pfaff + + * command/rank.sh (activity): Use DELETE VAR (which is new) + instead of MODIFY VARS. + Tue Dec 19 08:17:28 2006 Ben Pfaff * command/loop.sh: Test all the possible combinations of clauses. diff --git a/tests/command/rank.sh b/tests/command/rank.sh index 57824652..d64e9758 100755 --- a/tests/command/rank.sh +++ b/tests/command/rank.sh @@ -520,7 +520,7 @@ END DATA. RANK x. -MODIFY VARS /drop ran001 TO ran999. +DELETE VAR ran001 TO ran999. LIST. -- 2.30.2