X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Finclude.c;h=9f666747db6b99fe129ac24e7680beab3693eab1;hb=888d0f91d57e0c3c5a4206c30ac71eb87bf44227;hp=aab817cb5b07e5d2cb1cd79da2a069e1b9704331;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c index aab817cb5b..9f666747db 100644 --- a/src/language/utilities/include.c +++ b/src/language/utilities/include.c @@ -20,31 +20,51 @@ #include #include #include -#include "alloc.h" -#include "command.h" -#include "message.h" -#include "line-buffer.h" -#include "lexer.h" -#include "str.h" +#include +#include +#include +#include +#include +#include +#include +#include + #include "gettext.h" #define _(msgid) gettext (msgid) int -cmd_include (void) +cmd_include (struct lexer *lexer, struct dataset *ds UNUSED) { + struct source_stream *ss; + char *found_fn; + char *target_fn; + /* Skip optional FILE=. */ - if (lex_match_id ("FILE")) - lex_match ('='); + if (lex_match_id (lexer, "FILE")) + lex_match (lexer, '='); - /* Filename can be identifier or string. */ - if (token != T_ID && token != T_STRING) + /* File name can be identifier or string. */ + if (lex_token (lexer) != T_ID && lex_token (lexer) != T_STRING) { - lex_error (_("expecting filename")); + lex_error (lexer, _("expecting file name")); return CMD_CASCADING_FAILURE; } - getl_include_syntax_file (ds_c_str (&tokstr)); - lex_get (); - return lex_end_of_command (); + target_fn = ds_cstr (lex_tokstr (lexer)); + + ss = lex_get_source_stream (lexer); + found_fn = fn_search_path (target_fn, getl_include_path ( ss ), NULL); + + if (found_fn != NULL) + { + getl_include_source (ss, create_syntax_file_source (found_fn)); + free (found_fn); + } + else + msg (SE, _("Can't find `%s' in include file search path."), + target_fn); + + lex_get (lexer); + return lex_end_of_command (lexer); }