073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.235
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.235
073263
Problem:    It is not easy to get the full path of a command.
073263
Solution:   Add the exepath() function.
073263
Files:	    src/eval.c, src/misc1.c, src/os_amiga.c, src/os_msdos.c,
073263
	    src/os_unix.c, src/os_vms.c, src/os_win32.c,
073263
	    src/proto/os_amiga.pro, src/proto/os_msdos.pro,
073263
	    src/proto/os_unix.pro, src/proto/os_win32.pro,
073263
	    runtime/doc/eval.txt
073263
073263
073263
*** ../vim-7.4.234/src/eval.c	2014-04-01 19:55:46.252787300 +0200
073263
--- src/eval.c	2014-04-01 20:18:39.212768414 +0200
073263
***************
073263
*** 514,519 ****
073263
--- 514,520 ----
073263
  static void f_eval __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_eventhandler __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_executable __ARGS((typval_T *argvars, typval_T *rettv));
073263
+ static void f_exepath __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_exists __ARGS((typval_T *argvars, typval_T *rettv));
073263
  #ifdef FEAT_FLOAT
073263
  static void f_exp __ARGS((typval_T *argvars, typval_T *rettv));
073263
***************
073263
*** 7920,7925 ****
073263
--- 7921,7927 ----
073263
      {"eval",		1, 1, f_eval},
073263
      {"eventhandler",	0, 0, f_eventhandler},
073263
      {"executable",	1, 1, f_executable},
073263
+     {"exepath",		1, 1, f_exepath},
073263
      {"exists",		1, 1, f_exists},
073263
  #ifdef FEAT_FLOAT
073263
      {"exp",		1, 1, f_exp},
073263
***************
073263
*** 10046,10052 ****
073263
      typval_T	*argvars;
073263
      typval_T	*rettv;
073263
  {
073263
!     rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0]));
073263
  }
073263
  
073263
  /*
073263
--- 10048,10069 ----
073263
      typval_T	*argvars;
073263
      typval_T	*rettv;
073263
  {
073263
!     rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0]), NULL);
073263
! }
073263
! 
073263
! /*
073263
!  * "exepath()" function
073263
!  */
073263
!     static void
073263
! f_exepath(argvars, rettv)
073263
!     typval_T	*argvars;
073263
!     typval_T	*rettv;
073263
! {
073263
!     char_u *p = NULL;
073263
! 
073263
!     (void)mch_can_exe(get_tv_string(&argvars[0]), &p);
073263
!     rettv->v_type = VAR_STRING;
073263
!     rettv->vval.v_string = p;
073263
  }
073263
  
073263
  /*
073263
*** ../vim-7.4.234/src/misc1.c	2014-03-12 18:55:52.100906804 +0100
073263
--- src/misc1.c	2014-04-01 20:01:08.752782864 +0200
073263
***************
073263
*** 10728,10734 ****
073263
  	return;
073263
  
073263
      /* If the file isn't executable, may not add it.  Do accept directories. */
073263
!     if (!isdir && (flags & EW_EXEC) && !mch_can_exe(f))
073263
  	return;
073263
  
073263
      /* Make room for another item in the file list. */
073263
--- 10728,10734 ----
073263
  	return;
073263
  
073263
      /* If the file isn't executable, may not add it.  Do accept directories. */
073263
!     if (!isdir && (flags & EW_EXEC) && !mch_can_exe(f, NULL))
073263
  	return;
073263
  
073263
      /* Make room for another item in the file list. */
073263
*** ../vim-7.4.234/src/os_amiga.c	2013-05-06 04:06:04.000000000 +0200
073263
--- src/os_amiga.c	2014-04-01 20:19:50.804767429 +0200
073263
***************
073263
*** 884,891 ****
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(name)
073263
      char_u	*name;
