Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / language / utilities / include.c
index aab817cb5b07e5d2cb1cd79da2a069e1b9704331..0ef9d463d7393b1488dc0d768d012671dcde2b84 100644 (file)
@@ -1,50 +1,67 @@
-/* PSPP - computes sample statistics.
+/* PSPP - a program for statistical analysis.
    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
-   Written by Ben Pfaff <blp@gnu.org>.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 #include <ctype.h>
 #include <stdlib.h>
-#include "alloc.h"
-#include "command.h"
-#include "message.h"
-#include "line-buffer.h"
-#include "lexer.h"
-#include "str.h"
+#include <libpspp/alloc.h>
+#include <language/command.h>
+#include <libpspp/message.h>
+#include <libpspp/getl.h>
+#include <language/syntax-file.h>
+#include <language/lexer/lexer.h>
+#include <libpspp/str.h>
+#include <data/file-name.h>
+
 
 #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 ));
+
+  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);
 }