@@ -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
33663381mch_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;
0 commit comments