bd99770
To: vim-dev@vim.org
bd99770
Subject: Patch 7.1.256
bd99770
Fcc: outbox
bd99770
From: Bram Moolenaar <Bram@moolenaar.net>
bd99770
Mime-Version: 1.0
bd99770
Content-Type: text/plain; charset=ISO-8859-1
bd99770
Content-Transfer-Encoding: 8bit
bd99770
------------
bd99770
bd99770
Patch 7.1.256
bd99770
Problem:    findfile() also returns directories.
bd99770
Solution:   Cleanup the code for finding files and directories in a list of
bd99770
            directories.  Remove the ugly global ff_search_ctx.
bd99770
Files:      src/eval.c, src/misc2.c, src/vim.h, src/tag.c
bd99770
bd99770
bd99770
*** ../vim-7.1.255/src/eval.c	Wed Feb 13 12:41:30 2008
bd99770
--- src/eval.c	Wed Feb 20 11:08:21 2008
bd99770
***************
bd99770
*** 9203,9215 ****
bd99770
      rettv->vval.v_number = filewritable(get_tv_string(&argvars[0]));
bd99770
  }
bd99770
  
bd99770
! static void findfilendir __ARGS((typval_T *argvars, typval_T *rettv, int dir));
bd99770
  
bd99770
      static void
bd99770
! findfilendir(argvars, rettv, dir)
bd99770
      typval_T	*argvars;
bd99770
      typval_T	*rettv;
bd99770
!     int		dir;
bd99770
  {
bd99770
  #ifdef FEAT_SEARCHPATH
bd99770
      char_u	*fname;
bd99770
--- 9205,9217 ----
bd99770
      rettv->vval.v_number = filewritable(get_tv_string(&argvars[0]));
bd99770
  }
bd99770
  
bd99770
! static void findfilendir __ARGS((typval_T *argvars, typval_T *rettv, int find_what));
bd99770
  
bd99770
      static void
bd99770
! findfilendir(argvars, rettv, find_what)
bd99770
      typval_T	*argvars;
bd99770
      typval_T	*rettv;