073263
  {
073263
      /* TODO */
073263
      return -1;
073263
--- 884,892 ----
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(name, path)
073263
      char_u	*name;
073263
+     char_u	**path;
073263
  {
073263
      /* TODO */
073263
      return -1;
073263
*** ../vim-7.4.234/src/os_msdos.c	2014-03-23 15:12:29.931264336 +0100
073263
--- src/os_msdos.c	2014-04-01 20:02:39.996781608 +0200
073263
***************
073263
*** 2945,2958 ****
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(name)
073263
      char_u	*name;
073263
  {
073263
      char	*p;
073263
  
073263
      p = searchpath(name);
073263
      if (p == NULL || mch_isdir(p))
073263
  	return FALSE;
073263
      return TRUE;
073263
  }
073263
  
073263
--- 2945,2961 ----
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(name, path)
073263
      char_u	*name;
073263
+     char_u	**path;
073263
  {
073263
      char	*p;
073263
  
073263
      p = searchpath(name);
073263
      if (p == NULL || mch_isdir(p))
073263
  	return FALSE;
073263
+     if (path != NULL)
073263
+ 	*path = vim_strsave(p);
073263
      return TRUE;
073263
  }
073263
  
073263
*** ../vim-7.4.234/src/os_unix.c	2014-03-12 16:51:35.060792541 +0100
073263
--- src/os_unix.c	2014-04-01 20:46:21.304745550 +0200
073263
***************
073263
*** 2992,2999 ****
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(name)
073263
      char_u	*name;
073263
  {
073263
      char_u	*buf;
073263
      char_u	*p, *e;
073263
--- 2992,3000 ----
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(name, path)
073263
      char_u	*name;
073263
+     char_u	**path;
073263
  {
073263
      char_u	*buf;
073263
      char_u	*p, *e;
073263
***************
073263
*** 3003,3009 ****
073263
      if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/'
073263
  				      || (name[1] == '.' && name[2] == '/'))))
073263
      {
073263
! 	return executable_file(name);
073263
      }
073263
  
073263
      p = (char_u *)getenv("PATH");
073263
--- 3004,3021 ----
073263
      if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/'
073263
  				      || (name[1] == '.' && name[2] == '/'))))
073263
      {
073263
! 	if (executable_file(name))
073263
! 	{
073263
! 	    if (path != NULL)
073263
! 	    {
073263
! 		if (name[0] == '.')
073263
! 		    *path = FullName_save(name, TRUE);
073263
! 		else
073263
! 		    *path = vim_strsave(name);
073263
! 	    }
073263
! 	    return TRUE;
073263
! 	}
073263
! 	return FALSE;
073263
      }
073263
  
073263
      p = (char_u *)getenv("PATH");
073263
***************
073263
*** 3032,3038 ****
073263
--- 3044,3059 ----
073263
  	STRCAT(buf, name);
073263
  	retval = executable_file(buf);
073263
  	if (retval == 1)
073263
+ 	{
073263
+ 	    if (path != NULL)
073263
+ 	    {
073263
+ 		if (buf[0] == '.')
073263
+ 		    *path = FullName_save(buf, TRUE);
073263
+ 		else
073263
+ 		    *path = vim_strsave(buf);
073263
+ 	    }
073263
  	    break;
073263
+ 	}
073263
  
073263
  	if (*e != ':')
073263
  	    break;
073263
***************
073263
*** 5592,5598 ****
073263
  		    continue;
073263
  
073263
  		/* Skip files that are not executable if we check for that. */
073263
! 		if (!dir && (flags & EW_EXEC) && !mch_can_exe(p))
073263
  		    continue;
073263
  
073263
  		if (--files_free == 0)
073263
--- 5613,5619 ----
073263
  		    continue;
073263
  
073263
  		/* Skip files that are not executable if we check for that. */
073263
! 		if (!dir && (flags & EW_EXEC) && !mch_can_exe(p, NULL))
073263
  		    continue;
073263
  
073263
  		if (--files_free == 0)
073263
***************
073263
*** 6090,6096 ****
073263
  	    continue;
073263
  
073263
  	/* Skip files that are not executable if we check for that. */
073263
! 	if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i]))
073263
  	    continue;
073263
  
073263
  	p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir));
073263
--- 6111,6117 ----
073263
  	    continue;
073263
  
073263
  	/* Skip files that are not executable if we check for that. */
073263
! 	if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i], NULL))
073263
  	    continue;
073263
  
073263
  	p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir));
073263
***************
073263
*** 6317,6323 ****
073263
  
