]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.235 v7.4.235
authorBram Moolenaar <Bram@vim.org>
Tue, 1 Apr 2014 19:00:59 +0000 (21:00 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 1 Apr 2014 19:00:59 +0000 (21:00 +0200)
Problem:    It is not easy to get the full path of a command.
Solution:   Add the exepath() function.

13 files changed:
runtime/doc/eval.txt
src/eval.c
src/misc1.c
src/os_amiga.c
src/os_msdos.c
src/os_unix.c
src/os_vms.c
src/os_win32.c
src/proto/os_amiga.pro
src/proto/os_msdos.pro
src/proto/os_unix.pro
src/proto/os_win32.pro
src/version.c

index 66ee3aa2f272a30962e44937baa8e27aea0458c9..66b3038e26f52b514c96cc3f47d7ccf88487cebd 100644 (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
                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,
index 246e404bc87e1234159e4c680de8b46169a606e4..65419cb367b5e732dcb67d620254cf1fabf0ae71 100644 (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_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;
 }
 
 /*
index 943496186041840e99f6957ec989dea7e2f9e923..c52945f5cbe7c5e568aed5dd5ccfbdcddbbf8dc1 100644 (file)
@@ -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. */
index e5c7661efd8898ad1d01cddb624982f7cf32f1a5..324fc367b7c475e69560d6f7b37cffa8a53e3116 100644 (file)
@@ -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;
index 10c70b2e3b233902f91a055cdba3dbd09ebace18..f24a6f8eadfb7d3bbf8422084d81674ea61d1e30 100644 (file)
@@ -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;
 }
 
index 48f45b0ebd3ca9e30122366cb36a6ab17ae9be75..63d39493bac75be5964c92ee154d995dac983c50 100644 (file)
@@ -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()
index 814b64a3401370e9dca2424a754f9311cc40378e..55876b27fe6ae54543c56194cc4b9d4bfe353037 100644 (file)
@@ -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 */
index c23b791ae7cbd47a5d699ac0ae061aadb7d5e056..09e5c610ddec8029eb8ab27a74db4e5c62a206a1 100644 (file)
@@ -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;
index 3cbec6d26565386d39f39066d2d68fc4b0080f5f..16ee6571df19cc6774fb2b0cf21fac2d8c24aebb 100644 (file)
@@ -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));
index a867f3d1c89169080c85af769ce1ffeaa2a16430..e75521110a679976e2bcd32eabe35ac8e3a53d49 100644 (file)
@@ -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));
index e4cad51de4e2945efbbbb4c45b44fece531c04a3..a59b6aa5e5429e4a21f8aa2679398dd53ba01acf 100644 (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_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));
index a4c590f300f7c1bcb59e546594819a58d6a9b3ce..c149bc89f574b906149cb5450197dbb6458355a6 100644 (file)
@@ -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));
index 542342f3338b78bde5062ebaba7e23d71e2deb98..295af344ab4859162ae16dcfd7d9e342970cbb43 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    235,
 /**/
     234,
 /**/