1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "sort-criteria.h"
27 #include <data/procedure.h>
28 #include <data/settings.h>
29 #include <data/variable.h>
30 #include <language/command.h>
31 #include <language/lexer/lexer.h>
32 #include <libpspp/alloc.h>
33 #include <libpspp/message.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 sort_criteria *criteria;
48 lex_match (lexer, T_BY);
50 criteria = sort_parse_criteria (lexer, dataset_dict (ds), NULL, NULL, NULL, NULL);
52 return CMD_CASCADING_FAILURE;
54 if (get_testing_mode () && lex_match (lexer, '/'))
56 if (!lex_force_match_id (lexer, "BUFFERS") || !lex_match (lexer, '=')
57 || !lex_force_int (lexer))
60 min_buffers = max_buffers = lex_integer (lexer);
61 allow_internal_sort = false;
64 msg (SE, _("Buffer limit must be at least 2."));
71 success = sort_active_file_in_place (ds, criteria);
75 max_buffers = INT_MAX;
76 allow_internal_sort = true;
78 sort_destroy_criteria (criteria);
79 return success ? lex_end_of_command (lexer) : CMD_CASCADING_FAILURE;