073263
  /* Reads gpm event and adds special keys to input buf. Returns length of
073263
   * generated key sequence.
073263
!  * This function is made after gui_send_mouse_event
073263
   */
073263
      static int
073263
  mch_gpm_process()
073263
--- 6338,6344 ----
073263
  
073263
  /* Reads gpm event and adds special keys to input buf. Returns length of
073263
   * generated key sequence.
073263
!  * This function is styled after gui_send_mouse_event().
073263
   */
073263
      static int
073263
  mch_gpm_process()
073263
*** ../vim-7.4.234/src/os_vms.c	2014-03-12 16:51:35.060792541 +0100
073263
--- src/os_vms.c	2014-04-01 20:05:52.960778954 +0200
073263
***************
073263
*** 483,489 ****
073263
  		continue;
073263
  
073263
  	    /* Skip files that are not executable if we check for that. */
073263
! 	    if (!dir && (flags & EW_EXEC) && !mch_can_exe(vms_fmatch[i]))
073263
  		continue;
073263
  
073263
  	    /* allocate memory for pointers */
073263
--- 483,489 ----
073263
  		continue;
073263
  
073263
  	    /* Skip files that are not executable if we check for that. */
073263
! 	    if (!dir && (flags & EW_EXEC) && !mch_can_exe(vms_fmatch[i], NULL))
073263
  		continue;
073263
  
073263
  	    /* allocate memory for pointers */
073263
*** ../vim-7.4.234/src/os_win32.c	2014-02-11 17:05:57.282217857 +0100
073263
--- src/os_win32.c	2014-04-01 20:26:07.432762248 +0200
073263
***************
073263
*** 1882,1888 ****
073263
   * TODO: Should somehow check if it's really executable.
073263
   */
073263
      static int
073263
! executable_exists(char *name)
073263
  {
073263
      char	*dum;
073263
      char	fname[_MAX_PATH];
073263
--- 1882,1888 ----
073263
   * TODO: Should somehow check if it's really executable.
073263
   */
073263
      static int
073263
! executable_exists(char *name, char_u **path)
073263
  {
073263
      char	*dum;
073263
      char	fname[_MAX_PATH];
073263
***************
073263
*** 1905,1910 ****
073263
--- 1905,1912 ----
073263
  		    return FALSE;
073263
  		if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY)
073263
  		    return FALSE;
073263
+ 		if (path != NULL)
073263
+ 		    *path = utf16_to_enc(fnamew, NULL);
073263
  		return TRUE;
073263
  	    }
073263
  	    /* Retry with non-wide function (for Windows 98). */
073263
***************
073263
*** 1915,1920 ****
073263
--- 1917,1924 ----
073263
  	return FALSE;
073263
      if (mch_isdir(fname))
073263
  	return FALSE;
073263
+     if (path != NULL)
073263
+ 	*path = vim_strsave(fname);
073263
      return TRUE;
073263
  }
073263
  
073263
***************
073263
*** 1996,2002 ****
073263
  	    vimrun_path = (char *)vim_strsave(vimrun_location);
073263
  	    s_dont_use_vimrun = FALSE;
073263
  	}
073263
! 	else if (executable_exists("vimrun.exe"))
073263
  	    s_dont_use_vimrun = FALSE;
073263
  
073263
  	/* Don't give the warning for a missing vimrun.exe right now, but only
073263
--- 2000,2006 ----
073263
  	    vimrun_path = (char *)vim_strsave(vimrun_location);
073263
  	    s_dont_use_vimrun = FALSE;
073263
  	}
073263
! 	else if (executable_exists("vimrun.exe", NULL))
073263
  	    s_dont_use_vimrun = FALSE;
073263
  
073263
  	/* Don't give the warning for a missing vimrun.exe right now, but only
073263
***************
073263
*** 2010,2016 ****
073263
       * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
073263
       * Otherwise the default "findstr /n" is used.
073263
       */
073263
!     if (!executable_exists("findstr.exe"))
073263
  	set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);
073263
  
073263
  #ifdef FEAT_CLIPBOARD
073263
--- 2014,2020 ----
073263
       * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
073263
       * Otherwise the default "findstr /n" is used.
