mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
vim-patch:7.4.235
Problem: It is not easy to get the full path of a command. Solution: Add the exepath() function. https://code.google.com/p/vim/source/detail?r=5ab2946f7ce560985830fbc3c453bb0f7a01f385
This commit is contained in:
@@ -6355,6 +6355,7 @@ static struct fst {
|
|||||||
{"eval", 1, 1, f_eval},
|
{"eval", 1, 1, f_eval},
|
||||||
{"eventhandler", 0, 0, f_eventhandler},
|
{"eventhandler", 0, 0, f_eventhandler},
|
||||||
{"executable", 1, 1, f_executable},
|
{"executable", 1, 1, f_executable},
|
||||||
|
{"exepath", 1, 1, f_exepath},
|
||||||
{"exists", 1, 1, f_exists},
|
{"exists", 1, 1, f_exists},
|
||||||
{"exp", 1, 1, f_exp},
|
{"exp", 1, 1, f_exp},
|
||||||
{"expand", 1, 3, f_expand},
|
{"expand", 1, 3, f_expand},
|
||||||
@@ -8066,7 +8067,19 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv)
|
|||||||
*/
|
*/
|
||||||
static void f_executable(typval_T *argvars, typval_T *rettv)
|
static void f_executable(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
rettv->vval.v_number = os_can_exe(get_tv_string(&argvars[0]));
|
rettv->vval.v_number = os_can_exe(get_tv_string(&argvars[0]), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "exepath()" function
|
||||||
|
static void f_exepath(typval_T *argvars, typval_T *rettv)
|
||||||
|
{
|
||||||
|
char_u *arg = get_tv_string(&argvars[0]);
|
||||||
|
char_u *path = NULL;
|
||||||
|
|
||||||
|
(void)os_can_exe(arg, &path);
|
||||||
|
|
||||||
|
rettv->v_type = VAR_STRING;
|
||||||
|
rettv->vval.v_string = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -10577,7 +10590,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!os_can_exe(get_tv_string(&argvars[1]))) {
|
if (!os_can_exe(get_tv_string(&argvars[1]), NULL)) {
|
||||||
// String is not executable
|
// String is not executable
|
||||||
EMSG2(e_jobexe, get_tv_string(&argvars[1]));
|
EMSG2(e_jobexe, get_tv_string(&argvars[1]));
|
||||||
return;
|
return;
|
||||||
|
@@ -66,7 +66,10 @@ bool os_isdir(const char_u *name)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the given path represents an executable file.
|
/// Checks if the given path represents an executable file.
|
||||||
|
///
|
||||||
|
/// @param[in] name The name of the executable.
|
||||||
|
/// @param[out] abspath Path of the executable, if found and not `NULL`.
|
||||||
///
|
///
|
||||||
/// @return `true` if `name` is executable and
|
/// @return `true` if `name` is executable and
|
||||||
/// - can be found in $PATH,
|
/// - can be found in $PATH,
|
||||||
@@ -74,16 +77,24 @@ bool os_isdir(const char_u *name)
|
|||||||
/// - is absolute.
|
/// - is absolute.
|
||||||
///
|
///
|
||||||
/// @return `false` otherwise.
|
/// @return `false` otherwise.
|
||||||
bool os_can_exe(const char_u *name)
|
bool os_can_exe(const char_u *name, char_u **abspath)
|
||||||
{
|
{
|
||||||
// If it's an absolute or relative path don't need to use $PATH.
|
// If it's an absolute or relative path don't need to use $PATH.
|
||||||
if (path_is_absolute_path(name) ||
|
if (path_is_absolute_path(name) ||
|
||||||
(name[0] == '.' && (name[1] == '/' ||
|
(name[0] == '.' && (name[1] == '/' ||
|
||||||
(name[1] == '.' && name[2] == '/')))) {
|
(name[1] == '.' && name[2] == '/')))) {
|
||||||
return is_executable(name);
|
if (is_executable(name)) {
|
||||||
|
if (abspath != NULL) {
|
||||||
|
*abspath = save_absolute_path(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_executable_in_path(name);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_executable_in_path(name, abspath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if "name" is an executable file, false if not or it doesn't
|
// Return true if "name" is an executable file, false if not or it doesn't
|
||||||
@@ -103,10 +114,13 @@ static bool is_executable(const char_u *name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a file is inside the $PATH and is executable.
|
/// Checks if a file is inside the `$PATH` and is executable.
|
||||||
///
|
///
|
||||||
/// @return `true` if `name` is an executable inside $PATH.
|
/// @param[in] name The name of the executable.
|
||||||
static bool is_executable_in_path(const char_u *name)
|
/// @param[out] abspath Path of the executable, if found and not `NULL`.
|
||||||
|
///
|
||||||
|
/// @return `true` if `name` is an executable inside `$PATH`.
|
||||||
|
static bool is_executable_in_path(const char_u *name, char_u **abspath)
|
||||||
{
|
{
|
||||||
const char *path = getenv("PATH");
|
const char *path = getenv("PATH");
|
||||||
// PATH environment variable does not exist or is empty.
|
// PATH environment variable does not exist or is empty.
|
||||||
@@ -131,8 +145,13 @@ static bool is_executable_in_path(const char_u *name)
|
|||||||
append_path((char *) buf, (const char *) name, (int)buf_len);
|
append_path((char *) buf, (const char *) name, (int)buf_len);
|
||||||
|
|
||||||
if (is_executable(buf)) {
|
if (is_executable(buf)) {
|
||||||
// Found our executable. Free buf and return.
|
// Check if the caller asked for a copy of the path.
|
||||||
|
if (abspath != NULL) {
|
||||||
|
*abspath = save_absolute_path(buf);
|
||||||
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1331,7 +1331,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Skip files that are not executable if we check for that. */
|
/* Skip files that are not executable if we check for that. */
|
||||||
if (!dir && (flags & EW_EXEC) && !os_can_exe((*file)[i]))
|
if (!dir && (flags & EW_EXEC) && !os_can_exe((*file)[i], NULL))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
p = xmalloc(STRLEN((*file)[i]) + 1 + dir);
|
p = xmalloc(STRLEN((*file)[i]) + 1 + dir);
|
||||||
|
@@ -1232,7 +1232,7 @@ addfile (
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* If the file isn't executable, may not add it. Do accept directories. */
|
/* If the file isn't executable, may not add it. Do accept directories. */
|
||||||
if (!isdir && (flags & EW_EXEC) && !os_can_exe(f))
|
if (!isdir && (flags & EW_EXEC) && !os_can_exe(f, NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char_u *p = xmalloc(STRLEN(f) + 1 + isdir);
|
char_u *p = xmalloc(STRLEN(f) + 1 + isdir);
|
||||||
|
@@ -360,7 +360,7 @@ static int included_patches[] = {
|
|||||||
//238,
|
//238,
|
||||||
237,
|
237,
|
||||||
236,
|
236,
|
||||||
//235,
|
235,
|
||||||
234,
|
234,
|
||||||
233,
|
233,
|
||||||
232,
|
232,
|
||||||
|
@@ -11,6 +11,7 @@ local cstr = helpers.cstr
|
|||||||
local to_cstr = helpers.to_cstr
|
local to_cstr = helpers.to_cstr
|
||||||
local OK = helpers.OK
|
local OK = helpers.OK
|
||||||
local FAIL = helpers.FAIL
|
local FAIL = helpers.FAIL
|
||||||
|
local NULL = helpers.NULL
|
||||||
|
|
||||||
require('lfs')
|
require('lfs')
|
||||||
require('bit')
|
require('bit')
|
||||||
@@ -118,7 +119,7 @@ describe('fs function', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_can_exe', function()
|
describe('os_can_exe', function()
|
||||||
local function os_can_exe(name)
|
local function os_can_exe(name, NULL)
|
||||||
return fs.os_can_exe((to_cstr(name)))
|
return fs.os_can_exe((to_cstr(name)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user