comparison src/os_unix.c @ 5782:5ab2946f7ce5 v7.4.235

updated for version 7.4.235 Problem: It is not easy to get the full path of a command. Solution: Add the exepath() function.
author Bram Moolenaar <bram@vim.org>
date Tue, 01 Apr 2014 21:00:59 +0200
parents 47a673b20e49
children 410ef4f1a3d2
comparison
equal deleted inserted replaced
5781:eabbe5a74948 5782:5ab2946f7ce5
2990 /* 2990 /*
2991 * Return 1 if "name" can be found in $PATH and executed, 0 if not. 2991 * Return 1 if "name" can be found in $PATH and executed, 0 if not.
2992 * Return -1 if unknown. 2992 * Return -1 if unknown.
2993 */ 2993 */
2994 int 2994 int
2995 mch_can_exe(name) 2995 mch_can_exe(name, path)
2996 char_u *name; 2996 char_u *name;
2997 char_u **path;
2997 { 2998 {
2998 char_u *buf; 2999 char_u *buf;
2999 char_u *p, *e; 3000 char_u *p, *e;
3000 int retval; 3001 int retval;
3001 3002
3002 /* If it's an absolute or relative path don't need to use $PATH. */ 3003 /* If it's an absolute or relative path don't need to use $PATH. */
3003 if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/' 3004 if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/'
3004 || (name[1] == '.' && name[2] == '/')))) 3005 || (name[1] == '.' && name[2] == '/'))))
3005 { 3006 {
3006 return executable_file(name); 3007 if (executable_file(name))
3008 {
3009 if (path != NULL)
3010 {
3011 if (name[0] == '.')
3012 *path = FullName_save(name, TRUE);
3013 else
3014 *path = vim_strsave(name);
3015 }
3016 return TRUE;
3017 }
3018 return FALSE;
3007 } 3019 }
3008 3020
3009 p = (char_u *)getenv("PATH"); 3021 p = (char_u *)getenv("PATH");
3010 if (p == NULL || *p == NUL) 3022 if (p == NULL || *p == NUL)
3011 return -1; 3023 return -1;
3030 add_pathsep(buf); 3042 add_pathsep(buf);
3031 } 3043 }
3032 STRCAT(buf, name); 3044 STRCAT(buf, name);
3033 retval = executable_file(buf); 3045 retval = executable_file(buf);
3034 if (retval == 1) 3046 if (retval == 1)
3047 {
3048 if (path != NULL)
3049 {
3050 if (buf[0] == '.')
3051 *path = FullName_save(buf, TRUE);
3052 else
3053 *path = vim_strsave(buf);
3054 }
3035 break; 3055 break;
3056 }
3036 3057
3037 if (*e != ':') 3058 if (*e != ':')
3038 break; 3059 break;
3039 p = e + 1; 3060 p = e + 1;
3040 } 3061 }
5590 /* If we don't want dirs and this is one, skip it */ 5611 /* If we don't want dirs and this is one, skip it */
5591 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) 5612 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE)))
5592 continue; 5613 continue;
5593 5614
5594 /* Skip files that are not executable if we check for that. */ 5615 /* Skip files that are not executable if we check for that. */
5595 if (!dir && (flags & EW_EXEC) && !mch_can_exe(p)) 5616 if (!dir && (flags & EW_EXEC) && !mch_can_exe(p, NULL))
5596 continue; 5617 continue;
5597 5618
5598 if (--files_free == 0) 5619 if (--files_free == 0)
5599 { 5620 {
5600 /* need more room in table of pointers */ 5621 /* need more room in table of pointers */
6088 dir = (mch_isdir((*file)[i])); 6109 dir = (mch_isdir((*file)[i]));
6089 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) 6110 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE)))
6090 continue; 6111 continue;
6091 6112
6092 /* Skip files that are not executable if we check for that. */ 6113 /* Skip files that are not executable if we check for that. */
6093 if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i])) 6114 if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i], NULL))
6094 continue; 6115 continue;
6095 6116
6096 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); 6117 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir));
6097 if (p) 6118 if (p)
6098 { 6119 {
6315 Gpm_Close(); 6336 Gpm_Close();
6316 } 6337 }
6317 6338
6318 /* Reads gpm event and adds special keys to input buf. Returns length of 6339 /* Reads gpm event and adds special keys to input buf. Returns length of
6319 * generated key sequence. 6340 * generated key sequence.
6320 * This function is made after gui_send_mouse_event 6341 * This function is styled after gui_send_mouse_event().
6321 */ 6342 */
6322 static int 6343 static int
6323 mch_gpm_process() 6344 mch_gpm_process()
6324 { 6345 {
6325 int button; 6346 int button;