1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 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/>. */
25 #include <data/file-name.h>
26 #include <language/command.h>
27 #include <language/lexer/lexer.h>
28 #include <language/syntax-file.h>
29 #include <libpspp/getl.h>
30 #include <libpspp/message.h>
31 #include <libpspp/str.h>
37 #define _(msgid) gettext (msgid)
39 static int parse_insert (struct lexer *lexer, char **filename);
43 cmd_include (struct lexer *lexer, struct dataset *ds UNUSED)
45 char *filename = NULL;
46 int status = parse_insert (lexer, &filename);
48 if ( CMD_SUCCESS != status)
53 status = lex_end_of_command (lexer);
55 if ( status == CMD_SUCCESS)
57 struct source_stream *ss = lex_get_source_stream (lexer);
60 getl_include_source (ss, create_syntax_file_source (filename),
61 GETL_BATCH, ERRMODE_STOP);
70 cmd_insert (struct lexer *lexer, struct dataset *ds UNUSED)
72 enum syntax_mode syntax_mode = GETL_INTERACTIVE;
73 enum error_mode error_mode = ERRMODE_CONTINUE;
74 char *filename = NULL;
75 int status = parse_insert (lexer, &filename);
78 if ( CMD_SUCCESS != status)
83 while ( '.' != lex_token (lexer))
85 if (lex_match_id (lexer, "SYNTAX"))
87 lex_match (lexer, '=');
88 if ( lex_match_id (lexer, "INTERACTIVE") )
89 syntax_mode = GETL_INTERACTIVE;
90 else if ( lex_match_id (lexer, "BATCH"))
91 syntax_mode = GETL_BATCH;
95 _("Expecting BATCH or INTERACTIVE after SYNTAX."));
99 else if (lex_match_id (lexer, "CD"))
101 lex_match (lexer, '=');
102 if ( lex_match_id (lexer, "YES") )
106 else if ( lex_match_id (lexer, "NO"))
112 lex_error (lexer, _("Expecting YES or NO after CD."));
116 else if (lex_match_id (lexer, "ERROR"))
118 lex_match (lexer, '=');
119 if ( lex_match_id (lexer, "CONTINUE") )
121 error_mode = ERRMODE_CONTINUE;
123 else if ( lex_match_id (lexer, "STOP"))
125 error_mode = ERRMODE_STOP;
129 lex_error (lexer, _("Expecting CONTINUE or STOP after ERROR."));
136 lex_error (lexer, _("Unexpected token: `%s'."),
137 lex_token_representation (lexer));
143 status = lex_end_of_command (lexer);
145 if ( status == CMD_SUCCESS)
147 struct source_stream *ss = lex_get_source_stream (lexer);
150 getl_include_source (ss, create_syntax_file_source (filename),
156 char *directory = dir_name (filename);
169 parse_insert (struct lexer *lexer, char **filename)
172 char *relative_filename;
174 /* Skip optional FILE=. */
175 if (lex_match_id (lexer, "FILE"))
176 lex_match (lexer, '=');
178 /* File name can be identifier or string. */
179 if (lex_token (lexer) != T_ID && lex_token (lexer) != T_STRING)
181 lex_error (lexer, _("expecting file name"));
185 target_fn = ds_cstr (lex_tokstr (lexer));
188 fn_search_path (target_fn,
189 getl_include_path (lex_get_source_stream (lexer)));
191 if ( ! relative_filename)
193 msg (SE, _("Can't find `%s' in include file search path."),
198 *filename = relative_filename;
199 if (*filename == NULL)
201 msg (SE, _("Unable to open `%s': %s."),
202 relative_filename, strerror (errno));
203 free (relative_filename);