Skip to content

Commit 4366319

Browse files
committed
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)
1 parent 0f9ea22 commit 4366319

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

src/main.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,21 +3533,31 @@ time_msg(
35333533
set_progpath(char_u *argv0)
35343534
{
35353535
char_u *val = argv0;
3536+
#ifdef WIN32
3537+
char_u *path = NULL;
3538+
#else
35363539
char_u buf[MAXPATHL];
3540+
#endif
35373541

35383542
/* A relative path containing a "/" will become invalid when using ":cd",
35393543
* turn it into a full path.
35403544
* On MS-Windows "vim.exe" is found in the current directory, thus also do
35413545
* it when there is no path and the file exists. */
3542-
if ( !mch_isFullName(argv0)
3546+
if (!mch_isFullName(argv0))
3547+
{
35433548
# ifdef WIN32
3544-
&& mch_can_exe(argv0, NULL, TRUE)
3549+
if (mch_can_exe(argv0, &path, FALSE) && path != NULL)
3550+
val = path;
35453551
# else
3546-
&& gettail(argv0) != argv0
3552+
if (gettail(argv0) != argv0
3553+
&& vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL)
3554+
val = buf;
35473555
# endif
3548-
&& vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL)
3549-
val = buf;
3556+
}
35503557
set_vim_var_string(VV_PROGPATH, val, -1);
3558+
#ifdef WIN32
3559+
vim_free(path);
3560+
#endif
35513561
}
35523562

35533563
#endif /* NO_VIM_MAIN */

src/os_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
31033103
{
31043104
if (path != NULL)
31053105
{
3106-
if (name[0] == '.')
3106+
if (name[0] != '/')
31073107
*path = FullName_save(name, TRUE);
31083108
else
31093109
*path = vim_strsave(name);
@@ -3142,7 +3142,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
31423142
{
31433143
if (path != NULL)
31443144
{
3145-
if (buf[0] == '.')
3145+
if (buf[0] != '/')
31463146
*path = FullName_save(buf, TRUE);
31473147
else
31483148
*path = vim_strsave(buf);

src/os_win32.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,17 +1902,31 @@ mch_inchar(
19021902
#endif
19031903

19041904
/*
1905-
* Return TRUE if "name" is in $PATH.
1905+
* If "use_path" is TRUE: Return TRUE if "name" is in $PATH.
1906+
* If "use_path" is FALSE: Return TRUE if "name" exists.
1907+
* When returning TRUE and "path" is not NULL save the path and set "*path" to
1908+
* the allocated memory.
19061909
* TODO: Should somehow check if it's really executable.
19071910
*/
19081911
static int
1909-
executable_exists(char *name, char_u **path)
1912+
executable_exists(char *name, char_u **path, int use_path)
19101913
{
19111914
char *dum;
19121915
char fname[_MAX_PATH];
19131916
char *curpath, *newpath;
19141917
long n;
19151918

1919+
if (!use_path)
1920+
{
1921+
if (mch_getperm(name) != -1 && !mch_isdir(name))
1922+
{
1923+
if (path != NULL)
1924+
*path = vim_strsave((char_u *)name);
1925+
return TRUE;
1926+
}
1927+
return FALSE;
1928+
}
1929+
19161930
#ifdef FEAT_MBYTE
19171931
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
19181932
{
@@ -2038,7 +2052,7 @@ mch_init(void)
20382052
vimrun_path = (char *)vim_strsave(vimrun_location);
20392053
s_dont_use_vimrun = FALSE;
20402054
}
2041-
else if (executable_exists("vimrun.exe", NULL))
2055+
else if (executable_exists("vimrun.exe", NULL, TRUE))
20422056
s_dont_use_vimrun = FALSE;
20432057

20442058
/* Don't give the warning for a missing vimrun.exe right now, but only
@@ -2052,7 +2066,7 @@ mch_init(void)
20522066
* If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
20532067
* Otherwise the default "findstr /n" is used.
20542068
*/
2055-
if (!executable_exists("findstr.exe", NULL))
2069+
if (!executable_exists("findstr.exe", NULL, TRUE))
20562070
set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);
20572071

20582072
#ifdef FEAT_CLIPBOARD
@@ -3358,9 +3372,10 @@ mch_writable(char_u *name)
33583372
}
33593373

33603374
/*
3361-
* Return 1 if "name" can be executed, 0 if not.
3375+
* Return TRUE if "name" can be executed, FALSE if not.
33623376
* If "use_path" is FALSE only check if "name" is executable.
3363-
* Return -1 if unknown.
3377+
* When returning TRUE and "path" is not NULL save the path and set "*path" to
3378+
* the allocated memory.
33643379
*/
33653380
int
33663381
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)
33713386

33723387
if (len >= _MAX_PATH) /* safety check */
33733388
return FALSE;
3374-
if (!use_path)
3375-
{
3376-
/* TODO: check if file is really executable. */
3377-
return mch_getperm(name) != -1 && !mch_isdir(name);
3378-
}
33793389

33803390
/* If there already is an extension try using the name directly. Also do
33813391
* this with a Unix-shell like 'shell'. */
33823392
if (vim_strchr(gettail(name), '.') != NULL
33833393
|| strstr((char *)gettail(p_sh), "sh") != NULL)
3384-
if (executable_exists((char *)name, path))
3394+
if (executable_exists((char *)name, path, use_path))
33853395
return TRUE;
33863396

33873397
/*
@@ -3403,7 +3413,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
34033413
}
34043414
else
34053415
copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
3406-
if (executable_exists((char *)buf, path))
3416+
if (executable_exists((char *)buf, path, use_path))
34073417
return TRUE;
34083418
}
34093419
return FALSE;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
416,
767769
/**/
768770
415,
769771
/**/

0 commit comments

Comments
 (0)