bd99770
!     int		find_what;
bd99770
  {
bd99770
  #ifdef FEAT_SEARCHPATH
bd99770
      char_u	*fname;
bd99770
***************
bd99770
*** 9254,9261 ****
bd99770
  		vim_free(fresult);
bd99770
  	    fresult = find_file_in_path_option(first ? fname : NULL,
bd99770
  					       first ? (int)STRLEN(fname) : 0,
bd99770
! 					0, first, path, dir, curbuf->b_ffname,
bd99770
! 					dir ? (char_u *)"" : curbuf->b_p_sua);
bd99770
  	    first = FALSE;
bd99770
  
bd99770
  	    if (fresult != NULL && rettv->v_type == VAR_LIST)
bd99770
--- 9256,9266 ----
bd99770
  		vim_free(fresult);
bd99770
  	    fresult = find_file_in_path_option(first ? fname : NULL,
bd99770
  					       first ? (int)STRLEN(fname) : 0,
bd99770
! 					0, first, path,
bd99770
! 					find_what,
bd99770
! 					curbuf->b_ffname,
bd99770
! 					find_what == FINDFILE_DIR
bd99770
! 					    ? (char_u *)"" : curbuf->b_p_sua);
bd99770
  	    first = FALSE;
bd99770
  
bd99770
  	    if (fresult != NULL && rettv->v_type == VAR_LIST)
bd99770
***************
bd99770
*** 9445,9451 ****
bd99770
      typval_T	*argvars;
bd99770
      typval_T	*rettv;
bd99770
  {
bd99770
!     findfilendir(argvars, rettv, TRUE);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
--- 9450,9456 ----
bd99770
      typval_T	*argvars;
bd99770
      typval_T	*rettv;
bd99770
  {
bd99770
!     findfilendir(argvars, rettv, FINDFILE_DIR);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
***************
bd99770
*** 9456,9462 ****
bd99770
      typval_T	*argvars;
bd99770
      typval_T	*rettv;
bd99770
  {
bd99770
!     findfilendir(argvars, rettv, FALSE);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
--- 9461,9467 ----
bd99770
      typval_T	*argvars;
bd99770
      typval_T	*rettv;
bd99770
  {
bd99770
!     findfilendir(argvars, rettv, FINDFILE_FILE);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
*** ../vim-7.1.255/src/misc2.c	Fri Jan  4 21:25:01 2008
bd99770
--- src/misc2.c	Wed Feb 13 17:19:21 2008
bd99770
***************
bd99770
*** 3777,3785 ****
bd99770
      char_u		ffs_filearray_cur;   /* needed for partly handled dirs */
bd99770
  
bd99770
      /* to store status of partly handled directories
bd99770
!      * 0: we work the on this directory for the first time
bd99770
       * 1: this directory was partly searched in an earlier step
bd99770
!     */
bd99770
      int			ffs_stage;
bd99770
  
bd99770
      /* How deep are we in the directory tree?
bd99770
--- 3778,3786 ----
bd99770
      char_u		ffs_filearray_cur;   /* needed for partly handled dirs */
bd99770
  
bd99770
      /* to store status of partly handled directories
bd99770
!      * 0: we work on this directory for the first time
bd99770
       * 1: this directory was partly searched in an earlier step
bd99770
!      */
bd99770
      int			ffs_stage;
bd99770
  
bd99770
      /* How deep are we in the directory tree?
bd99770
***************
bd99770
*** 3848,3853 ****
bd99770
--- 3849,3855 ----
bd99770
   * Set the default maximum depth.
bd99770
   */
bd99770
  #define FF_MAX_STAR_STAR_EXPAND ((char_u)30)
bd99770
+ 
bd99770
  /*
bd99770
   * The search context:
bd99770
   *   ffsc_stack_ptr:	the stack for the dirs to search
bd99770
***************
bd99770
*** 3862,3868 ****
bd99770
   *   ffsc_wc_path:	the part of the given path containing wildcards
bd99770
   *   ffsc_level:	how many levels of dirs to search downwards
bd99770
   *   ffsc_stopdirs_v:	array of stop directories for upward search
bd99770
!  *   ffsc_need_dir:	TRUE if we search for a directory
bd99770
   */
bd99770
  typedef struct ff_search_ctx_T
bd99770
  {
bd99770
--- 3864,3870 ----
bd99770
   *   ffsc_wc_path:	the part of the given path containing wildcards
bd99770
   *   ffsc_level:	how many levels of dirs to search downwards
bd99770
   *   ffsc_stopdirs_v:	array of stop directories for upward search
bd99770
!  *   ffsc_find_what:	FINDFILE_BOTH, FINDFILE_DIR or FINDFILE_FILE
bd99770
   */
bd99770
  typedef struct ff_search_ctx_T
bd99770
  {
bd99770
***************
bd99770
*** 3879,3889 ****
bd99770
       int			ffsc_level;
bd99770
       char_u			**ffsc_stopdirs_v;
bd99770
  #endif
bd99770
!      int			ffsc_need_dir;
bd99770
  } ff_search_ctx_T;
bd99770
  
bd99770
- static ff_search_ctx_T *ff_search_ctx = NULL;
bd99770
- 
bd99770
  /* locally needed functions */
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  static int ff_check_visited __ARGS((ff_visited_T **, char_u *, char_u *));
bd99770
--- 3881,3889 ----
bd99770
       int			ffsc_level;
bd99770
       char_u			**ffsc_stopdirs_v;
bd99770
  #endif
bd99770
!      int			ffsc_find_what;
bd99770
  } ff_search_ctx_T;
bd99770
  
bd99770
  /* locally needed functions */
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  static int ff_check_visited __ARGS((ff_visited_T **, char_u *, char_u *));
bd99770
***************
bd99770
*** 3897,3906 ****
bd99770
  static int ff_wc_equal __ARGS((char_u *s1, char_u *s2));
bd99770
  #endif
bd99770
  
bd99770
! static void ff_push __ARGS((ff_stack_T *));
bd99770
! static ff_stack_T * ff_pop __ARGS((void));
bd99770
! static void ff_clear __ARGS((void));
bd99770
! static void ff_free_stack_element __ARGS((ff_stack_T *));
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  static ff_stack_T *ff_create_stack_element __ARGS((char_u *, char_u *, int, int));
bd99770
  #else
bd99770
--- 3897,3906 ----
bd99770
  static int ff_wc_equal __ARGS((char_u *s1, char_u *s2));
bd99770
  #endif
bd99770
  
bd99770
! static void ff_push __ARGS((ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr));
bd99770
! static ff_stack_T *ff_pop __ARGS((ff_search_ctx_T *search_ctx));
bd99770
! static void ff_clear __ARGS((ff_search_ctx_T *search_ctx));
bd99770
! static void ff_free_stack_element __ARGS((ff_stack_T *stack_ptr));
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  static ff_stack_T *ff_create_stack_element __ARGS((char_u *, char_u *, int, int));
bd99770
  #else
bd99770
***************
bd99770
*** 3961,3966 ****
bd99770
--- 3961,3969 ----
bd99770
   * not related to restricts given to the '**' wildcard. If 'level' is 100
bd99770
   * and you use '**200' vim_findfile() will stop after 100 levels.
bd99770
   *
bd99770
+  * 'filename' cannot contain wildcards!  It is used as-is, no backslashes to
bd99770
+  * escape special characters.
bd99770
+  *
bd99770
   * If 'stopdirs' is not NULL and nothing is found downward, the search is
bd99770
   * restarted on the next higher directory level. This is repeated until the
bd99770
   * start-directory of a search is contained in 'stopdirs'. 'stopdirs' has the
bd99770
***************
bd99770
*** 3980,4053 ****
bd99770
   * The list of visited files/dirs can also be cleared with the function
bd99770
   * vim_findfile_free_visited().
bd99770
   *
bd99770
!  * Set the parameter 'need_dir' to TRUE if you want to search for a directory
bd99770
!  * instead of a file.
bd99770
   *
bd99770
   * A search context returned by a previous call to vim_findfile_init() can be
bd99770
!  * passed in the parameter 'search_ctx'. This context is than reused and
bd99770
!  * reinitialized with the new parameters. The list of already viseted
bd99770
   * directories from this context is only deleted if the parameter
bd99770
!  * 'free_visited' is true. Be aware that the passed search_context is freed if
bd99770
!  * the reinitialization fails.
bd99770
   *
bd99770
!  * If you don't have a search context from a previous call 'search_ctx' must be
bd99770
!  * NULL.
bd99770
   *
bd99770
   * This function silently ignores a few errors, vim_findfile() will have
bd99770
   * limited functionality then.
bd99770
   */
bd99770
  /*ARGSUSED*/
bd99770
      void *
bd99770
! vim_findfile_init(path, filename, stopdirs, level, free_visited, need_dir,
bd99770
! 						search_ctx, tagfile, rel_fname)
bd99770
      char_u	*path;
bd99770
      char_u	*filename;
bd99770
      char_u	*stopdirs;
bd99770
      int		level;
bd99770
      int		free_visited;
bd99770
!     int		need_dir;
bd99770
!     void	*search_ctx;
bd99770
      int		tagfile;
bd99770
      char_u	*rel_fname;	/* file name to use for "." */
bd99770
  {
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     char_u	*wc_part;
bd99770
  #endif
bd99770
!     ff_stack_T	*sptr;
bd99770
  
bd99770
      /* If a search context is given by the caller, reuse it, else allocate a
bd99770
       * new one.
bd99770
       */
bd99770
!     if (search_ctx != NULL)
bd99770
! 	ff_search_ctx = search_ctx;
bd99770
      else
bd99770
      {
bd99770
! 	ff_search_ctx = (ff_search_ctx_T*)alloc(
bd99770
! 					   (unsigned)sizeof(ff_search_ctx_T));
bd99770
! 	if (ff_search_ctx == NULL)
bd99770
  	    goto error_return;
bd99770
! 	memset(ff_search_ctx, 0, sizeof(ff_search_ctx_T));
bd99770
      }
bd99770
  
bd99770
      /* clear the search context, but NOT the visited lists */
bd99770
!     ff_clear();
bd99770
  
bd99770
      /* clear visited list if wanted */
bd99770
      if (free_visited == TRUE)
bd99770
! 	vim_findfile_free_visited(ff_search_ctx);
bd99770
      else
bd99770
      {
bd99770
  	/* Reuse old visited lists. Get the visited list for the given
bd99770
  	 * filename. If no list for the current filename exists, creates a new
bd99770
! 	 * one.
bd99770
! 	 */
bd99770
! 	ff_search_ctx->ffsc_visited_list = ff_get_visited_list(filename,
bd99770
! 				     &ff_search_ctx->ffsc_visited_lists_list);
bd99770
! 	if (ff_search_ctx->ffsc_visited_list == NULL)
bd99770
  	    goto error_return;
bd99770
! 	ff_search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename,
bd99770
! 				 &ff_search_ctx->ffsc_dir_visited_lists_list);
bd99770
! 	if (ff_search_ctx->ffsc_dir_visited_list == NULL)
bd99770
  	    goto error_return;
bd99770
      }
bd99770
  
bd99770
--- 3983,4056 ----
bd99770
   * The list of visited files/dirs can also be cleared with the function
bd99770
   * vim_findfile_free_visited().
bd99770
   *
bd99770
!  * Set the parameter 'find_what' to FINDFILE_DIR if you want to search for
bd99770
!  * directories only, FINDFILE_FILE for files only, FINDFILE_BOTH for both.
bd99770
   *
bd99770
   * A search context returned by a previous call to vim_findfile_init() can be
bd99770
!  * passed in the parameter "search_ctx_arg".  This context is reused and
bd99770
!  * reinitialized with the new parameters.  The list of already visited
bd99770
   * directories from this context is only deleted if the parameter
bd99770
!  * "free_visited" is true.  Be aware that the passed "search_ctx_arg" is freed
bd99770
!  * if the reinitialization fails.
bd99770
   *
bd99770
!  * If you don't have a search context from a previous call "search_ctx_arg"
bd99770
!  * must be NULL.
bd99770
   *
bd99770
   * This function silently ignores a few errors, vim_findfile() will have
bd99770
   * limited functionality then.
bd99770
   */
bd99770
  /*ARGSUSED*/
bd99770
      void *
bd99770
! vim_findfile_init(path, filename, stopdirs, level, free_visited, find_what,
bd99770
! 					   search_ctx_arg, tagfile, rel_fname)
bd99770
      char_u	*path;
bd99770
      char_u	*filename;
bd99770
      char_u	*stopdirs;
bd99770
      int		level;
bd99770
      int		free_visited;
bd99770
!     int		find_what;
bd99770
!     void	*search_ctx_arg;
bd99770
      int		tagfile;
bd99770
      char_u	*rel_fname;	/* file name to use for "." */
bd99770
  {
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     char_u		*wc_part;
bd99770
  #endif
bd99770
!     ff_stack_T		*sptr;
bd99770
!     ff_search_ctx_T	*search_ctx;
bd99770
  
bd99770
      /* If a search context is given by the caller, reuse it, else allocate a
bd99770
       * new one.
bd99770
       */
bd99770
!     if (search_ctx_arg != NULL)
bd99770
! 	search_ctx = search_ctx_arg;
bd99770
      else
bd99770
      {
bd99770
! 	search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T));
bd99770
! 	if (search_ctx == NULL)
bd99770
  	    goto error_return;
bd99770
! 	memset(search_ctx, 0, sizeof(ff_search_ctx_T));
bd99770
      }
bd99770
+     search_ctx->ffsc_find_what = find_what;
bd99770
  
bd99770
      /* clear the search context, but NOT the visited lists */
bd99770
!     ff_clear(search_ctx);
bd99770
  
bd99770
      /* clear visited list if wanted */
bd99770
      if (free_visited == TRUE)
bd99770
! 	vim_findfile_free_visited(search_ctx);
bd99770
      else
bd99770
      {
bd99770
  	/* Reuse old visited lists. Get the visited list for the given
bd99770
  	 * filename. If no list for the current filename exists, creates a new
bd99770
! 	 * one. */
bd99770
! 	search_ctx->ffsc_visited_list = ff_get_visited_list(filename,
bd99770
! 					&search_ctx->ffsc_visited_lists_list);
bd99770
! 	if (search_ctx->ffsc_visited_list == NULL)
bd99770
  	    goto error_return;
bd99770
! 	search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename,
bd99770
! 				    &search_ctx->ffsc_dir_visited_lists_list);
bd99770
! 	if (search_ctx->ffsc_dir_visited_list == NULL)
bd99770
  	    goto error_return;
bd99770
      }
bd99770
  
bd99770
***************
bd99770
*** 4071,4082 ****
bd99770
  	{
bd99770
  	    /* Make the start dir an absolute path name. */
bd99770
  	    vim_strncpy(ff_expand_buffer, rel_fname, len);
bd99770
! 	    ff_search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer,
bd99770
! 								       FALSE);
bd99770
  	}
bd99770
  	else
bd99770
! 	    ff_search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
bd99770
! 	if (ff_search_ctx->ffsc_start_dir == NULL)
bd99770
  	    goto error_return;
bd99770
  	if (*++path != NUL)
bd99770
  	    ++path;
bd99770
--- 4074,4084 ----
bd99770
  	{
bd99770
  	    /* Make the start dir an absolute path name. */
bd99770
  	    vim_strncpy(ff_expand_buffer, rel_fname, len);
bd99770
! 	    search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE);
bd99770
  	}
bd99770
  	else
bd99770
! 	    search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
bd99770
! 	if (search_ctx->ffsc_start_dir == NULL)
bd99770
  	    goto error_return;
bd99770
  	if (*++path != NUL)
bd99770
  	    ++path;
bd99770
***************
bd99770
*** 4101,4108 ****
bd99770
  	if (mch_dirname(ff_expand_buffer, MAXPATHL) == FAIL)
bd99770
  	    goto error_return;
bd99770
  
bd99770
! 	ff_search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer);
bd99770
! 	if (ff_search_ctx->ffsc_start_dir == NULL)
bd99770
  	    goto error_return;
bd99770
  
bd99770
  #ifdef BACKSLASH_IN_FILENAME
bd99770
--- 4103,4110 ----
bd99770
  	if (mch_dirname(ff_expand_buffer, MAXPATHL) == FAIL)
bd99770
  	    goto error_return;
bd99770
  
bd99770
! 	search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer);
bd99770
! 	if (search_ctx->ffsc_start_dir == NULL)
bd99770
  	    goto error_return;
bd99770
  
bd99770
  #ifdef BACKSLASH_IN_FILENAME
bd99770
***************
bd99770
*** 4110,4117 ****
bd99770
  	 * directory (but not for "//machine/dir").  Only use the drive name. */
bd99770
  	if ((*path == '/' || *path == '\\')
bd99770
  		&& path[1] != path[0]
bd99770
! 		&& ff_search_ctx->ffsc_start_dir[1] == ':')
bd99770
! 	    ff_search_ctx->ffsc_start_dir[2] = NUL;
bd99770
  #endif
bd99770
      }
bd99770
  
bd99770
--- 4112,4119 ----
bd99770
  	 * directory (but not for "//machine/dir").  Only use the drive name. */
bd99770
  	if ((*path == '/' || *path == '\\')
bd99770
  		&& path[1] != path[0]
bd99770
! 		&& search_ctx->ffsc_start_dir[1] == ':')
bd99770
! 	    search_ctx->ffsc_start_dir[2] = NUL;
bd99770
  #endif
bd99770
      }
bd99770
  
bd99770
***************
bd99770
*** 4121,4127 ****
bd99770
       * If this fails (mem allocation), there is no upward search at all or a
bd99770
       * stop directory is not recognized -> continue silently.
bd99770
       * If stopdirs just contains a ";" or is empty,
