1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "sort-criteria.h"
26 #include <data/procedure.h>
27 #include <data/settings.h>
28 #include <data/variable.h>
29 #include <language/command.h>
30 #include <language/lexer/lexer.h>
31 #include <libpspp/alloc.h>
32 #include <libpspp/message.h>
33 #include <data/case-ordering.h>
34 #include <math/sort.h>
35 #include <sys/types.h>
38 #define _(msgid) gettext (msgid)
41 /* Performs the SORT CASES procedures. */
43 cmd_sort_cases (struct lexer *lexer, struct dataset *ds)
45 struct case_ordering *ordering;
46 struct casereader *output;
49 lex_match (lexer, T_BY);
51 proc_cancel_temporary_transformations (ds);
52 ordering = parse_case_ordering (lexer, dataset_dict (ds), NULL);
54 return CMD_CASCADING_FAILURE;
56 if (get_testing_mode () && lex_match (lexer, '/'))
58 if (!lex_force_match_id (lexer, "BUFFERS") || !lex_match (lexer, '=')
59 || !lex_force_int (lexer))
62 min_buffers = max_buffers = lex_integer (lexer);
65 msg (SE, _("Buffer limit must be at least 2."));
72 proc_discard_output (ds);
73 output = sort_execute (proc_open (ds), ordering);
75 ok = proc_commit (ds);
76 ok = proc_set_active_file_data (ds, output) && ok;
80 max_buffers = INT_MAX;
82 case_ordering_destroy (ordering);
83 return ok ? lex_end_of_command (lexer) : CMD_CASCADING_FAILURE;