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