bd99770
!      * ff_search_ctx->ffsc_stopdirs_v will only contain a  NULL pointer. This
bd99770
       * is handled as unlimited upward search.  See function
bd99770
       * ff_path_in_stoplist() for details.
bd99770
       */
bd99770
--- 4123,4129 ----
bd99770
       * If this fails (mem allocation), there is no upward search at all or a
bd99770
       * stop directory is not recognized -> continue silently.
bd99770
       * If stopdirs just contains a ";" or is empty,
bd99770
!      * search_ctx->ffsc_stopdirs_v will only contain a  NULL pointer. This
bd99770
       * is handled as unlimited upward search.  See function
bd99770
       * ff_path_in_stoplist() for details.
bd99770
       */
bd99770
***************
bd99770
*** 4134,4143 ****
bd99770
  	    walker++;
bd99770
  
bd99770
  	dircount = 1;
bd99770
! 	ff_search_ctx->ffsc_stopdirs_v =
bd99770
! 	    (char_u **)alloc((unsigned)sizeof(char_u *));
bd99770
  
bd99770
! 	if (ff_search_ctx->ffsc_stopdirs_v != NULL)
bd99770
  	{
bd99770
  	    do
bd99770
  	    {
bd99770
--- 4136,4145 ----
bd99770
  	    walker++;
bd99770
  
bd99770
  	dircount = 1;
bd99770
! 	search_ctx->ffsc_stopdirs_v =
bd99770
! 				 (char_u **)alloc((unsigned)sizeof(char_u *));
bd99770
  
bd99770
! 	if (search_ctx->ffsc_stopdirs_v != NULL)
bd99770
  	{
bd99770
  	    do
bd99770
  	    {
bd99770
***************
bd99770
*** 4145,4181 ****
bd99770
  		void	*ptr;
bd99770
  
bd99770
  		helper = walker;
bd99770
! 		ptr = vim_realloc(ff_search_ctx->ffsc_stopdirs_v,
bd99770
  					   (dircount + 1) * sizeof(char_u *));
bd99770
  		if (ptr)
bd99770
! 		    ff_search_ctx->ffsc_stopdirs_v = ptr;
bd99770
  		else
bd99770
  		    /* ignore, keep what we have and continue */
bd99770
  		    break;
bd99770
  		walker = vim_strchr(walker, ';');
bd99770
  		if (walker)
bd99770
  		{
bd99770
! 		    ff_search_ctx->ffsc_stopdirs_v[dircount-1] =
bd99770
! 			vim_strnsave(helper, (int)(walker - helper));
bd99770
  		    walker++;
bd99770
  		}
bd99770
  		else
bd99770
  		    /* this might be "", which means ascent till top
bd99770
  		     * of directory tree.
bd99770
  		     */
bd99770
! 		    ff_search_ctx->ffsc_stopdirs_v[dircount-1] =
bd99770
! 			vim_strsave(helper);
bd99770
  
bd99770
  		dircount++;
bd99770
  
bd99770
  	    } while (walker != NULL);
bd99770
! 	    ff_search_ctx->ffsc_stopdirs_v[dircount-1] = NULL;
bd99770
  	}
bd99770
      }
bd99770
  #endif
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     ff_search_ctx->ffsc_level = level;
bd99770
  
bd99770
      /* split into:
bd99770
       *  -fix path
bd99770
--- 4147,4183 ----
bd99770
  		void	*ptr;
bd99770
  
bd99770
  		helper = walker;
bd99770
! 		ptr = vim_realloc(search_ctx->ffsc_stopdirs_v,
bd99770
  					   (dircount + 1) * sizeof(char_u *));
bd99770
  		if (ptr)
bd99770
! 		    search_ctx->ffsc_stopdirs_v = ptr;
bd99770
  		else
bd99770
  		    /* ignore, keep what we have and continue */
bd99770
  		    break;
bd99770
  		walker = vim_strchr(walker, ';');
bd99770
  		if (walker)
bd99770
  		{
bd99770
! 		    search_ctx->ffsc_stopdirs_v[dircount-1] =
bd99770
! 				 vim_strnsave(helper, (int)(walker - helper));
bd99770
  		    walker++;
bd99770
  		}
bd99770
  		else
bd99770
  		    /* this might be "", which means ascent till top
bd99770
  		     * of directory tree.
bd99770
  		     */
bd99770
! 		    search_ctx->ffsc_stopdirs_v[dircount-1] =
bd99770
! 							  vim_strsave(helper);
bd99770
  
bd99770
  		dircount++;
bd99770
  
bd99770
  	    } while (walker != NULL);
bd99770
! 	    search_ctx->ffsc_stopdirs_v[dircount-1] = NULL;
bd99770
  	}
bd99770
      }
bd99770
  #endif
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     search_ctx->ffsc_level = level;
bd99770
  
bd99770
      /* split into:
bd99770
       *  -fix path
bd99770
***************
bd99770
*** 4189,4196 ****
bd99770
  	char	*errpt;
bd99770
  
bd99770
  	/* save the fix part of the path */
bd99770
! 	ff_search_ctx->ffsc_fix_path = vim_strnsave(path,
bd99770
! 						       (int)(wc_part - path));
bd99770
  
bd99770
  	/*
bd99770
  	 * copy wc_path and add restricts to the '**' wildcard.
bd99770
--- 4191,4197 ----
bd99770
  	char	*errpt;
bd99770
  
bd99770
  	/* save the fix part of the path */
bd99770
! 	search_ctx->ffsc_fix_path = vim_strnsave(path, (int)(wc_part - path));
bd99770
  
bd99770
  	/*
bd99770
  	 * copy wc_path and add restricts to the '**' wildcard.
bd99770
***************
bd99770
*** 4229,4275 ****
bd99770
  		ff_expand_buffer[len++] = *wc_part++;
bd99770
  	}
bd99770
  	ff_expand_buffer[len] = NUL;
bd99770
! 	ff_search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer);
bd99770
  
bd99770
! 	if (ff_search_ctx->ffsc_wc_path == NULL)
bd99770
  	    goto error_return;
bd99770
      }
bd99770
      else
bd99770
  #endif
bd99770
! 	ff_search_ctx->ffsc_fix_path = vim_strsave(path);
bd99770
  
bd99770
!     if (ff_search_ctx->ffsc_start_dir == NULL)
bd99770
      {
bd99770
  	/* store the fix part as startdir.
bd99770
  	 * This is needed if the parameter path is fully qualified.
bd99770
  	 */
bd99770
! 	ff_search_ctx->ffsc_start_dir = vim_strsave(ff_search_ctx->ffsc_fix_path);
bd99770
! 	if (ff_search_ctx->ffsc_start_dir)
bd99770
! 	    ff_search_ctx->ffsc_fix_path[0] = NUL;
bd99770
      }
bd99770
  
bd99770
      /* create an absolute path */
bd99770
!     STRCPY(ff_expand_buffer, ff_search_ctx->ffsc_start_dir);
bd99770
      add_pathsep(ff_expand_buffer);
bd99770
!     STRCAT(ff_expand_buffer, ff_search_ctx->ffsc_fix_path);
bd99770
      add_pathsep(ff_expand_buffer);
bd99770
  
bd99770
      sptr = ff_create_stack_element(ff_expand_buffer,
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
! 	    ff_search_ctx->ffsc_wc_path,
bd99770
  #endif
bd99770
  	    level, 0);
bd99770
  
bd99770
      if (sptr == NULL)
bd99770
  	goto error_return;
bd99770
  
bd99770
!     ff_push(sptr);
bd99770
  
bd99770
!     ff_search_ctx->ffsc_file_to_search = vim_strsave(filename);
bd99770
!     if (ff_search_ctx->ffsc_file_to_search == NULL)
bd99770
  	goto error_return;
bd99770
  
bd99770
!     return ff_search_ctx;
bd99770
  
bd99770
  error_return:
bd99770
      /*
bd99770
--- 4230,4276 ----
bd99770
  		ff_expand_buffer[len++] = *wc_part++;
bd99770
  	}
bd99770
  	ff_expand_buffer[len] = NUL;
bd99770
! 	search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer);
bd99770
  
bd99770
! 	if (search_ctx->ffsc_wc_path == NULL)
bd99770
  	    goto error_return;
bd99770
      }
bd99770
      else
bd99770
  #endif
bd99770
! 	search_ctx->ffsc_fix_path = vim_strsave(path);
bd99770
  
bd99770
!     if (search_ctx->ffsc_start_dir == NULL)
bd99770
      {
bd99770
  	/* store the fix part as startdir.
bd99770
  	 * This is needed if the parameter path is fully qualified.
bd99770
  	 */
bd99770
! 	search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path);
bd99770
! 	if (search_ctx->ffsc_start_dir)
bd99770
! 	    search_ctx->ffsc_fix_path[0] = NUL;
bd99770
      }
bd99770
  
bd99770
      /* create an absolute path */
bd99770
!     STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir);
bd99770
      add_pathsep(ff_expand_buffer);
bd99770
!     STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
bd99770
      add_pathsep(ff_expand_buffer);
bd99770
  
bd99770
      sptr = ff_create_stack_element(ff_expand_buffer,
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
! 	    search_ctx->ffsc_wc_path,
bd99770
  #endif
bd99770
  	    level, 0);
bd99770
  
bd99770
      if (sptr == NULL)
bd99770
  	goto error_return;
bd99770
  
bd99770
!     ff_push(search_ctx, sptr);
bd99770
  
bd99770
!     search_ctx->ffsc_file_to_search = vim_strsave(filename);
bd99770
!     if (search_ctx->ffsc_file_to_search == NULL)
bd99770
  	goto error_return;
bd99770
  
bd99770
!     return search_ctx;
bd99770
  
bd99770
  error_return:
bd99770
      /*
bd99770
***************
bd99770
*** 4277,4283 ****
bd99770
       * Even when the caller gave us a (perhaps valid) context we free it here,
bd99770
       * as we might have already destroyed it.
bd99770
       */
bd99770
!     vim_findfile_cleanup(ff_search_ctx);
bd99770
      return NULL;
