X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fsort-cases.c;h=cecdce27eb19a1cd8c8614d92500c473ac38c4b3;hb=2be9bee9da6a2ce27715e58128569594319abfa2;hp=156c5b42ad92de4f2e1cd920e9b04971c497d235;hpb=b0bf9b1b0f727fafac4296a048e3f45db5936f81;p=pspp-builds.git diff --git a/src/language/stats/sort-cases.c b/src/language/stats/sort-cases.c index 156c5b42..cecdce27 100644 --- a/src/language/stats/sort-cases.c +++ b/src/language/stats/sort-cases.c @@ -1,81 +1,83 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2010, 2011 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 the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + 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 3 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. + 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. */ + along with this program. If not, see . */ #include #include -#include #include - -#include "sort-criteria.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include "data/dataset.h" +#include "data/settings.h" +#include "data/subcase.h" +#include "data/variable.h" +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "language/stats/sort-criteria.h" +#include "libpspp/message.h" +#include "math/sort.h" + +#include "gl/xalloc.h" + #include "gettext.h" #define _(msgid) gettext (msgid) /* Performs the SORT CASES procedures. */ int -cmd_sort_cases (void) +cmd_sort_cases (struct lexer *lexer, struct dataset *ds) { - struct sort_criteria *criteria; - bool success = false; + struct subcase ordering; + struct casereader *output; + bool ok = false; - lex_match (T_BY); + lex_match (lexer, T_BY); - criteria = sort_parse_criteria (default_dict, NULL, NULL, NULL, NULL); - if (criteria == NULL) + proc_cancel_temporary_transformations (ds); + subcase_init_empty (&ordering); + if (!parse_sort_criteria (lexer, dataset_dict (ds), &ordering, NULL, NULL)) return CMD_CASCADING_FAILURE; - if (get_testing_mode () && lex_match ('/')) + if (settings_get_testing_mode () && lex_match (lexer, T_SLASH)) { - if (!lex_force_match_id ("BUFFERS") || !lex_match ('=') - || !lex_force_int ()) + if (!lex_force_match_id (lexer, "BUFFERS") || !lex_match (lexer, T_EQUALS) + || !lex_force_int (lexer)) goto done; - min_buffers = max_buffers = lex_integer (); - allow_internal_sort = false; - if (max_buffers < 2) + min_buffers = max_buffers = lex_integer (lexer); + if (max_buffers < 2) { msg (SE, _("Buffer limit must be at least 2.")); goto done; } - lex_get (); + lex_get (lexer); } - success = sort_active_file_in_place (criteria); + proc_discard_output (ds); + output = sort_execute (proc_open (ds), &ordering); + ok = proc_commit (ds); + ok = proc_set_active_file_data (ds, output) && ok; done: min_buffers = 64; max_buffers = INT_MAX; - allow_internal_sort = true; - - sort_destroy_criteria (criteria); - return success ? lex_end_of_command () : CMD_CASCADING_FAILURE; + + subcase_destroy (&ordering); + return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE; }