0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

updated for version 7.4.235

Problem:    It is not easy to get the full path of a command.
Solution:   Add the exepath() function.
This commit is contained in:
Bram Moolenaar 2014-04-01 21:00:59 +02:00
parent a1706c958e
commit c7f025536e
13 changed files with 82 additions and 20 deletions

View File

@ -1562,6 +1562,10 @@ v:progname Contains the name (with path removed) with which Vim was
v:progpath Contains the command with which Vim was invoked, including the v:progpath Contains the command with which Vim was invoked, including the
path. Useful if you want to message a Vim server using a path. Useful if you want to message a Vim server using a
|--remote-expr|. |--remote-expr|.
To get the full path use: >
echo exepath(v:progpath)
< NOTE: This does not work when the command is a relative path
and the current directory has changed.
Read-only. Read-only.
*v:register* *register-variable* *v:register* *register-variable*
@ -1762,6 +1766,7 @@ escape( {string}, {chars}) String escape {chars} in {string} with '\'
eval( {string}) any evaluate {string} into its value eval( {string}) any evaluate {string} into its value
eventhandler( ) Number TRUE if inside an event handler eventhandler( ) Number TRUE if inside an event handler
executable( {expr}) Number 1 if executable {expr} exists executable( {expr}) Number 1 if executable {expr} exists
exepath( {expr}) String full path of the command {expr}
exists( {expr}) Number TRUE if {expr} exists exists( {expr}) Number TRUE if {expr} exists
extend( {expr1}, {expr2} [, {expr3}]) extend( {expr1}, {expr2} [, {expr3}])
List/Dict insert items of {expr2} into {expr1} List/Dict insert items of {expr2} into {expr1}
@ -2706,6 +2711,15 @@ executable({expr}) *executable()*
0 does not exist 0 does not exist
-1 not implemented on this system -1 not implemented on this system
exepath({expr}) *exepath()*
If {expr} is an executable and is either an absolute path, a
relative path or found in $PATH, return the full path.
Note that the current directory is used when {expr} starts
with "./", which may be a problem for Vim: >
echo exepath(v:progpath)
< If {expr} cannot be found in $PATH or is not executable then
an empty string is returned.
*exists()* *exists()*
exists({expr}) The result is a Number, which is non-zero if {expr} is exists({expr}) The result is a Number, which is non-zero if {expr} is
defined, zero otherwise. The {expr} argument is a string, defined, zero otherwise. The {expr} argument is a string,

View File

@ -514,6 +514,7 @@ static void f_escape __ARGS((typval_T *argvars, typval_T *rettv));
static void f_eval __ARGS((typval_T *argvars, typval_T *rettv)); static void f_eval __ARGS((typval_T *argvars, typval_T *rettv));
static void f_eventhandler __ARGS((typval_T *argvars, typval_T *rettv)); static void f_eventhandler __ARGS((typval_T *argvars, typval_T *rettv));
static void f_executable __ARGS((typval_T *argvars, typval_T *rettv)); static void f_executable __ARGS((typval_T *argvars, typval_T *rettv));
static void f_exepath __ARGS((typval_T *argvars, typval_T *rettv));
static void f_exists __ARGS((typval_T *argvars, typval_T *rettv)); static void f_exists __ARGS((typval_T *argvars, typval_T *rettv));
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
static void f_exp __ARGS((typval_T *argvars, typval_T *rettv)); static void f_exp __ARGS((typval_T *argvars, typval_T *rettv));
@ -7920,6 +7921,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},
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
{"exp", 1, 1, f_exp}, {"exp", 1, 1, f_exp},
@ -10046,7 +10048,22 @@ f_executable(argvars, rettv)
typval_T *argvars; typval_T *argvars;
typval_T *rettv; typval_T *rettv;
{ {
rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0])); rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0]), NULL);
}
/*
* "exepath()" function
*/
static void
f_exepath(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *p = NULL;
(void)mch_can_exe(get_tv_string(&argvars[0]), &p);
rettv->v_type = VAR_STRING;
rettv->vval.v_string = p;
} }
/* /*

View File

@ -10728,7 +10728,7 @@ addfile(gap, f, flags)
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) && !mch_can_exe(f)) if (!isdir && (flags & EW_EXEC) && !mch_can_exe(f, NULL))
return; return;
/* Make room for another item in the file list. */ /* Make room for another item in the file list. */

View File

