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/>. */
20 #include <language/command.h>
21 #include <libpspp/message.h>
22 #include <libpspp/getl.h>
23 #include <language/syntax-file.h>
24 #include <language/lexer/lexer.h>
25 #include <libpspp/str.h>
26 #include <data/file-name.h>
32 #define _(msgid) gettext (msgid)
34 static int parse_insert (struct lexer *lexer, char **filename);
38 cmd_include (struct lexer *lexer, struct dataset *ds UNUSED)
40 char *filename = NULL;
41 int status = parse_insert (lexer, &filename);
43 if ( CMD_SUCCESS != status)
48 status = lex_end_of_command (lexer);
50 if ( status == CMD_SUCCESS)
52 struct source_stream *ss = lex_get_source_stream (lexer);
55 getl_include_source (ss, create_syntax_file_source (filename),
56 GETL_BATCH, ERRMODE_STOP);
65 cmd_insert (struct lexer *lexer, struct dataset *ds UNUSED)
67 enum syntax_mode syntax_mode = GETL_INTERACTIVE;
68 enum error_mode error_mode = ERRMODE_CONTINUE;
69 char *filename = NULL;
70 int status = parse_insert (lexer, &filename);
73 if ( CMD_SUCCESS != status)
78 while ( '.' != lex_token (lexer))
80 if (lex_match_id (lexer, "SYNTAX"))
82 lex_match (lexer, '=');
83 if ( lex_match_id (lexer, "INTERACTIVE") )
84 syntax_mode = GETL_INTERACTIVE;
85 else if ( lex_match_id (lexer, "BATCH"))
86 syntax_mode = GETL_BATCH;
90 _("Expecting BATCH or INTERACTIVE after SYNTAX."));
94 else if (lex_match_id (lexer, "CD"))
96 lex_match (lexer, '=');
97 if ( lex_match_id (lexer, "YES") )
101 else if ( lex_match_id (lexer, "NO"))
107 lex_error (lexer, _("Expecting YES or NO after CD."));
111 else if (lex_match_id (lexer, "ERROR"))
113 lex_match (lexer, '=');
114 if ( lex_match_id (lexer, "CONTINUE") )
116 error_mode = ERRMODE_CONTINUE;
118 else if ( lex_match_id (lexer, "STOP"))
120 error_mode = ERRMODE_STOP;
124 lex_error (lexer, _("Expecting CONTINUE or STOP after ERROR."));
131 lex_error (lexer, _("Unexpected token: `%s'."),
132 lex_token_representation (lexer));
138 status = lex_end_of_command (lexer);
140 if ( status == CMD_SUCCESS)
142 struct source_stream *ss = lex_get_source_stream (lexer);
145 getl_include_source (ss, create_syntax_file_source (filename),
151 char *directory = dir_name (filename);
164 parse_insert (struct lexer *lexer, char **filename)
167 char *relative_filename;
169 /* Skip optional FILE=. */
170 if (lex_match_id (lexer, "FILE"))
171 lex_match (lexer, '=');
173 /* File name can be identifier or string. */
174 if (lex_token (lexer) != T_ID && lex_token (lexer) != T_STRING)
176 lex_error (lexer, _("expecting file name"));
180 target_fn = ds_cstr (lex_tokstr (lexer));
183 fn_search_path (target_fn,
184 getl_include_path (lex_get_source_stream (lexer)));
186 if ( ! relative_filename)
188 msg (SE, _("Can't find `%s' in include file search path."),
193 *filename = relative_filename;