comparison src/misc2.c @ 17978:8f4cc259ed7a v8.1.1985

patch 8.1.1985: code for dealing with paths is spread out Commit: https://github.com/vim/vim/commit/26262f87770d3a1a68b09a70152d75c2e2ae186f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 4 20:59:15 2019 +0200 patch 8.1.1985: code for dealing with paths is spread out Problem: Code for dealing with paths is spread out. Solution: Move path related functions from misc1.c to filepath.c. Remove NO_EXPANDPATH.
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Sep 2019 21:00:04 +0200
parents 59f8948b7590
children 8b4f9be5db73
comparison
equal deleted inserted replaced
17977:7fa0c4b6bfa5 17978:8f4cc259ed7a
3936 int count) 3936 int count)
3937 { 3937 {
3938 qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare); 3938 qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare);
3939 } 3939 }
3940 3940
3941 #if !defined(NO_EXPANDPATH) || defined(PROTO)
3942 /*
3943 * Compare path "p[]" to "q[]".
3944 * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]"
3945 * Return value like strcmp(p, q), but consider path separators.
3946 */
3947 int
3948 pathcmp(const char *p, const char *q, int maxlen)
3949 {
3950 int i, j;
3951 int c1, c2;
3952 const char *s = NULL;
3953
3954 for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);)
3955 {
3956 c1 = PTR2CHAR((char_u *)p + i);
3957 c2 = PTR2CHAR((char_u *)q + j);
3958
3959 /* End of "p": check if "q" also ends or just has a slash. */
3960 if (c1 == NUL)
3961 {
3962 if (c2 == NUL) /* full match */
3963 return 0;
3964 s = q;
3965 i = j;
3966 break;
3967 }
3968
3969 /* End of "q": check if "p" just has a slash. */
3970 if (c2 == NUL)
3971 {
3972 s = p;
3973 break;
3974 }
3975
3976 if ((p_fic ? MB_TOUPPER(c1) != MB_TOUPPER(c2) : c1 != c2)
3977 #ifdef BACKSLASH_IN_FILENAME
3978 /* consider '/' and '\\' to be equal */
3979 && !((c1 == '/' && c2 == '\\')
3980 || (c1 == '\\' && c2 == '/'))
3981 #endif
3982 )
3983 {
3984 if (vim_ispathsep(c1))
3985 return -1;
3986 if (vim_ispathsep(c2))
3987 return 1;
3988 return p_fic ? MB_TOUPPER(c1) - MB_TOUPPER(c2)
3989 : c1 - c2; /* no match */
3990 }
3991
3992 i += MB_PTR2LEN((char_u *)p + i);
3993 j += MB_PTR2LEN((char_u *)q + j);
3994 }
3995 if (s == NULL) /* "i" or "j" ran into "maxlen" */
3996 return 0;
3997
3998 c1 = PTR2CHAR((char_u *)s + i);
3999 c2 = PTR2CHAR((char_u *)s + i + MB_PTR2LEN((char_u *)s + i));
4000 /* ignore a trailing slash, but not "//" or ":/" */
4001 if (c2 == NUL
4002 && i > 0
4003 && !after_pathsep((char_u *)s, (char_u *)s + i)
4004 #ifdef BACKSLASH_IN_FILENAME
4005 && (c1 == '/' || c1 == '\\')
4006 #else
4007 && c1 == '/'
4008 #endif
4009 )
4010 return 0; /* match with trailing slash */
4011 if (s == q)
4012 return -1; /* no match */
4013 return 1;
4014 }
4015 #endif
4016
4017 /* 3941 /*
4018 * The putenv() implementation below comes from the "screen" program. 3942 * The putenv() implementation below comes from the "screen" program.
4019 * Included with permission from Juergen Weigert. 3943 * Included with permission from Juergen Weigert.
4020 * See pty.c for the copyright notice. 3944 * See pty.c for the copyright notice.
4021 */ 3945 */