diff options
author | Bram Moolenaar <Bram@vim.org> | 2005-07-25 20:42:36 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2005-07-25 20:42:36 +0000 |
commit | 027436338b4b3e746ae5087b8a01c7404619d97b (patch) | |
tree | bd958bdd54dfad7073d368c34fc8cdcf863df9af /src/os_unix.c | |
parent | c013cb66a6f2403e90a43203e4059b4bb531a8e8 (diff) | |
download | vim-git-027436338b4b3e746ae5087b8a01c7404619d97b.tar.gz |
updated for version 7.0116
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 180 |
1 files changed, 5 insertions, 175 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index 9881d4a80..c1b64a76e 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -174,8 +174,6 @@ static int have_dollars __ARGS((int, char_u **)); #endif #ifndef NO_EXPANDPATH -static int pstrcmp __ARGS((const void *, const void *)); -static int unix_expandpath __ARGS((garray_T *gap, char_u *path, int wildoff, int flags)); # if defined(MACOS_X) && defined(FEAT_MBYTE) extern char_u *mac_precompose_path __ARGS((char_u *decompPath, size_t decompLen, size_t *precompLen)); # endif @@ -4735,19 +4733,11 @@ RealWaitForChar(fd, msec, check_for_gpm) #ifndef VMS #ifndef NO_EXPANDPATH - static int -pstrcmp(a, b) - const void *a, *b; -{ - return (pathcmp(*(char **)a, *(char **)b, -1)); -} - /* - * Recursively expand one path component into all matching files and/or - * directories. - * "path" has backslashes before chars that are not to be expanded, starting - * at "path + wildoff". - * Return the number of matches found. + * Expand a path into all matching files and/or directories. Handles "*", + * "?", "[a-z]", "**", etc. + * "path" has backslashes before chars that are not to be expanded. + * Returns the number of matches found. */ int mch_expandpath(gap, path, flags) @@ -4755,167 +4745,7 @@ mch_expandpath(gap, path, flags) char_u *path; int flags; /* EW_* flags */ { - return unix_expandpath(gap, path, 0, flags); -} - - static int -unix_expandpath(gap, path, wildoff, flags) - 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, c; - char_u *pat; - DIR *dirp; - regmatch_T regmatch; - struct dirent *dp; - int starts_with_dot; - int matches; - int len; - - start_len = gap->ga_len; - buf = alloc(STRLEN(path) + BASENAMELEN + 5);/* make room for file name */ - if (buf == NULL) - return 0; - -/* - * Find the first part in the path name that contains a wildcard. - * Copy it into buf, including the preceding characters. - */ - 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 == '/') - { - 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; - } - - /* convert the file pattern to a regexp pattern */ - starts_with_dot = (*s == '.'); - pat = file_pat_to_reg_pat(s, e, NULL, FALSE); - if (pat == NULL) - { - vim_free(buf); - return 0; - } - - /* compile the regexp into a program */ -#ifdef MACOS_X /* Can/Should we use CASE_INSENSITIVE_FILENAME instead ?*/ - regmatch.rm_ic = TRUE; /* Behave like Terminal.app */ -#else - regmatch.rm_ic = FALSE; /* Don't ever ignore case */ -#endif - regmatch.regprog = vim_regcomp(pat, RE_MAGIC); - vim_free(pat); - - if (regmatch.regprog == NULL) - { - vim_free(buf); - return 0; - } - - /* open the directory for scanning */ - c = *s; - *s = NUL; - dirp = opendir(*buf == NUL ? "." : (char *)buf); - *s = c; - - /* Find all matching entries */ - if (dirp != NULL) - { - for (;;) - { - dp = readdir(dirp); - if (dp == NULL) - break; - if ((dp->d_name[0] != '.' || starts_with_dot) - && vim_regexec(®match, (char_u *)dp->d_name, (colnr_T)0)) - { - STRCPY(s, dp->d_name); - len = STRLEN(buf); - STRCPY(buf + len, path_end); - if (mch_has_exp_wildcard(path_end)) /* handle more wildcards */ - { - /* need to expand another component of the path */ - /* remove backslashes for the remaining components only */ - (void)unix_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 != NUL) - backslash_halve(buf + len + 1); - if (mch_getperm(buf) >= 0) /* add existing file */ - { -#if defined(MACOS_X) && defined(FEAT_MBYTE) - size_t precomp_len = STRLEN(buf)+1; - char_u *precomp_buf = - mac_precompose_path(buf, precomp_len, &precomp_len); - if (precomp_buf) - { - mch_memmove(buf, precomp_buf, precomp_len); - vim_free(precomp_buf); - } -#endif - addfile(gap, buf, flags); - } - } - } - } - - closedir(dirp); - } - - vim_free(buf); - 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; + return unix_expandpath(gap, path, 0, flags, FALSE); } #endif |