A user recently asked Neovim project to change ":find" to work
breadth-first as opposed to depth-first, claiming it would find
"wrong/a/b/c/foo" before it found "goal/foo". (
https://github.com/neovim/neovim/issues/1035)

Included is two patches. The first enabling BFS through a new option,
'breadthfirst'. The second updating the identifiers and documentation to
not assume the underlying data structure is a stack.

One concern I didn't know to address is this comment:

misc2.c +4819
 * The search algorithm is depth first. To change this replace the
 * stack with a list (don't forget to leave partly searched directories on
the
 * top of the list).

Seems to me like this code is well factored enough that just changing
ff_push() and _pop() would be sufficient, but I'm not 100% on that.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt
--- a/runtime/doc/editing.txt
+++ b/runtime/doc/editing.txt
@@ -252,6 +252,9 @@
                                                        *:fin* *:find*
 :fin[d][!] [++opt] [+cmd] {file}
                        Find {file} in 'path' and then |:edit| it.
+
+                       By default uses a depth-first search of directories.
+                       Set 'breadthfirst' to search breadth-first.
                        {not in Vi} {not available when the |+file_in_path|
                        feature was disabled at compile time}
 
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1190,6 +1190,15 @@
        don't see it when editing.  When you don't change the options, the BOM
        will be restored when writing the file.
 
+                                               *'breadthfirst'* *'bfs'*
+'breadthfirst' 'bfs'   boolean (default off)
+                       global
+                       {not in Vi}
+       When set, causes ":find {file}" to search for {file} in the 'path'
+       closest to the current directory, rather than lexically first. For
+       example, if z/z/z/{file} and a/a/{file} are both in 'path', the first
+       will be returned by default, and the second with 'bfs' set.
+
                                                *'breakat'* *'brk'*
 'breakat' 'brk'                string  (default " ^I!@*-+;:,./?")
                        global
diff --git a/src/misc2.c b/src/misc2.c
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -4170,7 +4170,7 @@
  */
 typedef struct ff_stack
 {
-    struct ff_stack    *ffs_prev;
+    struct ff_stack    *ffs_child;
 
     /* the fix part (no wildcards) and the part containing the wildcards
      * of the search path
@@ -4264,6 +4264,7 @@
 /*
  * The search context:
  *   ffsc_stack_ptr:   the stack for the dirs to search
+ *   ffsc_stack_last:   the last element in the queue when using BFS
  *   ffsc_visited_list: the currently active visited list
  *   ffsc_dir_visited_list: the currently active visited list for search dirs
  *   ffsc_visited_lists_list: the list of all visited lists
@@ -4281,6 +4282,7 @@
 typedef struct ff_search_ctx_T
 {
      ff_stack_T                        *ffsc_stack_ptr;
+     ff_stack_T                        *ffsc_stack_last;
      ff_visited_list_hdr_T     *ffsc_visited_list;
      ff_visited_list_hdr_T     *ffsc_dir_visited_list;
      ff_visited_list_hdr_T     *ffsc_visited_lists_list;
@@ -4310,8 +4312,10 @@
 static int ff_wc_equal __ARGS((char_u *s1, char_u *s2));
 #endif
 
-static void ff_push __ARGS((ff_search_ctx_T *search_ctx, ff_stack_T 
*stack_ptr));
-static ff_stack_T *ff_pop __ARGS((ff_search_ctx_T *search_ctx));
+static void ffs_push __ARGS((ff_search_ctx_T *search_ctx, ff_stack_T 
*stack_ptr));
+static void ffq_push __ARGS((ff_search_ctx_T *search_ctx, ff_stack_T 
*queue_ptr));
+static ff_stack_T *ffs_pop __ARGS((ff_search_ctx_T *search_ctx));
+static ff_stack_T *ffq_pop __ARGS((ff_search_ctx_T *search_ctx));
 static void ff_clear __ARGS((ff_search_ctx_T *search_ctx));
 static void ff_free_stack_element __ARGS((ff_stack_T *stack_ptr));
 #ifdef FEAT_PATH_EXTRA
@@ -4325,6 +4329,15 @@
 
 static char_u e_pathtoolong[] = N_("E854: path too long for completion");
 
+
+/* 
+ * Function pointers to the state implementation.
+ * Set to ffq_push() and ffq_pop() when using BFS.
+ * Set to ffs_push() and ffs_pop() when using DFS.
+ */
+static void (*ff_push) (ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr);
+static ff_stack_T *(*ff_pop)(ff_search_ctx_T *search_ctx);
+
 #if 0
 /*
  * if someone likes findfirst/findnext, here are the functions
@@ -4433,6 +4446,14 @@
     ff_stack_T         *sptr;
     ff_search_ctx_T    *search_ctx;
 
+    if (p_bfs) {
+       ff_push = ffq_push;
+       ff_pop  = ffq_pop;
+    } else {
+       ff_push = ffs_push;
+       ff_pop  = ffs_pop;
+    }
+
     /* If a search context is given by the caller, reuse it, else allocate a
      * new one.
      */
@@ -5559,7 +5580,7 @@
     if (new == NULL)
        return NULL;
 
-    new->ffs_prev         = NULL;
+    new->ffs_child        = NULL;
     new->ffs_filearray    = NULL;
     new->ffs_filearray_size = 0;
     new->ffs_filearray_cur  = 0;
@@ -5595,7 +5616,7 @@
  * Push a dir on the directory stack.
  */
     static void
-ff_push(search_ctx, stack_ptr)
+ffs_push(search_ctx, stack_ptr)
     ff_search_ctx_T *search_ctx;
     ff_stack_T     *stack_ptr;
 {
@@ -5603,24 +5624,66 @@
      * to prevent a crash */
     if (stack_ptr != NULL)
     {
-       stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr;
+       stack_ptr->ffs_child = search_ctx->ffsc_stack_ptr;
        search_ctx->ffsc_stack_ptr = stack_ptr;
     }
 }
 
 /*
+ * Push a dir on the directory queue.
+ */
+    static void
+ffq_push(search_ctx, queue_ptr)
+    ff_search_ctx_T *search_ctx;
+    ff_stack_T     *queue_ptr;
+{
+    /* check for NULL pointer, not to return an error to the user, but
+     * to prevent a crash */
+    if (queue_ptr != NULL)
+    {
+       if (search_ctx->ffsc_stack_ptr && search_ctx->ffsc_stack_last)
+           search_ctx->ffsc_stack_last->ffs_child = queue_ptr;
+        else if (search_ctx->ffsc_stack_ptr)
+           search_ctx->ffsc_stack_ptr->ffs_child = queue_ptr;
+        else
+           search_ctx->ffsc_stack_ptr = queue_ptr;
+
+       search_ctx->ffsc_stack_last = queue_ptr;
+    }
+}
+
+/*
  * Pop a dir from the directory stack.
  * Returns NULL if stack is empty.
  */
     static ff_stack_T *
-ff_pop(search_ctx)
+ffs_pop(search_ctx)
     ff_search_ctx_T *search_ctx;
 {
     ff_stack_T  *sptr;
 
     sptr = search_ctx->ffsc_stack_ptr;
     if (search_ctx->ffsc_stack_ptr != NULL)
-       search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_prev;
+       search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_child;
+
+    return sptr;
+}
+
+/*
+ * Pop a dir from the directory queue.
+ * Returns NULL if queue is empty.
+ */
+    static ff_stack_T *
+ffq_pop(search_ctx)
+    ff_search_ctx_T *search_ctx;
+{
+    ff_stack_T  *sptr;
+
+    sptr = search_ctx->ffsc_stack_ptr;
+    if (search_ctx->ffsc_stack_ptr != NULL) {
+       search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_child;
+       sptr->ffs_child = NULL;
+    }
 
     return sptr;
 }
@@ -5687,6 +5750,7 @@
     search_ctx->ffsc_wc_path = NULL;
     search_ctx->ffsc_level = 0;
 #endif
+    search_ctx->ffsc_stack_last = NULL;
 }
 
 #ifdef FEAT_PATH_EXTRA
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -643,6 +643,9 @@
                            (char_u *)NULL, PV_NONE,
 #endif
                            {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
+    {"breadthfirst", "bfs",  P_BOOL|P_VIM,
+                           (char_u *)&p_bfs, PV_NONE,
+                           {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
     {"breakat",            "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
 #ifdef FEAT_LINEBREAK
                            (char_u *)&p_breakat, PV_NONE,
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -354,6 +354,7 @@
 #ifdef FEAT_BROWSE
 EXTERN char_u  *p_bsdir;       /* 'browsedir' */
 #endif
+EXTERN char_u   p_bfs;          /* 'breadthfirst` */
 #ifdef MSDOS
 EXTERN int     p_biosk;        /* 'bioskey' */
 EXTERN int     p_consk;        /* 'conskey' */
diff --git a/src/misc2.c b/src/misc2.c
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -4166,11 +4166,11 @@
  */
 
 /*
- * type for the directory search stack
- */
-typedef struct ff_stack
-{
-    struct ff_stack    *ffs_child;
+ * type for the directory search state
+ */
+typedef struct ff_state
+{
+    struct ff_state    *ffs_child;
 
     /* the fix part (no wildcards) and the part containing the wildcards
      * of the search path
@@ -4200,7 +4200,7 @@
 
     /* Did we already expand '**' to an empty string? */
     int                        ffs_star_star_empty;
-} ff_stack_T;
+} ff_state_T;
 
 /*
  * type for already visited directories or files.
@@ -4263,8 +4263,8 @@
 
 /*
  * The search context:
- *   ffsc_stack_ptr:   the stack for the dirs to search
- *   ffsc_stack_last:   the last element in the queue when using BFS
+ *   ffsc_state_ptr:   the stack for the dirs to search
+ *   ffsc_state_last:   the last element in the queue when using BFS
  *   ffsc_visited_list: the currently active visited list
  *   ffsc_dir_visited_list: the currently active visited list for search dirs
  *   ffsc_visited_lists_list: the list of all visited lists
@@ -4281,8 +4281,8 @@
  */
 typedef struct ff_search_ctx_T
 {
-     ff_stack_T                        *ffsc_stack_ptr;
-     ff_stack_T                        *ffsc_stack_last;
+     ff_state_T                        *ffsc_state_ptr;
+     ff_state_T                        *ffsc_state_last;
      ff_visited_list_hdr_T     *ffsc_visited_list;
      ff_visited_list_hdr_T     *ffsc_dir_visited_list;
      ff_visited_list_hdr_T     *ffsc_visited_lists_list;
@@ -4312,16 +4312,16 @@
 static int ff_wc_equal __ARGS((char_u *s1, char_u *s2));
 #endif
 
-static void ffs_push __ARGS((ff_search_ctx_T *search_ctx, ff_stack_T 
*stack_ptr));
-static void ffq_push __ARGS((ff_search_ctx_T *search_ctx, ff_stack_T 
*queue_ptr));
-static ff_stack_T *ffs_pop __ARGS((ff_search_ctx_T *search_ctx));
-static ff_stack_T *ffq_pop __ARGS((ff_search_ctx_T *search_ctx));
+static void ffs_push __ARGS((ff_search_ctx_T *search_ctx, ff_state_T 
*stack_ptr));
+static void ffq_push __ARGS((ff_search_ctx_T *search_ctx, ff_state_T 
*queue_ptr));
+static ff_state_T *ffs_pop __ARGS((ff_search_ctx_T *search_ctx));
+static ff_state_T *ffq_pop __ARGS((ff_search_ctx_T *search_ctx));
 static void ff_clear __ARGS((ff_search_ctx_T *search_ctx));
-static void ff_free_stack_element __ARGS((ff_stack_T *stack_ptr));
+static void ff_free_state_element __ARGS((ff_state_T *state_ptr));
 #ifdef FEAT_PATH_EXTRA
-static ff_stack_T *ff_create_stack_element __ARGS((char_u *, char_u *, int, 
int));
+static ff_state_T *ff_create_state_element __ARGS((char_u *, char_u *, int, 
int));
 #else
-static ff_stack_T *ff_create_stack_element __ARGS((char_u *, int, int));
+static ff_state_T *ff_create_state_element __ARGS((char_u *, int, int));
 #endif
 #ifdef FEAT_PATH_EXTRA
 static int ff_path_in_stoplist __ARGS((char_u *, int, char_u **));
@@ -4335,8 +4335,8 @@
  * Set to ffq_push() and ffq_pop() when using BFS.
  * Set to ffs_push() and ffs_pop() when using DFS.
  */
-static void (*ff_push) (ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr);
-static ff_stack_T *(*ff_pop)(ff_search_ctx_T *search_ctx);
+static void (*ff_push) (ff_search_ctx_T *search_ctx, ff_state_T *state_ptr);
+static ff_state_T *(*ff_pop)(ff_search_ctx_T *search_ctx);
 
 #if 0
 /*
@@ -4443,7 +4443,7 @@
 #ifdef FEAT_PATH_EXTRA
     char_u             *wc_part;
 #endif
-    ff_stack_T         *sptr;
+    ff_state_T         *sptr;
     ff_search_ctx_T    *search_ctx;
 
     if (p_bfs) {
@@ -4755,7 +4755,7 @@
        vim_free(buf);
     }
 
-    sptr = ff_create_stack_element(ff_expand_buffer,
+    sptr = ff_create_state_element(ff_expand_buffer,
 #ifdef FEAT_PATH_EXTRA
            search_ctx->ffsc_wc_path,
 #endif
@@ -4836,10 +4836,6 @@
  * To get all matching files call this function until you get NULL.
  *
  * If the passed search_context is NULL, NULL is returned.
- *
- * The search algorithm is depth first. To change this replace the
- * stack with a list (don't forget to leave partly searched directories on the
- * top of the list).
  */
     char_u *
 vim_findfile(search_ctx_arg)
@@ -4850,7 +4846,7 @@
     char_u     *rest_of_wildcards;
     char_u     *path_end = NULL;
 #endif
-    ff_stack_T *stackp;
+    ff_state_T *statep;
 #if defined(FEAT_SEARCHPATH) || defined(FEAT_PATH_EXTRA)
     int                len;
 #endif
@@ -4893,9 +4889,9 @@
            if (got_int)
                break;
 
-           /* get directory to work on from stack */
-           stackp = ff_pop(search_ctx);
-           if (stackp == NULL)
+           /* get directory to work on from state */
+           statep = ff_pop(search_ctx);
+           if (statep == NULL)
                break;
 
            /*
@@ -4915,14 +4911,14 @@
             *  /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop)
             *
             * This check is only needed for directories we work on for the
-            * first time (hence stackp->ff_filearray == NULL)
+            * first time (hence statep->ff_filearray == NULL)
             */
-           if (stackp->ffs_filearray == NULL
+           if (statep->ffs_filearray == NULL
                    && ff_check_visited(&search_ctx->ffsc_dir_visited_list
                                                          ->ffvl_visited_list,
-                       stackp->ffs_fix_path
+                       statep->ffs_fix_path
 #ifdef FEAT_PATH_EXTRA
-                       , stackp->ffs_wc_path
+                       , statep->ffs_wc_path
 #endif
                        ) == FAIL)
            {
@@ -4931,13 +4927,13 @@
                {
                    verbose_enter_scroll();
                    smsg((char_u *)"Already Searched: %s (%s)",
-                                  stackp->ffs_fix_path, stackp->ffs_wc_path);
+                                  statep->ffs_fix_path, statep->ffs_wc_path);
                    /* don't overwrite this either */
                    msg_puts((char_u *)"\n");
                    verbose_leave_scroll();
                }
 #endif
-               ff_free_stack_element(stackp);
+               ff_free_state_element(statep);
                continue;
            }
 #ifdef FF_VERBOSE
@@ -4945,7 +4941,7 @@
            {
                verbose_enter_scroll();
                smsg((char_u *)"Searching: %s (%s)",
-                                  stackp->ffs_fix_path, stackp->ffs_wc_path);
+                                  statep->ffs_fix_path, statep->ffs_wc_path);
                /* don't overwrite this either */
                msg_puts((char_u *)"\n");
                verbose_leave_scroll();
@@ -4953,9 +4949,9 @@
 #endif
 
            /* check depth */
-           if (stackp->ffs_level <= 0)
+           if (statep->ffs_level <= 0)
            {
-               ff_free_stack_element(stackp);
+               ff_free_state_element(statep);
                continue;
            }
 
@@ -4967,7 +4963,7 @@
             * and all possible expands are returned in one array. We use this
             * to handle the expansion of '**' into an empty string.
             */
-           if (stackp->ffs_filearray == NULL)
+           if (statep->ffs_filearray == NULL)
            {
                char_u *dirptrs[2];
 
@@ -4978,7 +4974,7 @@
                dirptrs[1] = NULL;
 
                /* if we have a start dir copy it in */
-               if (!vim_isAbsName(stackp->ffs_fix_path)
+               if (!vim_isAbsName(statep->ffs_fix_path)
                                                && search_ctx->ffsc_start_dir)
                {
                    STRCPY(file_path, search_ctx->ffsc_start_dir);
@@ -4986,11 +4982,11 @@
                }
 
                /* append the fix part of the search path */
-               STRCAT(file_path, stackp->ffs_fix_path);
+               STRCAT(file_path, statep->ffs_fix_path);
                add_pathsep(file_path);
 
 #ifdef FEAT_PATH_EXTRA
-               rest_of_wildcards = stackp->ffs_wc_path;
+               rest_of_wildcards = statep->ffs_wc_path;
                if (*rest_of_wildcards != NUL)
                {
                    len = (int)STRLEN(file_path);
@@ -5015,11 +5011,11 @@
                        else
                            rest_of_wildcards += 3;
 
-                       if (stackp->ffs_star_star_empty == 0)
+                       if (statep->ffs_star_star_empty == 0)
                        {
                            /* if not done before, expand '**' to empty */
-                           stackp->ffs_star_star_empty = 1;
-                           dirptrs[1] = stackp->ffs_fix_path;
+                           statep->ffs_star_star_empty = 1;
+                           dirptrs[1] = statep->ffs_fix_path;
                        }
                    }
 
@@ -5028,7 +5024,7 @@
                     * the path. If we stop at a path separator, there is
                     * still something else left. This is handled below by
                     * pushing every directory returned from expand_wildcards()
-                    * on the stack again for further search.
+                    * on the state again for further search.
                     */
                    while (*rest_of_wildcards
                            && !vim_ispathsep(*rest_of_wildcards))
@@ -5046,34 +5042,34 @@
                 */
                if (path_with_url(dirptrs[0]))
                {
-                   stackp->ffs_filearray = (char_u **)
+                   statep->ffs_filearray = (char_u **)
                                              alloc((unsigned)sizeof(char *));
-                   if (stackp->ffs_filearray != NULL
-                           && (stackp->ffs_filearray[0]
+                   if (statep->ffs_filearray != NULL
+                           && (statep->ffs_filearray[0]
                                = vim_strsave(dirptrs[0])) != NULL)
-                       stackp->ffs_filearray_size = 1;
+                       statep->ffs_filearray_size = 1;
                    else
-                       stackp->ffs_filearray_size = 0;
+                       statep->ffs_filearray_size = 0;
                }
                else
                    /* Add EW_NOTWILD because the expanded path may contain
                     * wildcard characters that are to be taken literally.
                     * This is a bit of a hack. */
                    expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs,
-                           &stackp->ffs_filearray_size,
-                           &stackp->ffs_filearray,
+                           &statep->ffs_filearray_size,
+                           &statep->ffs_filearray,
                            EW_DIR|EW_ADDSLASH|EW_SILENT|EW_NOTWILD);
 
-               stackp->ffs_filearray_cur = 0;
-               stackp->ffs_stage = 0;
+               statep->ffs_filearray_cur = 0;
+               statep->ffs_stage = 0;
            }
 #ifdef FEAT_PATH_EXTRA
            else
-               rest_of_wildcards = &stackp->ffs_wc_path[
-                                                STRLEN(stackp->ffs_wc_path)];
-#endif
-
-           if (stackp->ffs_stage == 0)
+               rest_of_wildcards = &statep->ffs_wc_path[
+                                                STRLEN(statep->ffs_wc_path)];
+#endif
+
+           if (statep->ffs_stage == 0)
            {
                /* this is the first time we work on this directory */
 #ifdef FEAT_PATH_EXTRA
@@ -5084,16 +5080,16 @@
                     * We don't have further wildcards to expand, so we have to
                     * check for the final file now.
                     */
-                   for (i = stackp->ffs_filearray_cur;
-                                         i < stackp->ffs_filearray_size; ++i)
+                   for (i = statep->ffs_filearray_cur;
+                                         i < statep->ffs_filearray_size; ++i)
                    {
-                       if (!path_with_url(stackp->ffs_filearray[i])
-                                     && !mch_isdir(stackp->ffs_filearray[i]))
+                       if (!path_with_url(statep->ffs_filearray[i])
+                                     && !mch_isdir(statep->ffs_filearray[i]))
                            continue;   /* not a directory */
 
                        /* prepare the filename to be checked for existence
                         * below */
-                       STRCPY(file_path, stackp->ffs_filearray[i]);
+                       STRCPY(file_path, statep->ffs_filearray[i]);
                        add_pathsep(file_path);
                        STRCAT(file_path, search_ctx->ffsc_file_to_search);
 
@@ -5152,8 +5148,8 @@
 #endif
 
                                /* push dir to examine rest of subdirs later */
-                               stackp->ffs_filearray_cur = i + 1;
-                               ff_push(search_ctx, stackp);
+                               statep->ffs_filearray_cur = i + 1;
+                               ff_push(search_ctx, statep);
 
                                if (!path_with_url(file_path))
                                    simplify_filename(file_path);
@@ -5195,22 +5191,22 @@
                     * still wildcards left, push the directories for further
                     * search
                     */
-                   for (i = stackp->ffs_filearray_cur;
-                                         i < stackp->ffs_filearray_size; ++i)
+                   for (i = statep->ffs_filearray_cur;
+                                         i < statep->ffs_filearray_size; ++i)
                    {
-                       if (!mch_isdir(stackp->ffs_filearray[i]))
+                       if (!mch_isdir(statep->ffs_filearray[i]))
                            continue;   /* not a directory */
 
                        ff_push(search_ctx,
-                               ff_create_stack_element(
-                                                    stackp->ffs_filearray[i],
+                               ff_create_state_element(
+                                                    statep->ffs_filearray[i],
                                                     rest_of_wildcards,
-                                                    stackp->ffs_level - 1, 0));
+                                                    statep->ffs_level - 1, 0));
                    }
                }
 #endif
-               stackp->ffs_filearray_cur = 0;
-               stackp->ffs_stage = 1;
+               statep->ffs_filearray_cur = 0;
+               statep->ffs_stage = 1;
            }
 
 #ifdef FEAT_PATH_EXTRA
@@ -5218,25 +5214,25 @@
             * if wildcards contains '**' we have to descent till we reach the
             * leaves of the directory tree.
             */
-           if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0)
+           if (STRNCMP(statep->ffs_wc_path, "**", 2) == 0)
            {
-               for (i = stackp->ffs_filearray_cur;
-                                         i < stackp->ffs_filearray_size; ++i)
+               for (i = statep->ffs_filearray_cur;
+                                         i < statep->ffs_filearray_size; ++i)
                {
-                   if (fnamecmp(stackp->ffs_filearray[i],
-                                                  stackp->ffs_fix_path) == 0)
+                   if (fnamecmp(statep->ffs_filearray[i],
+                                                  statep->ffs_fix_path) == 0)
                        continue; /* don't repush same directory */
-                   if (!mch_isdir(stackp->ffs_filearray[i]))
+                   if (!mch_isdir(statep->ffs_filearray[i]))
                        continue;   /* not a directory */
                    ff_push(search_ctx,
-                           ff_create_stack_element(stackp->ffs_filearray[i],
-                               stackp->ffs_wc_path, stackp->ffs_level - 1, 1));
+                           ff_create_state_element(statep->ffs_filearray[i],
+                               statep->ffs_wc_path, statep->ffs_level - 1, 1));
                }
            }
 #endif
 
            /* we are done with the current directory */
-           ff_free_stack_element(stackp);
+           ff_free_state_element(statep);
 
        }
 
@@ -5247,7 +5243,7 @@
        if (search_ctx->ffsc_start_dir
                && search_ctx->ffsc_stopdirs_v != NULL && !got_int)
        {
-           ff_stack_T  *sptr;
+           ff_state_T  *sptr;
 
            /* is the last starting directory in the stop list? */
            if (ff_path_in_stoplist(search_ctx->ffsc_start_dir,
@@ -5272,8 +5268,8 @@
            add_pathsep(file_path);
            STRCAT(file_path, search_ctx->ffsc_fix_path);
 
-           /* create a new stack entry */
-           sptr = ff_create_stack_element(file_path,
+           /* create a new entry */
+           sptr = ff_create_state_element(file_path,
                    search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
            if (sptr == NULL)
                break;
@@ -5559,10 +5555,10 @@
 }
 
 /*
- * create stack element from given path pieces
- */
-    static ff_stack_T *
-ff_create_stack_element(fix_part,
+ * create state element from given path pieces
+ */
+    static ff_state_T *
+ff_create_state_element(fix_part,
 #ifdef FEAT_PATH_EXTRA
        wc_part,
 #endif
@@ -5574,9 +5570,9 @@
     int                level;
     int                star_star_empty;
 {
-    ff_stack_T *new;
-
-    new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T));
+    ff_state_T *new;
+
+    new = (ff_state_T *)alloc((unsigned)sizeof(ff_state_T));
     if (new == NULL)
        return NULL;
 
@@ -5605,7 +5601,7 @@
 #endif
            )
     {
-       ff_free_stack_element(new);
+       ff_free_state_element(new);
        new = NULL;
     }
 
@@ -5618,14 +5614,14 @@
     static void
 ffs_push(search_ctx, stack_ptr)
     ff_search_ctx_T *search_ctx;
-    ff_stack_T     *stack_ptr;
+    ff_state_T     *stack_ptr;
 {
     /* check for NULL pointer, not to return an error to the user, but
      * to prevent a crash */
     if (stack_ptr != NULL)
     {
-       stack_ptr->ffs_child = search_ctx->ffsc_stack_ptr;
-       search_ctx->ffsc_stack_ptr = stack_ptr;
+       stack_ptr->ffs_child = search_ctx->ffsc_state_ptr;
+       search_ctx->ffsc_state_ptr = stack_ptr;
     }
 }
 
@@ -5635,20 +5631,20 @@
     static void
 ffq_push(search_ctx, queue_ptr)
     ff_search_ctx_T *search_ctx;
-    ff_stack_T     *queue_ptr;
+    ff_state_T     *queue_ptr;
 {
     /* check for NULL pointer, not to return an error to the user, but
      * to prevent a crash */
     if (queue_ptr != NULL)
     {
-       if (search_ctx->ffsc_stack_ptr && search_ctx->ffsc_stack_last)
-           search_ctx->ffsc_stack_last->ffs_child = queue_ptr;
-        else if (search_ctx->ffsc_stack_ptr)
-           search_ctx->ffsc_stack_ptr->ffs_child = queue_ptr;
+       if (search_ctx->ffsc_state_ptr && search_ctx->ffsc_state_last)
+           search_ctx->ffsc_state_last->ffs_child = queue_ptr;
+        else if (search_ctx->ffsc_state_ptr)
+           search_ctx->ffsc_state_ptr->ffs_child = queue_ptr;
         else
-           search_ctx->ffsc_stack_ptr = queue_ptr;
-
-       search_ctx->ffsc_stack_last = queue_ptr;
+           search_ctx->ffsc_state_ptr = queue_ptr;
+
+       search_ctx->ffsc_state_last = queue_ptr;
     }
 }
 
@@ -5656,15 +5652,15 @@
  * Pop a dir from the directory stack.
  * Returns NULL if stack is empty.
  */
-    static ff_stack_T *
+    static ff_state_T *
 ffs_pop(search_ctx)
     ff_search_ctx_T *search_ctx;
 {
-    ff_stack_T  *sptr;
-
-    sptr = search_ctx->ffsc_stack_ptr;
-    if (search_ctx->ffsc_stack_ptr != NULL)
-       search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_child;
+    ff_state_T  *sptr;
+
+    sptr = search_ctx->ffsc_state_ptr;
+    if (search_ctx->ffsc_state_ptr != NULL)
+       search_ctx->ffsc_state_ptr = search_ctx->ffsc_state_ptr->ffs_child;
 
     return sptr;
 }
@@ -5673,15 +5669,15 @@
  * Pop a dir from the directory queue.
  * Returns NULL if queue is empty.
  */
-    static ff_stack_T *
+    static ff_state_T *
 ffq_pop(search_ctx)
     ff_search_ctx_T *search_ctx;
 {
-    ff_stack_T  *sptr;
-
-    sptr = search_ctx->ffsc_stack_ptr;
-    if (search_ctx->ffsc_stack_ptr != NULL) {
-       search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_child;
+    ff_state_T  *sptr;
+
+    sptr = search_ctx->ffsc_state_ptr;
+    if (search_ctx->ffsc_state_ptr != NULL) {
+       search_ctx->ffsc_state_ptr = search_ctx->ffsc_state_ptr->ffs_child;
        sptr->ffs_child = NULL;
     }
 
@@ -5689,22 +5685,22 @@
 }
 
 /*
- * free the given stack element
+ * free the given element
  */
     static void
-ff_free_stack_element(stack_ptr)
-    ff_stack_T  *stack_ptr;
+ff_free_state_element(state_ptr)
+    ff_state_T  *state_ptr;
 {
     /* vim_free handles possible NULL pointers */
-    vim_free(stack_ptr->ffs_fix_path);
+    vim_free(state_ptr->ffs_fix_path);
 #ifdef FEAT_PATH_EXTRA
-    vim_free(stack_ptr->ffs_wc_path);
-#endif
-
-    if (stack_ptr->ffs_filearray != NULL)
-       FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray);
-
-    vim_free(stack_ptr);
+    vim_free(state_ptr->ffs_wc_path);
+#endif
+
+    if (state_ptr->ffs_filearray != NULL)
+       FreeWild(state_ptr->ffs_filearray_size, state_ptr->ffs_filearray);
+
+    vim_free(state_ptr);
 }
 
 /*
@@ -5714,11 +5710,11 @@
 ff_clear(search_ctx)
     ff_search_ctx_T *search_ctx;
 {
-    ff_stack_T   *sptr;
-
-    /* clear up stack */
+    ff_state_T   *sptr;
+
+    /* clear up state */
     while ((sptr = ff_pop(search_ctx)) != NULL)
-       ff_free_stack_element(sptr);
+       ff_free_state_element(sptr);
 
     vim_free(search_ctx->ffsc_file_to_search);
     vim_free(search_ctx->ffsc_start_dir);
@@ -5750,7 +5746,7 @@
     search_ctx->ffsc_wc_path = NULL;
     search_ctx->ffsc_level = 0;
 #endif
-    search_ctx->ffsc_stack_last = NULL;
+    search_ctx->ffsc_state_last = NULL;
 }
 
 #ifdef FEAT_PATH_EXTRA

Raspunde prin e-mail lui