To: vim-dev@vim.org Subject: Patch 6.1.052 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.052 Problem: Unix: The executable() function doesn't work when the "which" command isn't available. Solution: Go through $PATH manually. Also makes it work for VMS. Files: src/os_unix.c *** ../vim61.051/src/os_unix.c Wed May 1 19:40:35 2002 --- src/os_unix.c Fri May 3 19:35:14 2002 *************** *** 2287,2294 **** } #if defined(FEAT_EVAL) || defined(PROTO) /* ! * Return 1 if "name" can be executed, 0 if not. * Return -1 if unknown. */ int --- 2287,2311 ---- } #if defined(FEAT_EVAL) || defined(PROTO) + + static int executable_file __ARGS((char_u *name)); + /* ! * Return 1 if "name" is an executable file, 0 if not or it doesn't exist. ! */ ! static int ! executable_file(name) ! char_u *name; ! { ! struct stat st; ! ! if (stat((char *)name, &st)) ! return 0; ! return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0; ! } ! ! /* ! * Return 1 if "name" can be found in $PATH and executed, 0 if not. * Return -1 if unknown. */ int *************** *** 2296,2320 **** char_u *name; { char_u *buf; ! char_u *p; int retval; ! #ifdef VMS ! /* TODO */ ! return -1; ! #endif ! buf = alloc((unsigned)STRLEN(name) + 7); if (buf == NULL) return -1; ! sprintf((char *)buf, "which %s", name); ! p = get_cmd_output(buf, SHELL_SILENT); vim_free(buf); - if (p == NULL) - return -1; - /* result can be: "name: Command not found" */ - retval = (*p != NUL && strstr((char *)p, "not found") == NULL); - vim_free(p); return retval; } #endif --- 2313,2361 ---- char_u *name; { char_u *buf; ! char_u *p, *e; int retval; ! /* If it's an absolute or relative path don't need to use $PATH. */ ! if (mch_isFullName(name) || (name[0] == '.' && (name[1] == '/' ! || (name[1] == '.' && name[2] == '/')))) ! return executable_file(name); ! p = (char_u *)getenv("PATH"); ! if (p == NULL || *p == NUL) ! return -1; ! buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); if (buf == NULL) return -1; ! ! /* ! * Walk through all entries in $PATH to check if "name" exists there and ! * is an executable file. ! */ ! for (;;) ! { ! e = (char_u *)strchr((char *)p, ':'); ! if (e == NULL) ! e = p + STRLEN(p); ! if (e - p <= 1) /* empty entry means current dir */ ! STRCPY(buf, "./"); ! else ! { ! STRNCPY(buf, p, e - p); ! buf[e - p] = NUL; ! add_pathsep(buf); ! } ! STRCAT(buf, name); ! retval = executable_file(buf); ! if (retval == 1) ! break; ! ! if (*e != ':') ! break; ! p = e + 1; ! } ! vim_free(buf); return retval; } #endif *** ../vim61.051/src/version.c Sun May 5 14:29:43 2002 --- src/version.c Sun May 5 14:30:52 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 52, /**/ -- Lawmakers made it obligatory for everybody to take at least one bath each week -- on Saturday night. [real standing law in Vermont, United States of America] /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///