bd99770
  }
bd99770
  
bd99770
--- 4278,4284 ----
bd99770
       * Even when the caller gave us a (perhaps valid) context we free it here,
bd99770
       * as we might have already destroyed it.
bd99770
       */
bd99770
!     vim_findfile_cleanup(search_ctx);
bd99770
      return NULL;
bd99770
  }
bd99770
  
bd99770
***************
bd99770
*** 4314,4320 ****
bd99770
  }
bd99770
  #endif
bd99770
  
bd99770
! /* Clean up the given search context. Can handle a NULL pointer */
bd99770
      void
bd99770
  vim_findfile_cleanup(ctx)
bd99770
      void	*ctx;
bd99770
--- 4315,4323 ----
bd99770
  }
bd99770
  #endif
bd99770
  
bd99770
! /*
bd99770
!  * Clean up the given search context. Can handle a NULL pointer.
bd99770
!  */
bd99770
      void
bd99770
  vim_findfile_cleanup(ctx)
bd99770
      void	*ctx;
bd99770
***************
bd99770
*** 4322,4333 ****
bd99770
      if (ctx == NULL)
bd99770
  	return;
bd99770
  
bd99770
-     ff_search_ctx = ctx;
bd99770
- 
bd99770
      vim_findfile_free_visited(ctx);
bd99770
!     ff_clear();
bd99770
      vim_free(ctx);
bd99770
-     ff_search_ctx = NULL;
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
--- 4325,4333 ----
bd99770
      if (ctx == NULL)
bd99770
  	return;
bd99770
  
bd99770
      vim_findfile_free_visited(ctx);
bd99770
!     ff_clear(ctx);
bd99770
      vim_free(ctx);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
***************
bd99770
*** 4343,4357 ****
bd99770
   * top of the list).
bd99770
   */
bd99770
      char_u *
bd99770
! vim_findfile(search_ctx)
bd99770
!     void	*search_ctx;
bd99770
  {
bd99770
      char_u	*file_path;
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
      char_u	*rest_of_wildcards;
bd99770
      char_u	*path_end = NULL;
bd99770
  #endif
bd99770
!     ff_stack_T	*ctx;
bd99770
  #if defined(FEAT_SEARCHPATH) || defined(FEAT_PATH_EXTRA)
bd99770
      int		len;
bd99770
  #endif
bd99770
--- 4343,4357 ----
bd99770
   * top of the list).
bd99770
   */
bd99770
      char_u *
bd99770
! vim_findfile(search_ctx_arg)
bd99770
!     void	*search_ctx_arg;
bd99770
  {
bd99770
      char_u	*file_path;
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
      char_u	*rest_of_wildcards;
bd99770
      char_u	*path_end = NULL;
bd99770
  #endif
bd99770
!     ff_stack_T	*stackp;
bd99770
  #if defined(FEAT_SEARCHPATH) || defined(FEAT_PATH_EXTRA)
bd99770
      int		len;
bd99770
  #endif
bd99770
***************
bd99770
*** 4360,4370 ****
bd99770
  #ifdef FEAT_SEARCHPATH
bd99770
      char_u	*suf;
bd99770
  #endif
bd99770
  
bd99770
!     if (search_ctx == NULL)
bd99770
  	return NULL;
bd99770
  
bd99770
!     ff_search_ctx = (ff_search_ctx_T*)search_ctx;
bd99770
  
bd99770
      /*
bd99770
       * filepath is used as buffer for various actions and as the storage to
bd99770
--- 4360,4371 ----
bd99770
  #ifdef FEAT_SEARCHPATH
bd99770
      char_u	*suf;
bd99770
  #endif
bd99770
+     ff_search_ctx_T *search_ctx;
bd99770
  
bd99770
!     if (search_ctx_arg == NULL)
bd99770
  	return NULL;
bd99770
  
bd99770
!     search_ctx = (ff_search_ctx_T *)search_ctx_arg;
bd99770
  
bd99770
      /*
bd99770
       * filepath is used as buffer for various actions and as the storage to
bd99770
***************
bd99770
*** 4375,4382 ****
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
      /* store the end of the start dir -- needed for upward search */
bd99770
!     if (ff_search_ctx->ffsc_start_dir != NULL)
bd99770
! 	path_end = &ff_search_ctx->ffsc_start_dir[STRLEN(ff_search_ctx->ffsc_start_dir)];
bd99770
  #endif
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
--- 4376,4384 ----
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
      /* store the end of the start dir -- needed for upward search */
bd99770
!     if (search_ctx->ffsc_start_dir != NULL)
bd99770
! 	path_end = &search_ctx->ffsc_start_dir[
bd99770
! 					  STRLEN(search_ctx->ffsc_start_dir)];
bd99770
  #endif
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
***************
bd99770
*** 4393,4400 ****
bd99770
  		break;
bd99770
  
bd99770
  	    /* get directory to work on from stack */
bd99770
! 	    ctx = ff_pop();
bd99770
! 	    if (ctx == NULL)
bd99770
  		break;
bd99770
  
bd99770
  	    /*
bd99770
--- 4395,4402 ----
bd99770
  		break;
bd99770
  
bd99770
  	    /* get directory to work on from stack */
bd99770
! 	    stackp = ff_pop(search_ctx);
bd99770
! 	    if (stackp == NULL)
bd99770
  		break;
bd99770
  
bd99770
  	    /*
bd99770
***************
bd99770
*** 4414,4427 ****
bd99770
  	     *  /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop)
bd99770
  	     *
bd99770
  	     * This check is only needed for directories we work on for the
bd99770
! 	     * first time (hence ctx->ff_filearray == NULL)
bd99770
  	     */
bd99770
! 	    if (ctx->ffs_filearray == NULL
bd99770
! 		    && ff_check_visited(&ff_search_ctx->ffsc_dir_visited_list
bd99770
  							  ->ffvl_visited_list,
bd99770
! 			ctx->ffs_fix_path
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
! 			, ctx->ffs_wc_path
bd99770
  #endif
bd99770
  			) == FAIL)
bd99770
  	    {
bd99770
--- 4416,4429 ----
bd99770
  	     *  /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop)
bd99770
  	     *
bd99770
  	     * This check is only needed for directories we work on for the
bd99770
! 	     * first time (hence stackp->ff_filearray == NULL)
bd99770
  	     */
bd99770
! 	    if (stackp->ffs_filearray == NULL
bd99770
! 		    && ff_check_visited(&search_ctx->ffsc_dir_visited_list
bd99770
  							  ->ffvl_visited_list,
bd99770
! 			stackp->ffs_fix_path
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
! 			, stackp->ffs_wc_path
bd99770
  #endif
bd99770
  			) == FAIL)
bd99770
  	    {
bd99770
***************
bd99770
*** 4430,4442 ****
bd99770
  		{
bd99770
  		    verbose_enter_scroll();
bd99770
  		    smsg((char_u *)"Already Searched: %s (%s)",
bd99770
! 					   ctx->ffs_fix_path, ctx->ffs_wc_path);
bd99770
  		    /* don't overwrite this either */
bd99770
  		    msg_puts((char_u *)"\n");
bd99770
  		    verbose_leave_scroll();
bd99770
  		}
bd99770
  #endif
bd99770
! 		ff_free_stack_element(ctx);
bd99770
  		continue;
bd99770
  	    }
bd99770
  #ifdef FF_VERBOSE
bd99770
--- 4432,4444 ----
bd99770
  		{
bd99770
  		    verbose_enter_scroll();
bd99770
  		    smsg((char_u *)"Already Searched: %s (%s)",
bd99770
! 				   stackp->ffs_fix_path, stackp->ffs_wc_path);
bd99770
  		    /* don't overwrite this either */
bd99770
  		    msg_puts((char_u *)"\n");
bd99770
  		    verbose_leave_scroll();
bd99770
  		}
bd99770
  #endif
bd99770
! 		ff_free_stack_element(stackp);
bd99770
  		continue;
bd99770
  	    }
bd99770
  #ifdef FF_VERBOSE
