summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <bram@vim.org>2014-04-01 21:00:59 +0200
committerBram Moolenaar <bram@vim.org>2014-04-01 21:00:59 +0200
commit7c27bcd22be22fd29d36f533ad3d9ff004adfbe0 (patch)
treed0b2b65d4ef05f7983d59b5966c18d055f0abd40
parentacc1bd735a52e540ab77fe9cbfd6909fd4ba48f6 (diff)
downloadvim-7c27bcd22be22fd29d36f533ad3d9ff004adfbe0.tar.gz
updated for version 7.4.235v7.4.235v7-4-235
Problem: It is not easy to get the full path of a command. Solution: Add the exepath() function.
-rw-r--r--runtime/doc/eval.txt14
-rw-r--r--src/eval.c19
-rw-r--r--src/misc1.c2
-rw-r--r--src/os_amiga.c3
-rw-r--r--src/os_msdos.c5
-rw-r--r--src/os_unix.c31
-rw-r--r--src/os_vms.c2
-rw-r--r--src/os_win32.c16
-rw-r--r--src/proto/os_amiga.pro2
-rw-r--r--src/proto/os_msdos.pro2
-rw-r--r--src/proto/os_unix.pro2
-rw-r--r--src/proto/os_win32.pro2
-rw-r--r--src/version.c2
13 files changed, 82 insertions, 20 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 66ee3aa2..66b3038e 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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
path. Useful if you want to message a Vim server using a
|--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.
*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
eventhandler( ) Number TRUE if inside an event handler
executable( {expr}) Number 1 if executable {expr} exists
+exepath( {expr}) String full path of the command {expr}
exists( {expr}) Number TRUE if {expr} exists
extend( {expr1}, {expr2} [, {expr3}])
List/Dict insert items of {expr2} into {expr1}
@@ -2706,6 +2711,15 @@ executable({expr}) *executable()*
0 does not exist
-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({expr}) The result is a Number, which is non-zero if {expr} is
defined, zero otherwise. The {expr} argument is a string,
diff --git a/src/eval.c b/src/eval.c
index 246e404b..65419cb3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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_eventhandler __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));
#ifdef FEAT_FLOAT
static void f_exp __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7920,6 +7921,7 @@ static struct fst
{"eval", 1, 1, f_eval},
{"eventhandler", 0, 0, f_eventhandler},
{"executable", 1, 1, f_executable},
+ {"exepath", 1, 1, f_exepath},
{"exists", 1, 1, f_exists},
#ifdef FEAT_FLOAT
{"exp", 1, 1, f_exp},
@@ -10046,7 +10048,22 @@ f_executable(argvars, rettv)
typval_T *argvars;
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;
}
/*
diff --git a/src/misc1.c b/src/misc1.c
index 94349618..c52945f5 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -10728,7 +10728,7 @@ addfile(gap, f, flags)
return;
/* 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;
/* Make room for another item in the file list. */
diff --git a/src/os_amiga.c b/src/os_amiga.c
index e5c7661e..324fc367 100644
--- a/src/os_amiga.c
+++ b/src/os_amiga.c
@@ -884,8 +884,9 @@ mch_mkdir(name)
* Return -1 if unknown.
*/
int
-mch_can_exe(name)
+mch_can_exe(name, path)
char_u *name;
+ char_u **path;
{
/* TODO */
return -1;
diff --git a/src/os_msdos.c b/src/os_msdos.c
index 10c70b2e..f24a6f8e 100644
--- a/src/os_msdos.c
+++ b/src/os_msdos.c
@@ -2945,14 +2945,17 @@ mch_isdir(char_u *name)
* Return -1 if unknown.
*/
int
-mch_can_exe(name)
+mch_can_exe(name, path)
char_u *name;
+ char_u **path;
{
char *p;
p = searchpath(name);
if (p == NULL || mch_isdir(p))
return FALSE;
+ if (path != NULL)
+ *path = vim_strsave(p);
return TRUE;
}
diff --git a/src/os_unix.c b/src/os_unix.c
index 48f45b0e..63d39493 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -2992,8 +2992,9 @@ executable_file(name)
* Return -1 if unknown.
*/
int
-mch_can_exe(name)
+mch_can_exe(name, path)
char_u *name;
+ char_u **path;
{
char_u *buf;
char_u *p, *e;
@@ -3003,7 +3004,18 @@ mch_can_exe(name)
if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/'
|| (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");
@@ -3032,7 +3044,16 @@ mch_can_exe(name)
STRCAT(buf, name);
retval = executable_file(buf);
if (retval == 1)
+ {
+ if (path != NULL)
+ {
+ if (buf[0] == '.')
+ *path = FullName_save(buf, TRUE);
+ else
+ *path = vim_strsave(buf);
+ }
break;
+ }
if (*e != ':')
break;
@@ -5592,7 +5613,7 @@ mch_expand_wildcards(num_pat, pat, num_file, file, flags)
continue;
/* 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;
if (--files_free == 0)
@@ -6090,7 +6111,7 @@ mch_expand_wildcards(num_pat, pat, num_file, file, flags)
continue;
/* 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;
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
* generated key sequence.
- * This function is made after gui_send_mouse_event
+ * This function is styled after gui_send_mouse_event().
*/
static int
mch_gpm_process()
diff --git a/src/os_vms.c b/src/os_vms.c
index 814b64a3..55876b27 100644
--- a/src/os_vms.c
+++ b/src/os_vms.c
@@ -483,7 +483,7 @@ mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, i
continue;
/* 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;
/* allocate memory for pointers */
diff --git a/src/os_win32.c b/src/os_win32.c
index c23b791a..09e5c610 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -1882,7 +1882,7 @@ theend:
* TODO: Should somehow check if it's really executable.
*/
static int
-executable_exists(char *name)
+executable_exists(char *name, char_u **path)
{
char *dum;
char fname[_MAX_PATH];
@@ -1905,6 +1905,8 @@ executable_exists(char *name)
return FALSE;
if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY)
return FALSE;
+ if (path != NULL)
+ *path = utf16_to_enc(fnamew, NULL);
return TRUE;
}
/* Retry with non-wide function (for Windows 98). */
@@ -1915,6 +1917,8 @@ executable_exists(char *name)
return FALSE;
if (mch_isdir(fname))
return FALSE;
+ if (path != NULL)
+ *path = vim_strsave(fname);
return TRUE;
}
@@ -1996,7 +2000,7 @@ mch_init(void)
vimrun_path = (char *)vim_strsave(vimrun_location);
s_dont_use_vimrun = FALSE;
}
- else if (executable_exists("vimrun.exe"))
+ else if (executable_exists("vimrun.exe", NULL))
s_dont_use_vimrun = FALSE;
/* 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'.
* 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);
#ifdef FEAT_CLIPBOARD
@@ -3330,7 +3334,7 @@ mch_writable(char_u *name)
* Return -1 if unknown.
*/
int
-mch_can_exe(char_u *name)
+mch_can_exe(char_u *name, char_u **path)
{
char_u buf[_MAX_PATH];
int len = (int)STRLEN(name);
@@ -3343,7 +3347,7 @@ mch_can_exe(char_u *name)
* this with a Unix-shell like 'shell'. */
if (vim_strchr(gettail(name), '.') != NULL
|| strstr((char *)gettail(p_sh), "sh") != NULL)
- if (executable_exists((char *)name))
+ if (executable_exists((char *)name, path))
return TRUE;
/*
@@ -3365,7 +3369,7 @@ mch_can_exe(char_u *name)
}
else
copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
- if (executable_exists((char *)buf))
+ if (executable_exists((char *)buf, path))
return TRUE;
}
return FALSE;
diff --git a/src/proto/os_amiga.pro b/src/proto/os_amiga.pro
index 3cbec6d2..16ee6571 100644
--- a/src/proto/os_amiga.pro
+++ b/src/proto/os_amiga.pro
@@ -26,7 +26,7 @@ int mch_setperm __ARGS((char_u *name, long perm));
void mch_hide __ARGS((char_u *name));
int mch_isdir __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));
void mch_early_init __ARGS((void));
void mch_exit __ARGS((int r));
diff --git a/src/proto/os_msdos.pro b/src/proto/os_msdos.pro
index a867f3d1..e7552111 100644
--- a/src/proto/os_msdos.pro
+++ b/src/proto/os_msdos.pro
@@ -38,7 +38,7 @@ long mch_getperm __ARGS((char_u *name));
int mch_setperm __ARGS((char_u *name, long perm));
void mch_hide __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_dirname __ARGS((char_u *buf, int len));
int mch_remove __ARGS((char_u *name));
diff --git a/src/proto/os_unix.pro b/src/proto/os_unix.pro
index e4cad51d..a59b6aa5 100644
--- a/src/proto/os_unix.pro
+++ b/src/proto/os_unix.pro
@@ -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_hide __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));
void mch_early_init __ARGS((void));
void mch_free_mem __ARGS((void));
diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro
index a4c590f3..c149bc89 100644
--- a/src/proto/os_win32.pro
+++ b/src/proto/os_win32.pro
@@ -26,7 +26,7 @@ int mch_is_symbolic_link __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 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));
vim_acl_T mch_get_acl __ARGS((char_u *fname));
void mch_set_acl __ARGS((char_u *fname, vim_acl_T acl));
diff --git a/src/version.c b/src/version.c
index 542342f3..295af344 100644
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 235,
+/**/
234,
/**/
233,