@ -884,8 +884,9 @@ mch_mkdir(name)
* Return -1 if unknown. * Return -1 if unknown.
*/ */
int int
mch_can_exe(name) mch_can_exe(name, path)
char_u *name; char_u *name;
char_u **path;
{ {
/* TODO */ /* TODO */
return -1; return -1;

View File

@ -2945,14 +2945,17 @@ mch_isdir(char_u *name)
* Return -1 if unknown. * Return -1 if unknown.
*/ */
int int
mch_can_exe(name) mch_can_exe(name, path)
char_u *name; char_u *name;
char_u **path;
{ {
char *p; char *p;
p = searchpath(name); p = searchpath(name);
if (p == NULL || mch_isdir(p)) if (p == NULL || mch_isdir(p))
return FALSE; return FALSE;
if (path != NULL)
*path = vim_strsave(p);
return TRUE; return TRUE;
} }

View File

@ -2992,8 +2992,9 @@ executable_file(name)
* Return -1 if unknown. * Return -1 if unknown.
*/ */
int int
mch_can_exe(name) mch_can_exe(name, path)
char_u *name; char_u *name;
char_u **path;
{ {
char_u *buf; char_u *buf;
char_u *p, *e; char_u *p, *e;
@ -3003,7 +3004,18 @@ mch_can_exe(name)
if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/' if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/'
|| (name[1] == '.' && name[2] == '/')))) || (name[1] == '.' && name[2] == '/'))))
{ {
return executable_file(name); if (executable_file(name))
{
if (path != NULL)
{
if (name[0] == '.')
*path = FullName_save(name, TRUE);
else
*path = vim_strsave(name);
}
return TRUE;
}
return FALSE;
} }
p = (char_u *)getenv("PATH"); p = (char_u *)getenv("PATH");
@ -3032,7 +3044,16 @@ mch_can_exe(name)
STRCAT(buf, name); STRCAT(buf, name);
retval = executable_file(buf); retval = executable_file(buf);
if (retval == 1) if (retval == 1)
{
if (path != NULL)
{
if (buf[0] == '.')
*path = FullName_save(buf, TRUE);
else
*path = vim_strsave(buf);
}
break; break;
}
if (*e != ':') if (*e != ':')
break; break;
@ -5592,7 +5613,7 @@ mch_expand_wildcards(num_pat, pat, num_file, file, flags)
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) && !mch_can_exe(p)) if (!dir && (flags & EW_EXEC) && !mch_can_exe(p, NULL))
continue; continue;
if (--files_free == 0) if (--files_free == 0)
@ -6090,7 +6111,7 @@ mch_expand_wildcards(num_pat, pat, num_file, file, flags)
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) && !mch_can_exe((*file)[i])) if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i], NULL))
continue; continue;
p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir));
@ -6317,7 +6338,7 @@ gpm_close()
/* Reads gpm event and adds special keys to input buf. Returns length of /* Reads gpm event and adds special keys to input buf. Returns length of
* generated key sequence. * generated key sequence.
* This function is made after gui_send_mouse_event * This function is styled after gui_send_mouse_event().
*/ */
static int static int
mch_gpm_process() mch_gpm_process()

View File

@ -483,7 +483,7 @@ mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, i
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) && !mch_can_exe(vms_fmatch[i])) if (!dir && (flags & EW_EXEC) && !mch_can_exe(vms_fmatch[i], NULL))
continue; continue;
/* allocate memory for pointers */ /* allocate memory for pointers */

View File