073263
       */
073263
!     if (!executable_exists("findstr.exe", NULL))
073263
  	set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);
073263
  
073263
  #ifdef FEAT_CLIPBOARD
073263
***************
073263
*** 3330,3336 ****
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(char_u *name)
073263
  {
073263
      char_u	buf[_MAX_PATH];
073263
      int		len = (int)STRLEN(name);
073263
--- 3334,3340 ----
073263
   * Return -1 if unknown.
073263
   */
073263
      int
073263
! mch_can_exe(char_u *name, char_u **path)
073263
  {
073263
      char_u	buf[_MAX_PATH];
073263
      int		len = (int)STRLEN(name);
073263
***************
073263
*** 3343,3349 ****
073263
       * this with a Unix-shell like 'shell'. */
073263
      if (vim_strchr(gettail(name), '.') != NULL
073263
  			       || strstr((char *)gettail(p_sh), "sh") != NULL)
073263
! 	if (executable_exists((char *)name))
073263
  	    return TRUE;
073263
  
073263
      /*
073263
--- 3347,3353 ----
073263
       * this with a Unix-shell like 'shell'. */
073263
      if (vim_strchr(gettail(name), '.') != NULL
073263
  			       || strstr((char *)gettail(p_sh), "sh") != NULL)
073263
! 	if (executable_exists((char *)name, path))
073263
  	    return TRUE;
073263
  
073263
      /*
073263
***************
073263
*** 3365,3371 ****
073263
  	}
073263
  	else
073263
  	    copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
073263
! 	if (executable_exists((char *)buf))
073263
  	    return TRUE;
073263
      }
073263
      return FALSE;
073263
--- 3369,3375 ----
073263
  	}
073263
  	else
073263
  	    copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
073263
! 	if (executable_exists((char *)buf, path))
073263
  	    return TRUE;
073263
      }
073263
      return FALSE;
073263
*** ../vim-7.4.234/src/proto/os_amiga.pro	2013-08-10 13:37:37.000000000 +0200
073263
--- src/proto/os_amiga.pro	2014-04-01 20:41:23.672749644 +0200
073263
***************
073263
*** 26,32 ****
073263
  void mch_hide __ARGS((char_u *name));
073263
  int mch_isdir __ARGS((char_u *name));
073263
  int mch_mkdir __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  void mch_early_init __ARGS((void));
073263
  void mch_exit __ARGS((int r));
073263
--- 26,32 ----
073263
  void mch_hide __ARGS((char_u *name));
073263
  int mch_isdir __ARGS((char_u *name));
073263
  int mch_mkdir __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name, char_u **path));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  void mch_early_init __ARGS((void));
073263
  void mch_exit __ARGS((int r));
073263
*** ../vim-7.4.234/src/proto/os_msdos.pro	2013-08-10 13:37:37.000000000 +0200
073263
--- src/proto/os_msdos.pro	2014-04-01 20:41:32.432749524 +0200
073263
***************
073263
*** 38,44 ****
073263
  int mch_setperm __ARGS((char_u *name, long perm));
073263
  void mch_hide __ARGS((char_u *name));
073263
  int mch_isdir __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  int mch_dirname __ARGS((char_u *buf, int len));
073263
  int mch_remove __ARGS((char_u *name));
073263
--- 38,44 ----
073263
  int mch_setperm __ARGS((char_u *name, long perm));
073263
  void mch_hide __ARGS((char_u *name));
073263
  int mch_isdir __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name, char_u **path));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  int mch_dirname __ARGS((char_u *buf, int len));
073263
  int mch_remove __ARGS((char_u *name));
073263
*** ../vim-7.4.234/src/proto/os_unix.pro	2013-08-10 13:37:23.000000000 +0200
073263
--- src/proto/os_unix.pro	2014-04-01 20:41:58.712749162 +0200
073263
***************
073263
*** 42,48 ****
073263
  void mch_free_acl __ARGS((vim_acl_T aclent));
073263
  void mch_hide __ARGS((char_u *name));
073263
  int mch_isdir __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  void mch_early_init __ARGS((void));
073263
  void mch_free_mem __ARGS((void));
073263
--- 42,48 ----
073263
  void mch_free_acl __ARGS((vim_acl_T aclent));
073263
  void mch_hide __ARGS((char_u *name));
073263
  int mch_isdir __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name, char_u **path));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  void mch_early_init __ARGS((void));
073263
  void mch_free_mem __ARGS((void));
073263
*** ../vim-7.4.234/src/proto/os_win32.pro	2013-08-10 13:37:38.000000000 +0200
073263
--- src/proto/os_win32.pro	2014-04-01 20:42:16.992748911 +0200
073263
***************
073263
*** 26,32 ****
073263
  int mch_is_linked __ARGS((char_u *fname));
073263
  int win32_fileinfo __ARGS((char_u *fname, BY_HANDLE_FILE_INFORMATION *info));
073263
  int mch_writable __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  vim_acl_T mch_get_acl __ARGS((char_u *fname));
073263
  void mch_set_acl __ARGS((char_u *fname, vim_acl_T acl));
073263
--- 26,32 ----
073263
  int mch_is_linked __ARGS((char_u *fname));
073263
  int win32_fileinfo __ARGS((char_u *fname, BY_HANDLE_FILE_INFORMATION *info));
073263
  int mch_writable __ARGS((char_u *name));
073263
! int mch_can_exe __ARGS((char_u *name, char_u **path));
073263
  int mch_nodetype __ARGS((char_u *name));
073263
  vim_acl_T mch_get_acl __ARGS((char_u *fname));
073263
  void mch_set_acl __ARGS((char_u *fname, vim_acl_T acl));
073263
*** ../vim-7.4.234/runtime/doc/eval.txt	2014-04-01 19:55:46.244787300 +0200
073263
--- runtime/doc/eval.txt	2014-04-01 20:54:37.832738720 +0200
073263
***************
073263
*** 1561,1566 ****
073263
--- 1562,1571 ----
073263
  v:progpath	Contains the command with which Vim was invoked, including the
073263
  		path.  Useful if you want to message a Vim server using a
073263
  		|--remote-expr|.
073263
+ 		To get the full path use: >
073263
+ 			echo exepath(v:progpath)
073263
+ <		NOTE: This does not work when the command is a relative path
073263
+ 		and the current directory has changed.
073263
  		Read-only.
073263
  
073263
  					*v:register* *register-variable*
073263
***************
073263
*** 1761,1766 ****
073263
--- 1766,1772 ----
073263
  eval( {string})			any	evaluate {string} into its value
073263
  eventhandler( )			Number	TRUE if inside an event handler
073263
  executable( {expr})		Number	1 if executable {expr} exists
073263
+ exepath( {expr})		String  full path of the command {expr}
073263
  exists( {expr})			Number	TRUE if {expr} exists
073263
  extend( {expr1}, {expr2} [, {expr3}])
073263
  				List/Dict insert items of {expr2} into {expr1}
073263
***************
073263
*** 2705,2710 ****
073263
--- 2711,2725 ----
073263
  			0	does not exist
073263
  			-1	not implemented on this system
073263
  
073263
+ exepath({expr})						*exepath()*
073263
+ 		If {expr} is an executable and is either an absolute path, a
073263
+ 		relative path or found in $PATH, return the full path.
073263
+ 		Note that the current directory is used when {expr} starts
073263
+ 		with "./", which may be a problem for Vim: >
073263
+ 			echo exepath(v:progpath)
073263
+ < 		If {expr} cannot be found in $PATH or is not executable then
073263
+ 		an empty string is returned.
073263
+ 
073263
  							*exists()*
073263
  exists({expr})	The result is a Number, which is non-zero if {expr} is
073263
  		defined, zero otherwise.  The {expr} argument is a string,
073263
*** ../vim-7.4.234/src/version.c	2014-04-01 19:55:46.252787300 +0200
073263
--- src/version.c	2014-04-01 20:00:44.108783203 +0200
073263
***************
073263
*** 736,737 ****
073263
--- 736,739 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     235,
073263
  /**/
073263
073263
-- 
073263
hundred-and-one symptoms of being an internet addict:
073263
19. All of your friends have an @ in their names.
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///