bd99770
***************
bd99770
*** 4444,4450 ****
bd99770
  	    {
bd99770
  		verbose_enter_scroll();
bd99770
  		smsg((char_u *)"Searching: %s (%s)",
bd99770
! 					 ctx->ffs_fix_path, ctx->ffs_wc_path);
bd99770
  		/* don't overwrite this either */
bd99770
  		msg_puts((char_u *)"\n");
bd99770
  		verbose_leave_scroll();
bd99770
--- 4446,4452 ----
bd99770
  	    {
bd99770
  		verbose_enter_scroll();
bd99770
  		smsg((char_u *)"Searching: %s (%s)",
bd99770
! 				   stackp->ffs_fix_path, stackp->ffs_wc_path);
bd99770
  		/* don't overwrite this either */
bd99770
  		msg_puts((char_u *)"\n");
bd99770
  		verbose_leave_scroll();
bd99770
***************
bd99770
*** 4452,4460 ****
bd99770
  #endif
bd99770
  
bd99770
  	    /* check depth */
bd99770
! 	    if (ctx->ffs_level <= 0)
bd99770
  	    {
bd99770
! 		ff_free_stack_element(ctx);
bd99770
  		continue;
bd99770
  	    }
bd99770
  
bd99770
--- 4454,4462 ----
bd99770
  #endif
bd99770
  
bd99770
  	    /* check depth */
bd99770
! 	    if (stackp->ffs_level <= 0)
bd99770
  	    {
bd99770
! 		ff_free_stack_element(stackp);
bd99770
  		continue;
bd99770
  	    }
bd99770
  
bd99770
***************
bd99770
*** 4466,4472 ****
bd99770
  	     * and all possible expands are returned in one array. We use this
bd99770
  	     * to handle the expansion of '**' into an empty string.
bd99770
  	     */
bd99770
! 	    if (ctx->ffs_filearray == NULL)
bd99770
  	    {
bd99770
  		char_u *dirptrs[2];
bd99770
  
bd99770
--- 4468,4474 ----
bd99770
  	     * and all possible expands are returned in one array. We use this
bd99770
  	     * to handle the expansion of '**' into an empty string.
bd99770
  	     */
bd99770
! 	    if (stackp->ffs_filearray == NULL)
bd99770
  	    {
bd99770
  		char_u *dirptrs[2];
bd99770
  
bd99770
***************
bd99770
*** 4477,4495 ****
bd99770
  		dirptrs[1] = NULL;
bd99770
  
bd99770
  		/* if we have a start dir copy it in */
bd99770
! 		if (!vim_isAbsName(ctx->ffs_fix_path)
bd99770
! 			&& ff_search_ctx->ffsc_start_dir)
bd99770
  		{
bd99770
! 		    STRCPY(file_path, ff_search_ctx->ffsc_start_dir);
bd99770
  		    add_pathsep(file_path);
bd99770
  		}
bd99770
  
bd99770
  		/* append the fix part of the search path */
bd99770
! 		STRCAT(file_path, ctx->ffs_fix_path);
bd99770
  		add_pathsep(file_path);
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
! 		rest_of_wildcards = ctx->ffs_wc_path;
bd99770
  		if (*rest_of_wildcards != NUL)
bd99770
  		{
bd99770
  		    len = (int)STRLEN(file_path);
bd99770
--- 4479,4497 ----
bd99770
  		dirptrs[1] = NULL;
bd99770
  
bd99770
  		/* if we have a start dir copy it in */
bd99770
! 		if (!vim_isAbsName(stackp->ffs_fix_path)
bd99770
! 						&& search_ctx->ffsc_start_dir)
bd99770
  		{
bd99770
! 		    STRCPY(file_path, search_ctx->ffsc_start_dir);
bd99770
  		    add_pathsep(file_path);
bd99770
  		}
bd99770
  
bd99770
  		/* append the fix part of the search path */
bd99770
! 		STRCAT(file_path, stackp->ffs_fix_path);
bd99770
  		add_pathsep(file_path);
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
! 		rest_of_wildcards = stackp->ffs_wc_path;
bd99770
  		if (*rest_of_wildcards != NUL)
bd99770
  		{
bd99770
  		    len = (int)STRLEN(file_path);
bd99770
***************
bd99770
*** 4516,4526 ****
bd99770
  			else
bd99770
  			    rest_of_wildcards += 3;
bd99770
  
bd99770
! 			if (ctx->ffs_star_star_empty == 0)
bd99770
  			{
bd99770
  			    /* if not done before, expand '**' to empty */
bd99770
! 			    ctx->ffs_star_star_empty = 1;
bd99770
! 			    dirptrs[1] = ctx->ffs_fix_path;
bd99770
  			}
bd99770
  		    }
bd99770
  
bd99770
--- 4518,4528 ----
bd99770
  			else
bd99770
  			    rest_of_wildcards += 3;
bd99770
  
bd99770
! 			if (stackp->ffs_star_star_empty == 0)
bd99770
  			{
bd99770
  			    /* if not done before, expand '**' to empty */
bd99770
! 			    stackp->ffs_star_star_empty = 1;
bd99770
! 			    dirptrs[1] = stackp->ffs_fix_path;
bd99770
  			}
bd99770
  		    }
bd99770
  
bd99770
***************
bd99770
*** 4547,4576 ****
bd99770
  		 */
bd99770
  		if (path_with_url(dirptrs[0]))
bd99770
  		{
bd99770
! 		    ctx->ffs_filearray = (char_u **)
bd99770
  					      alloc((unsigned)sizeof(char *));
bd99770
! 		    if (ctx->ffs_filearray != NULL
bd99770
! 			    && (ctx->ffs_filearray[0]
bd99770
  				= vim_strsave(dirptrs[0])) != NULL)
bd99770
! 			ctx->ffs_filearray_size = 1;
bd99770
  		    else
bd99770
! 			ctx->ffs_filearray_size = 0;
bd99770
  		}
bd99770
  		else
bd99770
  		    expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs,
bd99770
! 			    &ctx->ffs_filearray_size,
bd99770
! 			    &ctx->ffs_filearray,
bd99770
  			    EW_DIR|EW_ADDSLASH|EW_SILENT);
bd99770
  
bd99770
! 		ctx->ffs_filearray_cur = 0;
bd99770
! 		ctx->ffs_stage = 0;
bd99770
  	    }
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  	    else
bd99770
! 		rest_of_wildcards = &ctx->ffs_wc_path[STRLEN(ctx->ffs_wc_path)];
bd99770
  #endif
bd99770
  
bd99770
! 	    if (ctx->ffs_stage == 0)
bd99770
  	    {
bd99770
  		/* this is the first time we work on this directory */
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
--- 4549,4579 ----
bd99770
  		 */
bd99770
  		if (path_with_url(dirptrs[0]))
bd99770
  		{
bd99770
! 		    stackp->ffs_filearray = (char_u **)
bd99770
  					      alloc((unsigned)sizeof(char *));
bd99770
! 		    if (stackp->ffs_filearray != NULL
bd99770
! 			    && (stackp->ffs_filearray[0]
bd99770
  				= vim_strsave(dirptrs[0])) != NULL)
bd99770
! 			stackp->ffs_filearray_size = 1;
bd99770
  		    else
bd99770
! 			stackp->ffs_filearray_size = 0;
bd99770
  		}
bd99770
  		else
bd99770
  		    expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs,
bd99770
! 			    &stackp->ffs_filearray_size,
bd99770
! 			    &stackp->ffs_filearray,
bd99770
  			    EW_DIR|EW_ADDSLASH|EW_SILENT);
bd99770
  
bd99770
! 		stackp->ffs_filearray_cur = 0;
bd99770
! 		stackp->ffs_stage = 0;
bd99770
  	    }
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  	    else
bd99770
! 		rest_of_wildcards = &stackp->ffs_wc_path[
bd99770
! 						 STRLEN(stackp->ffs_wc_path)];
bd99770
  #endif
bd99770
  
bd99770
! 	    if (stackp->ffs_stage == 0)
bd99770
  	    {
bd99770
  		/* this is the first time we work on this directory */
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
***************
bd99770
*** 4581,4598 ****
bd99770
  		     * we don't have further wildcards to expand, so we have to
bd99770
  		     * check for the final file now
bd99770
  		     */
bd99770
! 		    for (i = ctx->ffs_filearray_cur;
bd99770
! 					     i < ctx->ffs_filearray_size; ++i)
bd99770
  		    {
bd99770
! 			if (!path_with_url(ctx->ffs_filearray[i])
bd99770
! 					 && !mch_isdir(ctx->ffs_filearray[i]))
bd99770
  			    continue;   /* not a directory */
bd99770
  
bd99770
  			/* prepare the filename to be checked for existance
bd99770
  			 * below */
bd99770
! 			STRCPY(file_path, ctx->ffs_filearray[i]);
bd99770
  			add_pathsep(file_path);
bd99770
! 			STRCAT(file_path, ff_search_ctx->ffsc_file_to_search);
bd99770
  
bd99770
  			/*
bd99770
  			 * Try without extra suffix and then with suffixes
bd99770
--- 4584,4601 ----
bd99770
  		     * we don't have further wildcards to expand, so we have to
bd99770
  		     * check for the final file now
bd99770
  		     */
bd99770
! 		    for (i = stackp->ffs_filearray_cur;
bd99770
! 					  i < stackp->ffs_filearray_size; ++i)
bd99770
  		    {
bd99770
! 			if (!path_with_url(stackp->ffs_filearray[i])
bd99770
! 				      && !mch_isdir(stackp->ffs_filearray[i]))
bd99770
  			    continue;   /* not a directory */
bd99770
  
bd99770
  			/* prepare the filename to be checked for existance
bd99770
  			 * below */
bd99770
! 			STRCPY(file_path, stackp->ffs_filearray[i]);
bd99770
  			add_pathsep(file_path);
bd99770
! 			STRCAT(file_path, search_ctx->ffsc_file_to_search);
bd99770
  
bd99770
  			/*
bd99770
  			 * Try without extra suffix and then with suffixes
bd99770
***************
bd99770
*** 4606,4617 ****
bd99770
  			{
bd99770
  			    /* if file exists and we didn't already find it */
bd99770
  			    if ((path_with_url(file_path)
bd99770
! 					|| (mch_getperm(file_path) >= 0
bd99770
! 					    && (!ff_search_ctx->ffsc_need_dir
bd99770
! 						|| mch_isdir(file_path))))
bd99770
  #ifndef FF_VERBOSE
bd99770
  				    && (ff_check_visited(
bd99770
! 					    &ff_search_ctx->ffsc_visited_list->ffvl_visited_list,
bd99770
  					    file_path
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  					    , (char_u *)""
bd99770
--- 4609,4623 ----
bd99770
  			{
bd99770
  			    /* if file exists and we didn't already find it */
bd99770
  			    if ((path_with_url(file_path)
bd99770
! 				  || (mch_getperm(file_path) >= 0
bd99770
! 				      && (search_ctx->ffsc_find_what
bd99770
! 							      == FINDFILE_BOTH
bd99770
! 					  || ((search_ctx->ffsc_find_what
bd99770
! 							      == FINDFILE_DIR)
bd99770
! 						   == mch_isdir(file_path)))))
bd99770
  #ifndef FF_VERBOSE
bd99770
  				    && (ff_check_visited(
bd99770
! 					    &search_ctx->ffsc_visited_list->ffvl_visited_list,
bd99770
  					    file_path
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  					    , (char_u *)""
bd99770
***************
bd99770
*** 4622,4628 ****
bd99770
  			    {
bd99770
  #ifdef FF_VERBOSE
bd99770
  				if (ff_check_visited(
bd99770
! 					    &ff_search_ctx->ffsc_visited_list->ffvl_visited_list,
bd99770
  					    file_path
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  					    , (char_u *)""
bd99770
--- 4628,4634 ----
bd99770
  			    {
bd99770
  #ifdef FF_VERBOSE
bd99770
  				if (ff_check_visited(
bd99770
! 					    &search_ctx->ffsc_visited_list->ffvl_visited_list,
bd99770
  					    file_path
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
  					    , (char_u *)""
bd99770
***************
bd99770
*** 4643,4650 ****
bd99770
  #endif
bd99770
  
bd99770
  				/* push dir to examine rest of subdirs later */
bd99770
! 				ctx->ffs_filearray_cur = i + 1;
bd99770
! 				ff_push(ctx);
bd99770
  
bd99770
  				simplify_filename(file_path);
bd99770
  				if (mch_dirname(ff_expand_buffer, MAXPATHL)
bd99770
--- 4649,4656 ----
bd99770
  #endif
bd99770
  
bd99770
  				/* push dir to examine rest of subdirs later */
bd99770
! 				stackp->ffs_filearray_cur = i + 1;
bd99770
! 				ff_push(search_ctx, stackp);
bd99770
  
bd99770
  				simplify_filename(file_path);
bd99770
  				if (mch_dirname(ff_expand_buffer, MAXPATHL)
bd99770
***************
bd99770
*** 4686,4704 ****
bd99770
  		     * still wildcards left, push the directories for further
bd99770
  		     * search
bd99770
  		     */
bd99770
! 		    for (i = ctx->ffs_filearray_cur;
bd99770
! 					     i < ctx->ffs_filearray_size; ++i)
bd99770
  		    {
bd99770
! 			if (!mch_isdir(ctx->ffs_filearray[i]))
bd99770
  			    continue;	/* not a directory */
bd99770
  
bd99770
! 			ff_push(ff_create_stack_element(ctx->ffs_filearray[i],
bd99770
! 				      rest_of_wildcards, ctx->ffs_level - 1, 0));
bd99770
  		    }
bd99770
  		}
bd99770
  #endif
bd99770
! 		ctx->ffs_filearray_cur = 0;
bd99770
! 		ctx->ffs_stage = 1;
bd99770
  	    }
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
--- 4692,4713 ----
bd99770
  		     * still wildcards left, push the directories for further
bd99770
  		     * search
bd99770
  		     */
bd99770
! 		    for (i = stackp->ffs_filearray_cur;
bd99770
! 					  i < stackp->ffs_filearray_size; ++i)
bd99770
  		    {
bd99770
! 			if (!mch_isdir(stackp->ffs_filearray[i]))
bd99770
  			    continue;	/* not a directory */
bd99770
  
bd99770
! 			ff_push(search_ctx,
bd99770
! 				ff_create_stack_element(
bd99770
! 						     stackp->ffs_filearray[i],
bd99770
! 						     rest_of_wildcards,
bd99770
! 						     stackp->ffs_level - 1, 0));
bd99770
  		    }
bd99770
  		}
bd99770
  #endif
bd99770
! 		stackp->ffs_filearray_cur = 0;
bd99770
! 		stackp->ffs_stage = 1;
bd99770
  	    }
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
***************
bd99770
*** 4706,4728 ****
bd99770
  	     * if wildcards contains '**' we have to descent till we reach the
bd99770
  	     * leaves of the directory tree.
bd99770
  	     */
bd99770
! 	    if (STRNCMP(ctx->ffs_wc_path, "**", 2) == 0)
bd99770
  	    {
bd99770
! 		for (i = ctx->ffs_filearray_cur;
bd99770
! 					     i < ctx->ffs_filearray_size; ++i)
bd99770
  		{
bd99770
! 		    if (fnamecmp(ctx->ffs_filearray[i], ctx->ffs_fix_path) == 0)
bd99770
  			continue; /* don't repush same directory */
bd99770
! 		    if (!mch_isdir(ctx->ffs_filearray[i]))
bd99770
  			continue;   /* not a directory */
bd99770
! 		    ff_push(ff_create_stack_element(ctx->ffs_filearray[i],
bd99770
! 				ctx->ffs_wc_path, ctx->ffs_level - 1, 1));
bd99770
  		}
bd99770
  	    }
bd99770
  #endif
bd99770
  
bd99770
  	    /* we are done with the current directory */
bd99770
! 	    ff_free_stack_element(ctx);
bd99770
  
bd99770
  	}
bd99770
  
bd99770
--- 4715,4739 ----
bd99770
  	     * if wildcards contains '**' we have to descent till we reach the
bd99770
  	     * leaves of the directory tree.
bd99770
  	     */
bd99770
! 	    if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0)
bd99770
  	    {
bd99770
! 		for (i = stackp->ffs_filearray_cur;
bd99770
! 					  i < stackp->ffs_filearray_size; ++i)
bd99770
  		{
bd99770
! 		    if (fnamecmp(stackp->ffs_filearray[i],
bd99770
! 						   stackp->ffs_fix_path) == 0)
bd99770
  			continue; /* don't repush same directory */
bd99770
! 		    if (!mch_isdir(stackp->ffs_filearray[i]))
bd99770
  			continue;   /* not a directory */
bd99770
! 		    ff_push(search_ctx,
bd99770
! 			    ff_create_stack_element(stackp->ffs_filearray[i],
bd99770
! 				stackp->ffs_wc_path, stackp->ffs_level - 1, 1));
bd99770
  		}
bd99770
  	    }
bd99770
  #endif
bd99770
  
bd99770
  	    /* we are done with the current directory */
bd99770
! 	    ff_free_stack_element(stackp);
bd99770
  
bd99770
  	}
bd99770
  
bd99770
***************
bd99770
*** 4730,4769 ****
bd99770
  	/* If we reached this, we didn't find anything downwards.
bd99770
  	 * Let's check if we should do an upward search.
bd99770
  	 */
bd99770
! 	if (ff_search_ctx->ffsc_start_dir
bd99770
! 		&& ff_search_ctx->ffsc_stopdirs_v != NULL && !got_int)
bd99770
  	{
bd99770
  	    ff_stack_T  *sptr;
bd99770
  
bd99770
  	    /* is the last starting directory in the stop list? */
bd99770
! 	    if (ff_path_in_stoplist(ff_search_ctx->ffsc_start_dir,
bd99770
! 		       (int)(path_end - ff_search_ctx->ffsc_start_dir),
bd99770
! 		       ff_search_ctx->ffsc_stopdirs_v) == TRUE)
bd99770
  		break;
bd99770
  
bd99770
  	    /* cut of last dir */
bd99770
! 	    while (path_end > ff_search_ctx->ffsc_start_dir
bd99770
! 		    && vim_ispathsep(*path_end))
bd99770
  		path_end--;
bd99770
! 	    while (path_end > ff_search_ctx->ffsc_start_dir
bd99770
! 		    && !vim_ispathsep(path_end[-1]))
bd99770
  		path_end--;
bd99770
  	    *path_end = 0;
bd99770
  	    path_end--;
bd99770
  
bd99770
! 	    if (*ff_search_ctx->ffsc_start_dir == 0)
bd99770
  		break;
bd99770
  
bd99770
! 	    STRCPY(file_path, ff_search_ctx->ffsc_start_dir);
bd99770
  	    add_pathsep(file_path);
bd99770
! 	    STRCAT(file_path, ff_search_ctx->ffsc_fix_path);
bd99770
  
bd99770
  	    /* create a new stack entry */
bd99770
  	    sptr = ff_create_stack_element(file_path,
bd99770
! 		    ff_search_ctx->ffsc_wc_path, ff_search_ctx->ffsc_level, 0);
bd99770
  	    if (sptr == NULL)
bd99770
  		break;
bd99770
! 	    ff_push(sptr);
bd99770
  	}
bd99770
  	else
bd99770
  	    break;
bd99770
--- 4741,4780 ----
bd99770
  	/* If we reached this, we didn't find anything downwards.
bd99770
  	 * Let's check if we should do an upward search.
bd99770
  	 */
bd99770
! 	if (search_ctx->ffsc_start_dir
bd99770
! 		&& search_ctx->ffsc_stopdirs_v != NULL && !got_int)
bd99770
  	{
bd99770
  	    ff_stack_T  *sptr;
bd99770
  
bd99770
  	    /* is the last starting directory in the stop list? */
bd99770
! 	    if (ff_path_in_stoplist(search_ctx->ffsc_start_dir,
bd99770
! 		       (int)(path_end - search_ctx->ffsc_start_dir),
bd99770
! 		       search_ctx->ffsc_stopdirs_v) == TRUE)
bd99770
  		break;
bd99770
  
bd99770
  	    /* cut of last dir */
bd99770
! 	    while (path_end > search_ctx->ffsc_start_dir
bd99770
! 						  && vim_ispathsep(*path_end))
bd99770
  		path_end--;
bd99770
! 	    while (path_end > search_ctx->ffsc_start_dir
bd99770
! 					      && !vim_ispathsep(path_end[-1]))
bd99770
  		path_end--;
bd99770
  	    *path_end = 0;
bd99770
  	    path_end--;
bd99770
  
bd99770
! 	    if (*search_ctx->ffsc_start_dir == 0)
bd99770
  		break;
bd99770
  
bd99770
! 	    STRCPY(file_path, search_ctx->ffsc_start_dir);
bd99770
  	    add_pathsep(file_path);
bd99770
! 	    STRCAT(file_path, search_ctx->ffsc_fix_path);
bd99770
  
bd99770
  	    /* create a new stack entry */
bd99770
  	    sptr = ff_create_stack_element(file_path,
bd99770
! 		    search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
bd99770
  	    if (sptr == NULL)
bd99770
  		break;
bd99770
! 	    ff_push(search_ctx, sptr);
bd99770
  	}
bd99770
  	else
bd99770
  	    break;
bd99770
***************
bd99770
*** 4779,4794 ****
bd99770
   * Can handle it if the passed search_context is NULL;
bd99770
   */
bd99770
      void
bd99770
! vim_findfile_free_visited(search_ctx)
bd99770
!     void	*search_ctx;
bd99770
  {
bd99770
!     if (search_ctx == NULL)
bd99770
! 	return;
bd99770
  
bd99770
!     ff_search_ctx = (ff_search_ctx_T *)search_ctx;
bd99770
  
bd99770
!     vim_findfile_free_visited_list(&ff_search_ctx->ffsc_visited_lists_list);
bd99770
!     vim_findfile_free_visited_list(&ff_search_ctx->ffsc_dir_visited_lists_list);
bd99770
  }
bd99770
  
bd99770
      static void
bd99770
--- 4790,4806 ----
bd99770
   * Can handle it if the passed search_context is NULL;
bd99770
   */
bd99770
      void
bd99770
! vim_findfile_free_visited(search_ctx_arg)
bd99770
!     void	*search_ctx_arg;
bd99770
  {
bd99770
!     ff_search_ctx_T *search_ctx;
bd99770
  
bd99770
!     if (search_ctx_arg == NULL)
bd99770
! 	return;
bd99770
  
bd99770
!     search_ctx = (ff_search_ctx_T *)search_ctx_arg;
bd99770
!     vim_findfile_free_visited_list(&search_ctx->ffsc_visited_lists_list);
bd99770
!     vim_findfile_free_visited_list(&search_ctx->ffsc_dir_visited_lists_list);
bd99770
  }
bd99770
  
bd99770
      static void
bd99770
***************
bd99770
*** 5103,5135 ****
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
!  * push a dir on the directory stack
bd99770
   */
bd99770
      static void
bd99770
! ff_push(ctx)
bd99770
!     ff_stack_T *ctx;
bd99770
  {
bd99770
      /* check for NULL pointer, not to return an error to the user, but
bd99770
       * to prevent a crash */
bd99770
!     if (ctx != NULL)
bd99770
      {
bd99770
! 	ctx->ffs_prev   = ff_search_ctx->ffsc_stack_ptr;
bd99770
! 	ff_search_ctx->ffsc_stack_ptr = ctx;
bd99770
      }
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
!  * pop a dir from the directory stack
bd99770
!  * returns NULL if stack is empty
bd99770
   */
bd99770
      static ff_stack_T *
bd99770
! ff_pop()
bd99770
  {
bd99770
      ff_stack_T  *sptr;
bd99770
  
bd99770
!     sptr = ff_search_ctx->ffsc_stack_ptr;
bd99770
!     if (ff_search_ctx->ffsc_stack_ptr != NULL)
bd99770
! 	ff_search_ctx->ffsc_stack_ptr = ff_search_ctx->ffsc_stack_ptr->ffs_prev;
bd99770
  
bd99770
      return sptr;
bd99770
  }
bd99770
--- 5115,5149 ----
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
!  * Push a dir on the directory stack.
bd99770
   */
bd99770
      static void
bd99770
! ff_push(search_ctx, stack_ptr)
bd99770
!     ff_search_ctx_T *search_ctx;
bd99770
!     ff_stack_T	    *stack_ptr;
bd99770
  {
bd99770
      /* check for NULL pointer, not to return an error to the user, but
bd99770
       * to prevent a crash */
bd99770
!     if (stack_ptr != NULL)
bd99770
      {
bd99770
! 	stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr;
bd99770
! 	search_ctx->ffsc_stack_ptr = stack_ptr;
bd99770
      }
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
!  * Pop a dir from the directory stack.
bd99770
!  * Returns NULL if stack is empty.
bd99770
   */
bd99770
      static ff_stack_T *
bd99770
! ff_pop(search_ctx)
bd99770
!     ff_search_ctx_T *search_ctx;
bd99770
  {
bd99770
      ff_stack_T  *sptr;
bd99770
  
bd99770
!     sptr = search_ctx->ffsc_stack_ptr;
bd99770
!     if (search_ctx->ffsc_stack_ptr != NULL)
bd99770
! 	search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_prev;
bd99770
  
bd99770
      return sptr;
bd99770
  }
bd99770
***************
bd99770
*** 5138,5199 ****
bd99770
   * free the given stack element
bd99770
   */
bd99770
      static void
bd99770
! ff_free_stack_element(ctx)
bd99770
!     ff_stack_T  *ctx;
bd99770
  {
bd99770
      /* vim_free handles possible NULL pointers */
bd99770
!     vim_free(ctx->ffs_fix_path);
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     vim_free(ctx->ffs_wc_path);
bd99770
  #endif
bd99770
  
bd99770
!     if (ctx->ffs_filearray != NULL)
bd99770
! 	FreeWild(ctx->ffs_filearray_size, ctx->ffs_filearray);
bd99770
  
bd99770
!     vim_free(ctx);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
!  * clear the search context
bd99770
   */
bd99770
      static void
bd99770
! ff_clear()
bd99770
  {
bd99770
      ff_stack_T   *sptr;
bd99770
  
bd99770
      /* clear up stack */
bd99770
!     while ((sptr = ff_pop()) != NULL)
bd99770
  	ff_free_stack_element(sptr);
bd99770
  
bd99770
!     vim_free(ff_search_ctx->ffsc_file_to_search);
bd99770
!     vim_free(ff_search_ctx->ffsc_start_dir);
bd99770
!     vim_free(ff_search_ctx->ffsc_fix_path);
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     vim_free(ff_search_ctx->ffsc_wc_path);
bd99770
  #endif
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     if (ff_search_ctx->ffsc_stopdirs_v != NULL)
bd99770
      {
bd99770
  	int  i = 0;
bd99770
  
bd99770
! 	while (ff_search_ctx->ffsc_stopdirs_v[i] != NULL)
bd99770
  	{
bd99770
! 	    vim_free(ff_search_ctx->ffsc_stopdirs_v[i]);
bd99770
  	    i++;
bd99770
  	}
bd99770
! 	vim_free(ff_search_ctx->ffsc_stopdirs_v);
bd99770
      }
bd99770
!     ff_search_ctx->ffsc_stopdirs_v = NULL;
bd99770
  #endif
bd99770
  
bd99770
      /* reset everything */
bd99770
!     ff_search_ctx->ffsc_file_to_search	= NULL;
bd99770
!     ff_search_ctx->ffsc_start_dir	= NULL;
bd99770
!     ff_search_ctx->ffsc_fix_path	= NULL;
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     ff_search_ctx->ffsc_wc_path		= NULL;
bd99770
!     ff_search_ctx->ffsc_level		= 0;
bd99770
  #endif
bd99770
  }
bd99770
  
bd99770
--- 5152,5214 ----
bd99770
   * free the given stack element
bd99770
   */
bd99770
      static void
bd99770
! ff_free_stack_element(stack_ptr)
bd99770
!     ff_stack_T  *stack_ptr;
bd99770
  {
bd99770
      /* vim_free handles possible NULL pointers */
bd99770
!     vim_free(stack_ptr->ffs_fix_path);
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     vim_free(stack_ptr->ffs_wc_path);
bd99770
  #endif
bd99770
  
bd99770
!     if (stack_ptr->ffs_filearray != NULL)
bd99770
! 	FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray);
bd99770
  
bd99770
!     vim_free(stack_ptr);
bd99770
  }
bd99770
  
bd99770
  /*
bd99770
!  * Clear the search context, but NOT the visited list.
bd99770
   */
bd99770
      static void
bd99770
! ff_clear(search_ctx)
bd99770
!     ff_search_ctx_T *search_ctx;
bd99770
  {
bd99770
      ff_stack_T   *sptr;
bd99770
  
bd99770
      /* clear up stack */
bd99770
!     while ((sptr = ff_pop(search_ctx)) != NULL)
bd99770
  	ff_free_stack_element(sptr);
bd99770
  
bd99770
!     vim_free(search_ctx->ffsc_file_to_search);
bd99770
!     vim_free(search_ctx->ffsc_start_dir);
bd99770
!     vim_free(search_ctx->ffsc_fix_path);
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     vim_free(search_ctx->ffsc_wc_path);
bd99770
  #endif
bd99770
  
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     if (search_ctx->ffsc_stopdirs_v != NULL)
bd99770
      {
bd99770
  	int  i = 0;
bd99770
  
bd99770
! 	while (search_ctx->ffsc_stopdirs_v[i] != NULL)
bd99770
  	{
bd99770
! 	    vim_free(search_ctx->ffsc_stopdirs_v[i]);
bd99770
  	    i++;
bd99770
  	}
bd99770
! 	vim_free(search_ctx->ffsc_stopdirs_v);
bd99770
      }
bd99770
!     search_ctx->ffsc_stopdirs_v = NULL;
bd99770
  #endif
bd99770
  
bd99770
      /* reset everything */
bd99770
!     search_ctx->ffsc_file_to_search = NULL;
bd99770
!     search_ctx->ffsc_start_dir = NULL;
bd99770
!     search_ctx->ffsc_fix_path = NULL;
bd99770
  #ifdef FEAT_PATH_EXTRA
bd99770
!     search_ctx->ffsc_wc_path = NULL;
bd99770
!     search_ctx->ffsc_level = 0;
bd99770
  #endif
bd99770
  }
bd99770
  
bd99770
***************
bd99770
*** 5242,5248 ****
bd99770
  
bd99770
  #if defined(FEAT_SEARCHPATH) || defined(PROTO)
bd99770
  /*
bd99770
!  * Find the file name "ptr[len]" in the path.
bd99770
   *
bd99770
   * On the first call set the parameter 'first' to TRUE to initialize
bd99770
   * the search.  For repeating calls to FALSE.
bd99770
--- 5257,5263 ----
bd99770
  
bd99770
  #if defined(FEAT_SEARCHPATH) || defined(PROTO)
bd99770
  /*
bd99770
!  * Find the file name "ptr[len]" in the path.  Also finds directory names.
bd99770
   *
bd99770
   * On the first call set the parameter 'first' to TRUE to initialize
bd99770
   * the search.  For repeating calls to FALSE.
bd99770
***************
bd99770
*** 5276,5282 ****
bd99770
  {
bd99770
      return find_file_in_path_option(ptr, len, options, first,
bd99770
  	    *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path,
bd99770
! 	    FALSE, rel_fname, curbuf->b_p_sua);
bd99770
  }
bd99770
  
bd99770
  static char_u	*ff_file_to_find = NULL;
bd99770
--- 5291,5297 ----
bd99770
  {
bd99770
      return find_file_in_path_option(ptr, len, options, first,
bd99770
  	    *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path,
bd99770
! 	    FINDFILE_BOTH, rel_fname, curbuf->b_p_sua);
bd99770
  }
bd99770
  
bd99770
  static char_u	*ff_file_to_find = NULL;
bd99770
***************
bd99770
*** 5309,5325 ****
bd99770
      char_u	*rel_fname;	/* file name searching relative to */
bd99770
  {
bd99770
      return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath,
bd99770
! 					       TRUE, rel_fname, (char_u *)"");
bd99770
  }
bd99770
  
bd99770
      char_u *
bd99770
! find_file_in_path_option(ptr, len, options, first, path_option, need_dir, rel_fname, suffixes)
bd99770
      char_u	*ptr;		/* file name */
bd99770
      int		len;		/* length of file name */
bd99770
      int		options;
bd99770
      int		first;		/* use count'th matching file name */
bd99770
      char_u	*path_option;	/* p_path or p_cdpath */
bd99770
!     int		need_dir;	/* looking for directory name */
bd99770
      char_u	*rel_fname;	/* file name we are looking relative to. */
bd99770
      char_u	*suffixes;	/* list of suffixes, 'suffixesadd' option */
bd99770
  {
bd99770
--- 5324,5340 ----
bd99770
      char_u	*rel_fname;	/* file name searching relative to */
bd99770
  {
bd99770
      return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath,
bd99770
! 				       FINDFILE_DIR, rel_fname, (char_u *)"");
bd99770
  }
bd99770
  
bd99770
      char_u *
bd99770
! find_file_in_path_option(ptr, len, options, first, path_option, find_what, rel_fname, suffixes)
bd99770
      char_u	*ptr;		/* file name */
bd99770
      int		len;		/* length of file name */
bd99770
      int		options;
bd99770
      int		first;		/* use count'th matching file name */
bd99770
      char_u	*path_option;	/* p_path or p_cdpath */
bd99770
!     int		find_what;	/* FINDFILE_FILE, _DIR or _BOTH */
bd99770
      char_u	*rel_fname;	/* file name we are looking relative to. */
bd99770
      char_u	*suffixes;	/* list of suffixes, 'suffixesadd' option */
bd99770
  {
bd99770
***************
bd99770
*** 5421,5432 ****
bd99770
  #ifdef DJGPP
bd99770
  			    /* "C:" by itself will fail for mch_getperm(),
bd99770
  			     * assume it's always valid. */
bd99770
! 			    (need_dir && NameBuff[0] != NUL
bd99770
  				  && NameBuff[1] == ':'
bd99770
  				  && NameBuff[2] == NUL) ||
bd99770
  #endif
bd99770
  			    (mch_getperm(NameBuff) >= 0
bd99770
! 				       && (!need_dir || mch_isdir(NameBuff))))
bd99770
  		    {
bd99770
  			file_name = vim_strsave(NameBuff);
bd99770
  			goto theend;
bd99770
--- 5436,5449 ----
bd99770
  #ifdef DJGPP
bd99770
  			    /* "C:" by itself will fail for mch_getperm(),
bd99770
  			     * assume it's always valid. */
bd99770
! 			    (find_what != FINDFILE_FILE && NameBuff[0] != NUL
bd99770
  				  && NameBuff[1] == ':'
bd99770
  				  && NameBuff[2] == NUL) ||
bd99770
  #endif
bd99770
  			    (mch_getperm(NameBuff) >= 0
bd99770
! 			     && (find_what == FINDFILE_BOTH
bd99770
! 				 || ((find_what == FINDFILE_DIR)
bd99770
! 						    == mch_isdir(NameBuff)))))
bd99770
  		    {
bd99770
  			file_name = vim_strsave(NameBuff);
bd99770
  			goto theend;
bd99770
***************
bd99770
*** 5457,5465 ****
bd99770
  	{
bd99770
  	    if (did_findfile_init)
bd99770
  	    {
bd99770
- 		ff_search_ctx->ffsc_need_dir = need_dir;
bd99770
  		file_name = vim_findfile(fdip_search_ctx);
bd99770
- 		ff_search_ctx->ffsc_need_dir = FALSE;
bd99770
  		if (file_name != NULL)
bd99770
  		    break;
bd99770
  
bd99770
--- 5474,5480 ----
bd99770
***************
bd99770
*** 5492,5498 ****
bd99770
  		r_ptr = NULL;
bd99770
  #endif
bd99770
  		fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find,
bd99770
! 					    r_ptr, 100, FALSE, TRUE,
bd99770
  					   fdip_search_ctx, FALSE, rel_fname);
bd99770
  		if (fdip_search_ctx != NULL)
bd99770
  		    did_findfile_init = TRUE;
bd99770
--- 5507,5513 ----
bd99770
  		r_ptr = NULL;
bd99770
  #endif
bd99770
  		fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find,
bd99770
! 					    r_ptr, 100, FALSE, find_what,
bd99770
  					   fdip_search_ctx, FALSE, rel_fname);
bd99770
  		if (fdip_search_ctx != NULL)
bd99770
  		    did_findfile_init = TRUE;
bd99770
***************
bd99770
*** 5504,5510 ****
bd99770
      {
bd99770
  	if (first == TRUE)
bd99770
  	{
bd99770
! 	    if (need_dir)
bd99770
  		EMSG2(_("E344: Can't find directory \"%s\" in cdpath"),
bd99770
  			ff_file_to_find);
bd99770
  	    else
bd99770
--- 5519,5525 ----
bd99770
      {
bd99770
  	if (first == TRUE)
bd99770
  	{
bd99770
! 	    if (find_what == FINDFILE_DIR)
bd99770
  		EMSG2(_("E344: Can't find directory \"%s\" in cdpath"),
bd99770
  			ff_file_to_find);
bd99770
  	    else
bd99770
***************
bd99770
*** 5513,5519 ****
bd99770
  	}
bd99770
  	else
bd99770
  	{
bd99770
! 	    if (need_dir)
bd99770
  		EMSG2(_("E346: No more directory \"%s\" found in cdpath"),
bd99770
  			ff_file_to_find);
bd99770
  	    else
bd99770
--- 5528,5534 ----
bd99770
  	}
bd99770
  	else
bd99770
  	{
bd99770
! 	    if (find_what == FINDFILE_DIR)
bd99770
  		EMSG2(_("E346: No more directory \"%s\" found in cdpath"),
bd99770
  			ff_file_to_find);
bd99770
  	    else
bd99770
*** ../vim-7.1.255/src/vim.h	Sat Jan 19 15:55:51 2008
bd99770
--- src/vim.h	Tue Jan 22 22:35:16 2008
bd99770
***************
bd99770
*** 721,726 ****
bd99770
--- 721,731 ----
bd99770
  /* Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND
bd99770
   * is used when executing commands and EW_SILENT for interactive expanding. */
bd99770
  
bd99770
+ /* Flags for find_file_*() functions. */
bd99770
+ #define FINDFILE_FILE	0	/* only files */
bd99770
+ #define FINDFILE_DIR	1	/* only directories */
bd99770
+ #define FINDFILE_BOTH	2	/* files and directories */
bd99770
+ 
bd99770
  #ifdef FEAT_VERTSPLIT
bd99770
  # define W_WINCOL(wp)	(wp->w_wincol)
bd99770
  # define W_WIDTH(wp)	(wp->w_width)
bd99770
*** ../vim-7.1.255/src/tag.c	Sat Jan 19 15:55:51 2008
bd99770
--- src/tag.c	Wed Feb 13 18:02:32 2008
bd99770
***************
bd99770
*** 2669,2676 ****
bd99770
  
bd99770
  	    tnp->tn_search_ctx = vim_findfile_init(buf, filename,
bd99770
  		    r_ptr, 100,
bd99770
! 		    FALSE, /* don't free visited list */
bd99770
! 		    FALSE, /* we search for a file */
bd99770
  		    tnp->tn_search_ctx, TRUE, curbuf->b_ffname);
bd99770
  	    if (tnp->tn_search_ctx != NULL)
bd99770
  		tnp->tn_did_filefind_init = TRUE;
bd99770
--- 2669,2676 ----
bd99770
  
bd99770
  	    tnp->tn_search_ctx = vim_findfile_init(buf, filename,
bd99770
  		    r_ptr, 100,
bd99770
! 		    FALSE,         /* don't free visited list */
bd99770
! 		    FINDFILE_FILE, /* we search for a file */
bd99770
  		    tnp->tn_search_ctx, TRUE, curbuf->b_ffname);
bd99770
  	    if (tnp->tn_search_ctx != NULL)
bd99770
  		tnp->tn_did_filefind_init = TRUE;
bd99770
***************
bd99770
*** 2691,2696 ****
bd99770
--- 2691,2697 ----
bd99770
  {
bd99770
      vim_free(tnp->tn_tags);
bd99770
      vim_findfile_cleanup(tnp->tn_search_ctx);
bd99770
+     tnp->tn_search_ctx = NULL;
bd99770
      ga_clear_strings(&tag_fnames);
bd99770
  }
bd99770
  
bd99770
*** ../vim-7.1.255/src/version.c	Wed Feb 20 11:27:59 2008
bd99770
--- src/version.c	Wed Feb 20 12:09:54 2008
bd99770
***************
bd99770
*** 668,669 ****
bd99770
--- 668,671 ----
bd99770
  {   /* Add new patch number below this line */
bd99770
+ /**/
bd99770
+     256,
bd99770
  /**/
bd99770
bd99770
-- 
bd99770
hundred-and-one symptoms of being an internet addict:
bd99770
38. You wake up at 3 a.m. to go to the bathroom and stop and check your e-mail
bd99770
    on the way back to bed.
bd99770
bd99770
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
bd99770
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
bd99770
\\\        download, build and distribute -- http://www.A-A-P.org        ///
bd99770
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///