1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2007 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/>. */
20 #include <libpspp/message.h>
21 #include <data/gnumeric-reader.h>
23 #include <language/command.h>
24 #include <language/lexer/lexer.h>
26 #include <data/procedure.h>
29 #define _(msgid) gettext (msgid)
30 #define N_(msgid) (msgid)
32 static int parse_get_gnm (struct lexer *lexer, struct dataset *);
35 cmd_get_data (struct lexer *lexer, struct dataset *ds)
37 lex_force_match (lexer, '/');
39 if (!lex_force_match_id (lexer, "TYPE"))
42 lex_force_match (lexer, '=');
44 if (lex_match_id (lexer, "GNM"))
45 return parse_get_gnm (lexer, ds);
47 msg (SE, _("Unsupported TYPE %s"), lex_tokid (lexer));
53 parse_get_gnm (struct lexer *lexer, struct dataset *ds)
55 struct gnumeric_read_info gri = {NULL, NULL, NULL, 1, true, -1};
57 lex_force_match (lexer, '/');
59 if (!lex_force_match_id (lexer, "FILE"))
62 lex_force_match (lexer, '=');
64 if (!lex_force_string (lexer))
67 gri.file_name = strdup (ds_cstr (lex_tokstr (lexer)));
71 while (lex_match (lexer, '/') )
73 if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
75 lex_match (lexer, '=');
76 gri.asw = lex_integer (lexer);
78 else if (lex_match_id (lexer, "SHEET"))
80 lex_match (lexer, '=');
81 if (lex_match_id (lexer, "NAME"))
83 if ( ! lex_force_string (lexer) )
86 gri.sheet_name = strdup (ds_cstr (lex_tokstr (lexer)));
89 else if (lex_match_id (lexer, "INDEX"))
91 gri.sheet_index = lex_integer (lexer);
96 else if (lex_match_id (lexer, "CELLRANGE"))
98 lex_match (lexer, '=');
100 if (lex_match_id (lexer, "FULL"))
102 gri.cell_range = NULL;
103 lex_put_back (lexer, T_ID);
105 else if (lex_match_id (lexer, "RANGE"))
107 if ( ! lex_force_string (lexer) )
110 gri.cell_range = strdup (ds_cstr (lex_tokstr (lexer)));
115 else if (lex_match_id (lexer, "READNAMES"))
117 lex_match (lexer, '=');
119 if ( lex_match_id (lexer, "ON"))
121 gri.read_names = true;
123 else if (lex_match_id (lexer, "OFF"))
125 gri.read_names = false;
129 lex_put_back (lexer, T_ID);
133 printf ("Unknown data file type \"\%s\"\n", lex_tokid (lexer));
140 struct dictionary *dict = NULL;
141 struct casereader *reader = gnumeric_open_reader (&gri, &dict);
144 proc_set_active_file (ds, reader, dict);
147 free (gri.file_name);
148 free (gri.sheet_name);
149 free (gri.cell_range);
154 free (gri.file_name);
155 free (gri.sheet_name);
156 free (gri.cell_range);