mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
vim-patch:partial:8.1.0914: code related to findfile() is spread out (#30000)
Problem: Code related to findfile() is spread out.
Solution: Put findfile() related code into a new source file. (Yegappan
Lakshmanan, closes vim/vim#3934)
5fd0f5052f
Keep functions related to wildcard expansion in path.c, as in Vim they
are now spread out among multiple files, which isn't really ideal.
This commit is contained in:
@@ -8,23 +8,17 @@
|
||||
|
||||
#include "auto/config.h"
|
||||
#include "nvim/ascii_defs.h"
|
||||
#include "nvim/buffer_defs.h"
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/cmdexpand.h"
|
||||
#include "nvim/eval.h"
|
||||
#include "nvim/eval/typval_defs.h"
|
||||
#include "nvim/ex_docmd.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/gettext_defs.h"
|
||||
#include "nvim/globals.h"
|
||||
#include "nvim/macros_defs.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/option_defs.h"
|
||||
#include "nvim/option_vars.h"
|
||||
#include "nvim/os/fs.h"
|
||||
#include "nvim/os/fs_defs.h"
|
||||
@@ -37,7 +31,6 @@
|
||||
#include "nvim/regexp_defs.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/vim_defs.h"
|
||||
#include "nvim/window.h"
|
||||
|
||||
enum {
|
||||
URL_SLASH = 1, // path_is_url() has found ":/"
|
||||
@@ -1687,87 +1680,6 @@ void simplify_filename(char *filename)
|
||||
} while (*p != NUL);
|
||||
}
|
||||
|
||||
static char *eval_includeexpr(const char *const ptr, const size_t len)
|
||||
{
|
||||
const sctx_T save_sctx = current_sctx;
|
||||
set_vim_var_string(VV_FNAME, ptr, (ptrdiff_t)len);
|
||||
current_sctx = curbuf->b_p_script_ctx[BV_INEX].script_ctx;
|
||||
|
||||
char *res = eval_to_string_safe(curbuf->b_p_inex,
|
||||
was_set_insecurely(curwin, kOptIncludeexpr, OPT_LOCAL),
|
||||
true);
|
||||
|
||||
set_vim_var_string(VV_FNAME, NULL, 0);
|
||||
current_sctx = save_sctx;
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Return the name of the file ptr[len] in 'path'.
|
||||
/// Otherwise like file_name_at_cursor().
|
||||
///
|
||||
/// @param rel_fname file we are searching relative to
|
||||
char *find_file_name_in_path(char *ptr, size_t len, int options, long count, char *rel_fname)
|
||||
{
|
||||
char *file_name;
|
||||
char *tofree = NULL;
|
||||
|
||||
if (len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) {
|
||||
tofree = eval_includeexpr(ptr, len);
|
||||
if (tofree != NULL) {
|
||||
ptr = tofree;
|
||||
len = strlen(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (options & FNAME_EXP) {
|
||||
char *file_to_find = NULL;
|
||||
char *search_ctx = NULL;
|
||||
|
||||
file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS,
|
||||
true, rel_fname, &file_to_find, &search_ctx);
|
||||
|
||||
// If the file could not be found in a normal way, try applying
|
||||
// 'includeexpr' (unless done already).
|
||||
if (file_name == NULL
|
||||
&& !(options & FNAME_INCL) && *curbuf->b_p_inex != NUL) {
|
||||
tofree = eval_includeexpr(ptr, len);
|
||||
if (tofree != NULL) {
|
||||
ptr = tofree;
|
||||
len = strlen(ptr);
|
||||
file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS,
|
||||
true, rel_fname, &file_to_find, &search_ctx);
|
||||
}
|
||||
}
|
||||
if (file_name == NULL && (options & FNAME_MESS)) {
|
||||
char c = ptr[len];
|
||||
ptr[len] = NUL;
|
||||
semsg(_("E447: Can't find file \"%s\" in path"), ptr);
|
||||
ptr[len] = c;
|
||||
}
|
||||
|
||||
// Repeat finding the file "count" times. This matters when it
|
||||
// appears several times in the path.
|
||||
while (file_name != NULL && --count > 0) {
|
||||
xfree(file_name);
|
||||
file_name = find_file_in_path(ptr, len, options, false, rel_fname,
|
||||
&file_to_find, &search_ctx);
|
||||
}
|
||||
|
||||
xfree(file_to_find);
|
||||
vim_findfile_cleanup(search_ctx);
|
||||
} else {
|
||||
file_name = xstrnsave(ptr, len);
|
||||
}
|
||||
|
||||
xfree(tofree);
|
||||
|
||||
return file_name;
|
||||
}
|
||||
|
||||
/// Checks for a Windows drive letter ("C:/") at the start of the path.
|
||||
///
|
||||
/// @see https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
|
||||
|
Reference in New Issue
Block a user