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/>. */
21 #include <libpspp/message.h>
22 #include <data/gnumeric-reader.h>
24 #include <language/command.h>
25 #include <language/lexer/lexer.h>
27 #include <data/procedure.h>
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) (msgid)
33 static int parse_get_gnm (struct lexer *lexer, struct dataset *);
36 parse_get_data_command (struct lexer *lexer, struct dataset *ds)
38 lex_force_match (lexer, '/');
40 if (!lex_force_match_id (lexer, "TYPE"))
43 lex_force_match (lexer, '=');
45 if (lex_match_id (lexer, "GNM"))
46 return parse_get_gnm (lexer, ds);
48 msg (SE, _("Unsupported TYPE %s"), lex_tokid (lexer));
54 parse_get_gnm (struct lexer *lexer, struct dataset *ds)
56 struct gnumeric_read_info gri = {NULL, NULL, NULL, 1, true, -1};
58 lex_force_match (lexer, '/');
60 if (!lex_force_match_id (lexer, "FILE"))
63 lex_force_match (lexer, '=');
65 if (!lex_force_string (lexer))
68 gri.file_name = strdup (ds_cstr (lex_tokstr (lexer)));
72 while (lex_match (lexer, '/') )
74 if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
76 lex_match (lexer, '=');
77 gri.asw = lex_integer (lexer);
79 else if (lex_match_id (lexer, "SHEET"))
81 lex_match (lexer, '=');
82 if (lex_match_id (lexer, "NAME"))
84 if ( ! lex_force_string (lexer) )
87 gri.sheet_name = strdup (ds_cstr (lex_tokstr (lexer)));
90 else if (lex_match_id (lexer, "INDEX"))
92 gri.sheet_index = lex_integer (lexer);
97 else if (lex_match_id (lexer, "CELLRANGE"))
99 lex_match (lexer, '=');
101 if (lex_match_id (lexer, "FULL"))
103 gri.cell_range = NULL;
104 lex_put_back (lexer, T_ID);
106 else if (lex_match_id (lexer, "RANGE"))
108 if ( ! lex_force_string (lexer) )
111 gri.cell_range = strdup (ds_cstr (lex_tokstr (lexer)));
116 else if (lex_match_id (lexer, "READNAMES"))
118 lex_match (lexer, '=');
120 if ( lex_match_id (lexer, "ON"))
122 gri.read_names = true;
124 else if (lex_match_id (lexer, "OFF"))
126 gri.read_names = false;
130 lex_put_back (lexer, T_ID);
134 printf ("Unknown data file type \"\%s\"\n", lex_tokid (lexer));
141 struct dictionary *dict = NULL;
142 struct casereader *reader = gnumeric_open_reader (&gri, &dict);
145 proc_set_active_file (ds, reader, dict);
148 free (gri.file_name);
149 free (gri.sheet_name);
150 free (gri.cell_range);
155 free (gri.file_name);
156 free (gri.sheet_name);
157 free (gri.cell_range);