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

patch 8.0.0416: setting v:progpath is not quite right

Problem:    Setting v:progpath is not quite right.
Solution:   On MS-Windows add the extension. On Unix use the full path for a
            relative directory. (partly by James McCoy, closes #1531)
This commit is contained in:
Bram Moolenaar
2017-03-05 14:29:12 +01:00
parent 0f9ea22c11
commit 4366319697
4 changed files with 42 additions and 20 deletions

View File

@@ -3533,21 +3533,31 @@ time_msg(
set_progpath(char_u *argv0) set_progpath(char_u *argv0)
{ {
char_u *val = argv0; char_u *val = argv0;
#ifdef WIN32
char_u *path = NULL;
#else
char_u buf[MAXPATHL]; char_u buf[MAXPATHL];
#endif
/* A relative path containing a "/" will become invalid when using ":cd", /* A relative path containing a "/" will become invalid when using ":cd",
* turn it into a full path. * turn it into a full path.
* On MS-Windows "vim.exe" is found in the current directory, thus also do * On MS-Windows "vim.exe" is found in the current directory, thus also do
* it when there is no path and the file exists. */ * it when there is no path and the file exists. */
if ( !mch_isFullName(argv0) if (!mch_isFullName(argv0))
{
# ifdef WIN32 # ifdef WIN32
&& mch_can_exe(argv0, NULL, TRUE) if (mch_can_exe(argv0, &path, FALSE) && path != NULL)
val = path;
# else # else
&& gettail(argv0) != argv0 if (gettail(argv0) != argv0
&& vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL)
val = buf;
# endif # endif
&& vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL) }
val = buf;
set_vim_var_string(VV_PROGPATH, val, -1); set_vim_var_string(VV_PROGPATH, val, -1);
#ifdef WIN32
vim_free(path);
#endif
} }
#endif /* NO_VIM_MAIN */ #endif /* NO_VIM_MAIN */

View File

@@ -3103,7 +3103,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
{ {
if (path != NULL) if (path != NULL)
{ {
if (name[0] == '.') if (name[0] != '/')
*path = FullName_save(name, TRUE); *path = FullName_save(name, TRUE);
else else
*path = vim_strsave(name); *path = vim_strsave(name);
@@ -3142,7 +3142,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
{ {
if (path != NULL) if (path != NULL)
{ {
if (buf[0] == '.') if (buf[0] != '/')
*path = FullName_save(buf, TRUE); *path = FullName_save(buf, TRUE);
else else
*path = vim_strsave(buf); *path = vim_strsave(buf);

View File

@@ -1902,17 +1902,31 @@ theend:
#endif #endif
/* /*
* Return TRUE if "name" is in $PATH. * If "use_path" is TRUE: Return TRUE if "name" is in $PATH.
* If "use_path" is FALSE: Return TRUE if "name" exists.
* When returning TRUE and "path" is not NULL save the path and set "*path" to
* the allocated memory.
* 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, char_u **path) executable_exists(char *name, char_u **path, int use_path)
{ {
char *dum; char *dum;
char fname[_MAX_PATH]; char fname[_MAX_PATH];
char *curpath, *newpath; char *curpath, *newpath;
long n; long n;
if (!use_path)
{
if (mch_getperm(name) != -1 && !mch_isdir(name))
{
if (path != NULL)
*path = vim_strsave((char_u *)name);
return TRUE;
}
return FALSE;
}
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{ {
@@ -2038,7 +2052,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", NULL)) else if (executable_exists("vimrun.exe", NULL, TRUE))
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
@@ -2052,7 +2066,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", NULL)) if (!executable_exists("findstr.exe", NULL, TRUE))
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
@@ -3358,9 +3372,10 @@ mch_writable(char_u *name)
} }
/* /*
* Return 1 if "name" can be executed, 0 if not. * Return TRUE if "name" can be executed, FALSE if not.
* If "use_path" is FALSE only check if "name" is executable. * If "use_path" is FALSE only check if "name" is executable.
* Return -1 if unknown. * When returning TRUE and "path" is not NULL save the path and set "*path" to
* the allocated memory.
*/ */
int int
mch_can_exe(char_u *name, char_u **path, int use_path) mch_can_exe(char_u *name, char_u **path, int use_path)
@@ -3371,17 +3386,12 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
if (len >= _MAX_PATH) /* safety check */ if (len >= _MAX_PATH) /* safety check */
return FALSE; return FALSE;
if (!use_path)
{
/* TODO: check if file is really executable. */
return mch_getperm(name) != -1 && !mch_isdir(name);
}
/* If there already is an extension try using the name directly. Also do /* If there already is an extension try using the name directly. Also do
* 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, path)) if (executable_exists((char *)name, path, use_path))
return TRUE; return TRUE;
/* /*
@@ -3403,7 +3413,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
} }
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, path)) if (executable_exists((char *)buf, path, use_path))
return TRUE; return TRUE;
} }
return FALSE; return FALSE;

View File

@@ -764,6 +764,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 */
/**/
416,
/**/ /**/
415, 415,
/**/ /**/