1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "sort-criteria.h"
24 #include <data/procedure.h>
25 #include <data/settings.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/lexer/lexer.h>
29 #include <libpspp/message.h>
30 #include <data/case-ordering.h>
31 #include <math/sort.h>
32 #include <sys/types.h>
37 #define _(msgid) gettext (msgid)
40 /* Performs the SORT CASES procedures. */
42 cmd_sort_cases (struct lexer *lexer, struct dataset *ds)
44 struct case_ordering *ordering;
45 struct casereader *output;
48 lex_match (lexer, T_BY);
50 proc_cancel_temporary_transformations (ds);
51 ordering = parse_case_ordering (lexer, dataset_dict (ds), NULL);
53 return CMD_CASCADING_FAILURE;
55 if (settings_get_testing_mode () && lex_match (lexer, '/'))
57 if (!lex_force_match_id (lexer, "BUFFERS") || !lex_match (lexer, '=')
58 || !lex_force_int (lexer))
61 min_buffers = max_buffers = lex_integer (lexer);
64 msg (SE, _("Buffer limit must be at least 2."));
71 proc_discard_output (ds);
72 output = sort_execute (proc_open (ds), ordering);
74 ok = proc_commit (ds);
75 ok = proc_set_active_file_data (ds, output) && ok;
79 max_buffers = INT_MAX;
81 case_ordering_destroy (ordering);
82 return ok ? lex_end_of_command (lexer) : CMD_CASCADING_FAILURE;