OSDN Git Service

PR fortran/20811
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Nov 2005 12:51:41 +0000 (12:51 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Nov 2005 12:51:41 +0000 (12:51 +0000)
* scanner.c (gfc_open_included_file): Add an extra include_cwd
argument. Only include files in the current working directory if
its value is true.
* gfortran.h: Change prototype for gfc_open_included_file.
(load_file): Don't search for include files in the current working
directory.
* options.c (gfc_post_options): Add the directory of the source file
to the list of paths for included files.
* module.c (gfc_use_module): Look for module files in the current
directory.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107120 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/module.c
gcc/fortran/options.c
gcc/fortran/scanner.c

index 7e22961..6ed025b 100644 (file)
@@ -1,3 +1,17 @@
+2005-11-17  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/20811
+       * scanner.c (gfc_open_included_file): Add an extra include_cwd
+       argument. Only include files in the current working directory if
+       its value is true.
+       * gfortran.h: Change prototype for gfc_open_included_file.
+       (load_file): Don't search for include files in the current working
+       directory.
+       * options.c (gfc_post_options): Add the directory of the source file
+       to the list of paths for included files.
+       * module.c (gfc_use_module): Look for module files in the current
+       directory.
+
 2005-11-16  Alan Modra  <amodra@bigpond.net.au>
 
        PR fortran/24096
 2005-11-16  Alan Modra  <amodra@bigpond.net.au>
 
        PR fortran/24096
index a0d0e8c..95794a5 100644 (file)
@@ -1548,7 +1548,7 @@ void gfc_scanner_init_1 (void);
 
 void gfc_add_include_path (const char *);
 void gfc_release_include_path (void);
 
 void gfc_add_include_path (const char *);
 void gfc_release_include_path (void);
-FILE *gfc_open_included_file (const char *);
+FILE *gfc_open_included_file (const char *, bool);
 
 int gfc_at_end (void);
 int gfc_at_eof (void);
 
 int gfc_at_end (void);
 int gfc_at_eof (void);
index 6f978aa..8f1ab73 100644 (file)
@@ -3741,7 +3741,7 @@ gfc_use_module (void)
   strcpy (filename, module_name);
   strcat (filename, MODULE_EXTENSION);
 
   strcpy (filename, module_name);
   strcat (filename, MODULE_EXTENSION);
 
-  module_fp = gfc_open_included_file (filename);
+  module_fp = gfc_open_included_file (filename, true);
   if (module_fp == NULL)
     gfc_fatal_error ("Can't open module file '%s' for reading at %C: %s",
                     filename, strerror (errno));
   if (module_fp == NULL)
     gfc_fatal_error ("Can't open module file '%s' for reading at %C: %s",
                     filename, strerror (errno));
index ebce409..a39876b 100644 (file)
@@ -172,6 +172,8 @@ bool
 gfc_post_options (const char **pfilename)
 {
   const char *filename = *pfilename;
 gfc_post_options (const char **pfilename)
 {
   const char *filename = *pfilename;
+  char *source_path;
+  int i;
 
   /* Verify the input file name.  */
   if (!filename || strcmp (filename, "-") == 0)
 
   /* Verify the input file name.  */
   if (!filename || strcmp (filename, "-") == 0)
@@ -181,6 +183,21 @@ gfc_post_options (const char **pfilename)
 
   gfc_source_file = filename;
 
 
   gfc_source_file = filename;
 
+  /* Adds the path where the source file is to the list of include files.  */
+
+  i = strlen(gfc_source_file);
+  while (i > 0 && !IS_DIR_SEPARATOR(gfc_source_file[i]))
+    i--;
+  if (i != 0)
+    {
+      source_path = alloca (i + 1);
+      memcpy (source_path, gfc_source_file, i);
+      source_path[i] = 0;
+      gfc_add_include_path (source_path);
+    }
+  else
+    gfc_add_include_path (".");
+
   /* Decide which form the file will be read in as.  */
 
   if (gfc_option.source_form != FORM_UNKNOWN)
   /* Decide which form the file will be read in as.  */
 
   if (gfc_option.source_form != FORM_UNKNOWN)
index 738e172..8835761 100644 (file)
@@ -159,18 +159,22 @@ gfc_release_include_path (void)
 }
 
 /* Opens file for reading, searching through the include directories
 }
 
 /* Opens file for reading, searching through the include directories
-   given if necessary.  */
+   given if necessary.  If the include_cwd argument is true, we try
+   to open the file in the current directory first.  */
 
 FILE *
 
 FILE *
-gfc_open_included_file (const char *name)
+gfc_open_included_file (const char *name, const bool include_cwd)
 {
   char *fullname;
   gfc_directorylist *p;
   FILE *f;
 
 {
   char *fullname;
   gfc_directorylist *p;
   FILE *f;
 
-  f = gfc_open_file (name);
-  if (f != NULL)
-    return f;
+  if (include_cwd)
+    {
+      f = gfc_open_file (name);
+      if (f != NULL)
+       return f;
+    }
 
   for (p = include_dirs; p; p = p->next)
     {
 
   for (p = include_dirs; p; p = p->next)
     {
@@ -1034,7 +1038,7 @@ load_file (const char *filename, bool initial)
     }
   else
     {
     }
   else
     {
-      input = gfc_open_included_file (filename);
+      input = gfc_open_included_file (filename, false);
       if (input == NULL)
        {
          gfc_error_now ("Can't open included file '%s'", filename);
       if (input == NULL)
        {
          gfc_error_now ("Can't open included file '%s'", filename);