To: vim-dev@vim.org Subject: Patch 6.0.206 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.206 Problem: Unix: if expanding a wildcard in a file name results in a wildcard character and there are more parts in the path with a wildcard, it is expanded again. Windows: ":edit \[abc]" could never edit the file "[abc]". Solution: Don't expand wildcards in already expanded parts. Don't remove backslashes used to escape the special meaning of a wildcard; can edit "[abc]" if '[' is removed from 'isfname'. Files: src/misc1.c, src/os_unix.c *** ../vim60.205/src/misc1.c Mon Feb 4 22:37:41 2002 --- src/misc1.c Sun Feb 10 14:24:07 2002 *************** *** 6520,6535 **** * in `path'. Called by expand_wildcards(). * Return the number of matches found. * "path" has backslashes before chars that are not to be expanded, starting ! * at "wildc". */ static int dos_expandpath( garray_T *gap, char_u *path, ! char_u *wildc, int flags) /* EW_* flags */ { char_u *buf; char_u *p, *s, *e; int start_len = gap->ga_len; int ok; --- 6520,6536 ---- * in `path'. Called by expand_wildcards(). * Return the number of matches found. * "path" has backslashes before chars that are not to be expanded, starting ! * at "path[wildoff]". */ static int dos_expandpath( garray_T *gap, char_u *path, ! int wildoff, int flags) /* EW_* flags */ { char_u *buf; + char_u *path_end; char_u *p, *s, *e; int start_len = gap->ga_len; int ok; *************** *** 6558,6592 **** p = buf; s = buf; e = NULL; ! while (*path != NUL) { ! if (path >= wildc && rem_backslash(path)) /* remove a backslash */ ! ++path; ! else if (*path == '\\' || *path == ':' || *path == '/') { if (e != NULL) break; ! else ! s = p + 1; } ! else if (path >= wildc && (*path == '*' || *path == '?' ! || *path == '[' || *path == '~')) e = p; #ifdef FEAT_MBYTE if (has_mbyte) { ! len = (*mb_ptr2len_check)(path); ! STRNCPY(p, path, len); p += len; ! path += len; } else #endif ! *p++ = *path++; } e = p; *e = NUL; /* now we have one wildcard component between s and e */ starts_with_dot = (*s == '.'); pat = file_pat_to_reg_pat(s, e, NULL, FALSE); --- 6559,6605 ---- p = buf; s = buf; e = NULL; ! path_end = path; ! while (*path_end != NUL) { ! /* May ignore a wildcard that has a backslash before it; it will ! * be removed by rem_backslash() or file_pat_to_reg_pat() below. */ ! if (path_end >= path + wildoff && rem_backslash(path_end)) ! *p++ = *path_end++; ! else if (*path_end == '\\' || *path_end == ':' || *path_end == '/') { if (e != NULL) break; ! s = p + 1; } ! else if (path_end >= path + wildoff ! && vim_strchr((char_u *)"*?[~", *path_end) != NULL) e = p; #ifdef FEAT_MBYTE if (has_mbyte) { ! len = (*mb_ptr2len_check)(path_end); ! STRNCPY(p, path_end, len); p += len; ! path_end += len; } else #endif ! *p++ = *path_end++; } e = p; *e = NUL; + /* now we have one wildcard component between s and e */ + /* Remove backslashes between "wildoff" and the start of the wildcard + * component. */ + for (p = buf + wildoff; p < s; ++p) + if (rem_backslash(p)) + { + STRCPY(p, p + 1); + --e; + --s; + } starts_with_dot = (*s == '.'); pat = file_pat_to_reg_pat(s, e, NULL, FALSE); *************** *** 6618,6624 **** #else /* If we are expanding wildcards we try both files and directories */ ok = (findfirst((char *)buf, &fb, ! (*path || (flags & EW_DIR)) ? FA_DIREC : 0) == 0); #endif while (ok) --- 6631,6637 ---- #else /* If we are expanding wildcards we try both files and directories */ ok = (findfirst((char *)buf, &fb, ! (*path_end != NUL || (flags & EW_DIR)) ? FA_DIREC : 0) == 0); #endif while (ok) *************** *** 6640,6657 **** namelowcpy(s, p); #endif len = (int)STRLEN(buf); ! STRCPY(buf + len, path); ! if (mch_has_exp_wildcard(path)) { /* need to expand another component of the path */ /* remove backslashes for the remaining components only */ ! (void)dos_expandpath(gap, buf, buf + len + 1, flags); } else { /* no more wildcards, check if there is a match */ /* remove backslashes for the remaining components only */ ! if (*path) backslash_halve(buf + len + 1); if (mch_getperm(buf) >= 0) /* add existing file */ addfile(gap, buf, flags); --- 6653,6670 ---- namelowcpy(s, p); #endif len = (int)STRLEN(buf); ! STRCPY(buf + len, path_end); ! if (mch_has_exp_wildcard(path_end)) { /* need to expand another component of the path */ /* remove backslashes for the remaining components only */ ! (void)dos_expandpath(gap, buf, len + 1, flags); } else { /* no more wildcards, check if there is a match */ /* remove backslashes for the remaining components only */ ! if (*path_end != 0) backslash_halve(buf + len + 1); if (mch_getperm(buf) >= 0) /* add existing file */ addfile(gap, buf, flags); *************** *** 6674,6680 **** ok = (hFind != INVALID_HANDLE_VALUE); #else ok = (findfirst((char *)buf, &fb, ! (*path || (flags & EW_DIR)) ? FA_DIREC : 0) == 0); #endif vim_free(matchname); matchname = NULL; --- 6687,6693 ---- ok = (hFind != INVALID_HANDLE_VALUE); #else ok = (findfirst((char *)buf, &fb, ! (*path_end != NUL || (flags & EW_DIR)) ? FA_DIREC : 0) == 0); #endif vim_free(matchname); matchname = NULL; *************** *** 6689,6695 **** vim_free(matchname); matches = gap->ga_len - start_len; ! if (matches) qsort(((char_u **)gap->ga_data) + start_len, (size_t)matches, sizeof(char_u *), pstrcmp); return matches; --- 6702,6708 ---- vim_free(matchname); matches = gap->ga_len - start_len; ! if (matches > 0) qsort(((char_u **)gap->ga_data) + start_len, (size_t)matches, sizeof(char_u *), pstrcmp); return matches; *************** *** 6701,6709 **** char_u *path, int flags) /* EW_* flags */ { ! return dos_expandpath(gap, path, path, flags); } ! # endif /* MSDOS || FEAT_GUI_W16 */ /* * Generic wildcard expansion code. --- 6714,6722 ---- char_u *path, int flags) /* EW_* flags */ { ! return dos_expandpath(gap, path, 0, flags); } ! # endif /* MSDOS || FEAT_GUI_W16 || WIN3264 */ /* * Generic wildcard expansion code. *** ../vim60.205/src/os_unix.c Mon Feb 4 17:08:29 2002 --- src/os_unix.c Sun Feb 10 14:10:11 2002 *************** *** 3916,3924 **** s = buf; e = NULL; path_end = path; ! while (*path_end) { ! /* May ignore a wildcard that has a backslash before it */ if (path_end >= path + wildoff && rem_backslash(path_end)) *p++ = *path_end++; else if (*path_end == '/') --- 3970,3979 ---- s = buf; e = NULL; path_end = path; ! while (*path_end != NUL) { ! /* May ignore a wildcard that has a backslash before it; it will ! * be removed by rem_backslash() or file_pat_to_reg_pat() below. */ if (path_end >= path + wildoff && rem_backslash(path_end)) *p++ = *path_end++; else if (*path_end == '/') *************** *** 3927,3933 **** break; s = p + 1; } ! else if (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL) e = p; #ifdef FEAT_MBYTE if (has_mbyte) --- 3982,3989 ---- break; s = p + 1; } ! else if (path_end >= path + wildoff ! && vim_strchr((char_u *)"*?[{~$", *path_end) != NULL) e = p; #ifdef FEAT_MBYTE if (has_mbyte) *************** *** 4009,4015 **** { /* no more wildcards, check if there is a match */ /* remove backslashes for the remaining components only */ ! if (*path_end) backslash_halve(buf + len + 1); if (mch_getperm(buf) >= 0) /* add existing file */ addfile(gap, buf, flags); --- 4065,4071 ---- { /* no more wildcards, check if there is a match */ /* remove backslashes for the remaining components only */ ! if (*path_end != NUL) backslash_halve(buf + len + 1); if (mch_getperm(buf) >= 0) /* add existing file */ addfile(gap, buf, flags); *************** *** 4024,4030 **** vim_free(regmatch.regprog); matches = gap->ga_len - start_len; ! if (matches) qsort(((char_u **)gap->ga_data) + start_len, matches, sizeof(char_u *), pstrcmp); return matches; --- 4080,4086 ---- vim_free(regmatch.regprog); matches = gap->ga_len - start_len; ! if (matches > 0) qsort(((char_u **)gap->ga_data) + start_len, matches, sizeof(char_u *), pstrcmp); return matches; *** ../vim60.205/src/version.c Sun Feb 10 12:57:34 2002 --- src/version.c Sun Feb 10 14:21:30 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 206, /**/ -- GUARD #1: What, ridden on a horse? ARTHUR: Yes! GUARD #1: You're using coconuts! ARTHUR: What? GUARD #1: You've got two empty halves of coconut and you're bangin' 'em together. The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///