@ -1882,7 +1882,7 @@ theend:
* TODO: Should somehow check if it's really executable. * TODO: Should somehow check if it's really executable.
*/ */
static int static int
executable_exists(char *name) executable_exists(char *name, char_u **path)
{ {
char *dum; char *dum;
char fname[_MAX_PATH]; char fname[_MAX_PATH];
@ -1905,6 +1905,8 @@ executable_exists(char *name)
return FALSE; return FALSE;
if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY)
return FALSE; return FALSE;
if (path != NULL)
*path = utf16_to_enc(fnamew, NULL);
return TRUE; return TRUE;
} }
/* Retry with non-wide function (for Windows 98). */ /* Retry with non-wide function (for Windows 98). */
@ -1915,6 +1917,8 @@ executable_exists(char *name)
return FALSE; return FALSE;
if (mch_isdir(fname)) if (mch_isdir(fname))
return FALSE; return FALSE;
if (path != NULL)
*path = vim_strsave(fname);
return TRUE; return TRUE;
} }
@ -1996,7 +2000,7 @@ mch_init(void)
vimrun_path = (char *)vim_strsave(vimrun_location); vimrun_path = (char *)vim_strsave(vimrun_location);
s_dont_use_vimrun = FALSE; s_dont_use_vimrun = FALSE;
} }
else if (executable_exists("vimrun.exe")) else if (executable_exists("vimrun.exe", NULL))
s_dont_use_vimrun = FALSE; s_dont_use_vimrun = FALSE;
/* Don't give the warning for a missing vimrun.exe right now, but only /* Don't give the warning for a missing vimrun.exe right now, but only
@ -2010,7 +2014,7 @@ mch_init(void)
* If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
* Otherwise the default "findstr /n" is used. * Otherwise the default "findstr /n" is used.
*/ */
if (!executable_exists("findstr.exe")) if (!executable_exists("findstr.exe", NULL))
set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);
#ifdef FEAT_CLIPBOARD #ifdef FEAT_CLIPBOARD
@ -3330,7 +3334,7 @@ mch_writable(char_u *name)
* Return -1 if unknown. * Return -1 if unknown.
*/ */
int int
mch_can_exe(char_u *name) mch_can_exe(char_u *name, char_u **path)
{ {
char_u buf[_MAX_PATH]; char_u buf[_MAX_PATH];
int len = (int)STRLEN(name); int len = (int)STRLEN(name);
@ -3343,7 +3347,7 @@ mch_can_exe(char_u *name)
* this with a Unix-shell like 'shell'. */ * this with a Unix-shell like 'shell'. */
if (vim_strchr(gettail(name), '.') != NULL if (vim_strchr(gettail(name), '.') != NULL
|| strstr((char *)gettail(p_sh), "sh") != NULL) || strstr((char *)gettail(p_sh), "sh") != NULL)
if (executable_exists((char *)name)) if (executable_exists((char *)name, path))
return TRUE; return TRUE;
/* /*
@ -3365,7 +3369,7 @@ mch_can_exe(char_u *name)
} }
else else
copy_option_part(&p, buf + len, _MAX_PATH - len, ";"); copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
if (executable_exists((char *)buf)) if (executable_exists((char *)buf, path))
return TRUE; return TRUE;
} }
return FALSE; return FALSE;

View File

@ -26,7 +26,7 @@ int mch_setperm __ARGS((char_u *name, long perm));
void mch_hide __ARGS((char_u *name)); void mch_hide __ARGS((char_u *name));
int mch_isdir __ARGS((char_u *name)); int mch_isdir __ARGS((char_u *name));
int mch_mkdir __ARGS((char_u *name)); int mch_mkdir __ARGS((char_u *name));
int mch_can_exe __ARGS((char_u *name)); int mch_can_exe __ARGS((char_u *name, char_u **path));
int mch_nodetype __ARGS((char_u *name)); int mch_nodetype __ARGS((char_u *name));
void mch_early_init __ARGS((void)); void mch_early_init __ARGS((void));
void mch_exit __ARGS((int r)); void mch_exit __ARGS((int r));

View File

@ -38,7 +38,7 @@ long mch_getperm __ARGS((char_u *name));
int mch_setperm __ARGS((char_u *name, long perm)); int mch_setperm __ARGS((char_u *name, long perm));
void mch_hide __ARGS((char_u *name)); void mch_hide __ARGS((char_u *name));
int mch_isdir __ARGS((char_u *name)); int mch_isdir __ARGS((char_u *name));
int mch_can_exe __ARGS((char_u *name)); int mch_can_exe __ARGS((char_u *name, char_u **path));
int mch_nodetype __ARGS((char_u *name)); int mch_nodetype __ARGS((char_u *name));
int mch_dirname __ARGS((char_u *buf, int len)); int mch_dirname __ARGS((char_u *buf, int len));
int mch_remove __ARGS((char_u *name)); int mch_remove __ARGS((char_u *name));

View File

@ -42,7 +42,7 @@ void mch_set_acl __ARGS((char_u *fname, vim_acl_T aclent));
void mch_free_acl __ARGS((vim_acl_T aclent)); void mch_free_acl __ARGS((vim_acl_T aclent));
void mch_hide __ARGS((char_u *name)); void mch_hide __ARGS((char_u *name));
int mch_isdir __ARGS((char_u *name)); int mch_isdir __ARGS((char_u *name));
int mch_can_exe __ARGS((char_u *name)); int mch_can_exe __ARGS((char_u *name, char_u **path));
int mch_nodetype __ARGS((char_u *name)); int mch_nodetype __ARGS((char_u *name));
void mch_early_init __ARGS((void)); void mch_early_init __ARGS((void));
void mch_free_mem __ARGS((void)); void mch_free_mem __ARGS((void));

View File

@ -26,7 +26,7 @@ int mch_is_symbolic_link __ARGS((char_u *fname));
int mch_is_linked __ARGS((char_u *fname)); int mch_is_linked __ARGS((char_u *fname));
int win32_fileinfo __ARGS((char_u *fname, BY_HANDLE_FILE_INFORMATION *info)); int win32_fileinfo __ARGS((char_u *fname, BY_HANDLE_FILE_INFORMATION *info));
int mch_writable __ARGS((char_u *name)); int mch_writable __ARGS((char_u *name));
int mch_can_exe __ARGS((char_u *name)); int mch_can_exe __ARGS((char_u *name, char_u **path));
int mch_nodetype __ARGS((char_u *name)); int mch_nodetype __ARGS((char_u *name));
vim_acl_T mch_get_acl __ARGS((char_u *fname)); vim_acl_T mch_get_acl __ARGS((char_u *fname));
void mch_set_acl __ARGS((char_u *fname, vim_acl_T acl)); void mch_set_acl __ARGS((char_u *fname, vim_acl_T acl));

View File

@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
235,
/**/ /**/
234, 234,
/**/ /**/