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 <math/sort.h>
34 #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 sort_criteria *criteria;
47 lex_match (lexer, T_BY);
49 criteria = sort_parse_criteria (lexer, dataset_dict (ds), NULL, NULL, NULL, NULL);
51 return CMD_CASCADING_FAILURE;
53 if (get_testing_mode () && lex_match (lexer, '/'))
55 if (!lex_force_match_id (lexer, "BUFFERS") || !lex_match (lexer, '=')
56 || !lex_force_int (lexer))
59 min_buffers = max_buffers = lex_integer (lexer);
60 allow_internal_sort = false;
63 msg (SE, _("Buffer limit must be at least 2."));
70 success = sort_active_file_in_place (ds, criteria);
74 max_buffers = INT_MAX;
75 allow_internal_sort = true;
77 sort_destroy_criteria (criteria);
78 return success ? lex_end_of_command (lexer) : CMD_CASCADING_FAILURE;