1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2010, 2012 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/>. */
19 #include "data/case.h"
20 #include "data/dataset.h"
21 #include "data/dictionary.h"
22 #include "language/command.h"
23 #include "language/data-io/file-handle.h"
24 #include "language/lexer/lexer.h"
25 #include "libpspp/pxd.h"
27 #include "gl/xalloc.h"
30 #define _(msgid) gettext (msgid)
33 cmd_save_session (struct lexer *lexer, struct dataset *ds)
35 struct file_handle *handle;
36 struct pxd_object *obj;
40 if (!lex_force_match_id (lexer, "OUTFILE"))
42 lex_match (lexer, '=');
44 handle = fh_parse (lexer, FH_REF_FILE, dataset_session (ds));
48 pxd = pxd_open (fh_get_file_name (handle), true);
49 obj = dict_save (dataset_dict (ds), pxd);
50 pxd_get_root (pxd, &root);
51 pxd_swap_root (pxd, &root, obj);
58 cmd_get_session (struct lexer *lexer, struct dataset *ds)
60 struct file_handle *handle;
61 struct pxd_object *obj;
65 if (lex_match_id (lexer, "FILE"))
66 lex_match (lexer, '=');
68 handle = fh_parse (lexer, FH_REF_FILE, dataset_session (ds));
72 pxd = pxd_open (fh_get_file_name (handle), false);
73 pxd_get_root (pxd, &root);
74 obj = pxd_fetch (pxd, &root);
75 dict_destroy (dict_load (obj, pxd));