forked from aniani/vim
updated for version 7.1-304
This commit is contained in:
191
src/eval.c
191
src/eval.c
@@ -21068,8 +21068,12 @@ static int shortpath_for_invalid_fname __ARGS((char_u **fname, char_u **bufp, in
|
|||||||
static int shortpath_for_partial __ARGS((char_u **fnamep, char_u **bufp, int *fnamelen));
|
static int shortpath_for_partial __ARGS((char_u **fnamep, char_u **bufp, int *fnamelen));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the short pathname of a file.
|
* Get the short path (8.3) for the filename in "fnamep".
|
||||||
* Returns 1 on success. *fnamelen is 0 for nonexistent path.
|
* Only works for a valid file name.
|
||||||
|
* When the path gets longer "fnamep" is changed and the allocated buffer
|
||||||
|
* is put in "bufp".
|
||||||
|
* *fnamelen is the length of "fnamep" and set to 0 for a nonexistent path.
|
||||||
|
* Returns OK on success, FAIL on failure.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
get_short_pathname(fnamep, bufp, fnamelen)
|
get_short_pathname(fnamep, bufp, fnamelen)
|
||||||
@@ -21077,36 +21081,44 @@ get_short_pathname(fnamep, bufp, fnamelen)
|
|||||||
char_u **bufp;
|
char_u **bufp;
|
||||||
int *fnamelen;
|
int *fnamelen;
|
||||||
{
|
{
|
||||||
int l,len;
|
int l, len;
|
||||||
char_u *newbuf;
|
char_u *newbuf;
|
||||||
|
|
||||||
len = *fnamelen;
|
len = *fnamelen;
|
||||||
|
|
||||||
l = GetShortPathName(*fnamep, *fnamep, len);
|
l = GetShortPathName(*fnamep, *fnamep, len);
|
||||||
if (l > len - 1)
|
if (l > len - 1)
|
||||||
{
|
{
|
||||||
/* If that doesn't work (not enough space), then save the string
|
/* If that doesn't work (not enough space), then save the string
|
||||||
* and try again with a new buffer big enough
|
* and try again with a new buffer big enough. */
|
||||||
*/
|
|
||||||
newbuf = vim_strnsave(*fnamep, l);
|
newbuf = vim_strnsave(*fnamep, l);
|
||||||
if (newbuf == NULL)
|
if (newbuf == NULL)
|
||||||
return 0;
|
return FAIL;
|
||||||
|
|
||||||
vim_free(*bufp);
|
vim_free(*bufp);
|
||||||
*fnamep = *bufp = newbuf;
|
*fnamep = *bufp = newbuf;
|
||||||
|
|
||||||
l = GetShortPathName(*fnamep,*fnamep,l+1);
|
/* Really should always succeed, as the buffer is big enough. */
|
||||||
|
l = GetShortPathName(*fnamep, *fnamep, l+1);
|
||||||
/* Really should always succeed, as the buffer is big enough */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*fnamelen = l;
|
*fnamelen = l;
|
||||||
return 1;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a short path name. Returns the length of the buffer it needs.
|
* Get the short path (8.3) for the filename in "fname". The converted
|
||||||
* Doesn't copy over the end of the buffer passed in.
|
* path is returned in "bufp".
|
||||||
|
*
|
||||||
|
* Some of the directories specified in "fname" may not exist. This function
|
||||||
|
* will shorten the existing directories at the beginning of the path and then
|
||||||
|
* append the remaining non-existing path.
|
||||||
|
*
|
||||||
|
* fname - Pointer to the filename to shorten. On return, contains the
|
||||||
|
* pointer to the shortened pathname
|
||||||
|
* bufp - Pointer to an allocated buffer for the filename.
|
||||||
|
* fnamelen - Length of the filename pointed to by fname
|
||||||
|
*
|
||||||
|
* Returns OK on success (or nothing done) and FAIL on failure (out of memory).
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
shortpath_for_invalid_fname(fname, bufp, fnamelen)
|
shortpath_for_invalid_fname(fname, bufp, fnamelen)
|
||||||
@@ -21114,85 +21126,106 @@ shortpath_for_invalid_fname(fname, bufp, fnamelen)
|
|||||||
char_u **bufp;
|
char_u **bufp;
|
||||||
int *fnamelen;
|
int *fnamelen;
|
||||||
{
|
{
|
||||||
char_u *s, *p, *pbuf2, *pbuf3;
|
char_u *short_fname, *save_fname, *pbuf_unused;
|
||||||
|
char_u *endp, *save_endp;
|
||||||
char_u ch;
|
char_u ch;
|
||||||
int len, len2, plen, slen;
|
int old_len, len;
|
||||||
|
int new_len, sfx_len;
|
||||||
|
int retval = OK;
|
||||||
|
|
||||||
/* Make a copy */
|
/* Make a copy */
|
||||||
len2 = *fnamelen;
|
old_len = *fnamelen;
|
||||||
pbuf2 = vim_strnsave(*fname, len2);
|
save_fname = vim_strnsave(*fname, old_len);
|
||||||
pbuf3 = NULL;
|
pbuf_unused = NULL;
|
||||||
|
short_fname = NULL;
|
||||||
|
|
||||||
s = pbuf2 + len2 - 1; /* Find the end */
|
endp = save_fname + old_len - 1; /* Find the end of the copy */
|
||||||
slen = 1;
|
save_endp = endp;
|
||||||
plen = len2;
|
|
||||||
|
|
||||||
if (after_pathsep(pbuf2, s + 1))
|
/*
|
||||||
|
* Try shortening the supplied path till it succeeds by removing one
|
||||||
|
* directory at a time from the tail of the path.
|
||||||
|
*/
|
||||||
|
len = 0;
|
||||||
|
for (;;)
|
||||||
{
|
{
|
||||||
--s;
|
/* go back one path-separator */
|
||||||
++slen;
|
while (endp > save_fname && !after_pathsep(save_fname, endp + 1))
|
||||||
--plen;
|
--endp;
|
||||||
|
if (endp <= save_fname)
|
||||||
|
break; /* processed the complete path */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Replace the path separator with a NUL and try to shorten the
|
||||||
|
* resulting path.
|
||||||
|
*/
|
||||||
|
ch = *endp;
|
||||||
|
*endp = 0;
|
||||||
|
short_fname = save_fname;
|
||||||
|
len = STRLEN(short_fname) + 1;
|
||||||
|
if (get_short_pathname(&short_fname, &pbuf_unused, &len) == FAIL)
|
||||||
|
{
|
||||||
|
retval = FAIL;
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
|
*endp = ch; /* preserve the string */
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
break; /* successfully shortened the path */
|
||||||
|
|
||||||
|
/* failed to shorten the path. Skip the path separator */
|
||||||
|
--endp;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
if (len > 0)
|
||||||
{
|
{
|
||||||
/* Go back one path-separator */
|
/*
|
||||||
while (s > pbuf2 && !after_pathsep(pbuf2, s + 1))
|
* Succeeded in shortening the path. Now concatenate the shortened
|
||||||
{
|
* path with the remaining path at the tail.
|
||||||
--s;
|
*/
|
||||||
++slen;
|
|
||||||
--plen;
|
|
||||||
}
|
|
||||||
if (s <= pbuf2)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Remember the character that is about to be splatted */
|
/* Compute the length of the new path. */
|
||||||
ch = *s;
|
sfx_len = (int)(save_endp - endp) + 1;
|
||||||
*s = 0; /* get_short_pathname requires a null-terminated string */
|
new_len = len + sfx_len;
|
||||||
|
|
||||||
/* Try it in situ */
|
*fnamelen = new_len;
|
||||||
p = pbuf2;
|
|
||||||
if (!get_short_pathname(&p, &pbuf3, &plen))
|
|
||||||
{
|
|
||||||
vim_free(pbuf2);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*s = ch; /* Preserve the string */
|
|
||||||
} while (plen == 0);
|
|
||||||
|
|
||||||
if (plen > 0)
|
|
||||||
{
|
|
||||||
/* Remember the length of the new string. */
|
|
||||||
*fnamelen = len = plen + slen;
|
|
||||||
vim_free(*bufp);
|
vim_free(*bufp);
|
||||||
if (len > len2)
|
if (new_len > old_len)
|
||||||
{
|
{
|
||||||
/* If there's not enough space in the currently allocated string,
|
/* There is not enough space in the currently allocated string,
|
||||||
* then copy it to a buffer big enough.
|
* copy it to a buffer big enough. */
|
||||||
*/
|
*fname = *bufp = vim_strnsave(short_fname, new_len);
|
||||||
*fname= *bufp = vim_strnsave(p, len);
|
|
||||||
if (*fname == NULL)
|
if (*fname == NULL)
|
||||||
return -1;
|
{
|
||||||
|
retval = FAIL;
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Transfer pbuf2 to being the main buffer (it's big enough) */
|
/* Transfer short_fname to the main buffer (it's big enough),
|
||||||
*fname = *bufp = pbuf2;
|
* unless get_short_pathname() did its work in-place. */
|
||||||
if (p != pbuf2)
|
*fname = *bufp = save_fname;
|
||||||
strncpy(*fname, p, plen);
|
if (short_fname != save_fname)
|
||||||
pbuf2 = NULL;
|
vim_strncpy(save_fname, short_fname, len);
|
||||||
|
save_fname = NULL;
|
||||||
}
|
}
|
||||||
/* Concat the next bit */
|
|
||||||
strncpy(*fname + plen, s, slen);
|
/* concat the not-shortened part of the path */
|
||||||
(*fname)[len] = '\0';
|
vim_strncpy(*fname + len, endp, sfx_len);
|
||||||
|
(*fname)[new_len] = NUL;
|
||||||
}
|
}
|
||||||
vim_free(pbuf3);
|
|
||||||
vim_free(pbuf2);
|
theend:
|
||||||
return 0;
|
vim_free(pbuf_unused);
|
||||||
|
vim_free(save_fname);
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a pathname for a partial path.
|
* Get a pathname for a partial path.
|
||||||
|
* Returns OK for success, FAIL for failure.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
shortpath_for_partial(fnamep, bufp, fnamelen)
|
shortpath_for_partial(fnamep, bufp, fnamelen)
|
||||||
@@ -21222,8 +21255,8 @@ shortpath_for_partial(fnamep, bufp, fnamelen)
|
|||||||
|
|
||||||
len = tflen = (int)STRLEN(tfname);
|
len = tflen = (int)STRLEN(tfname);
|
||||||
|
|
||||||
if (!get_short_pathname(&tfname, &pbuf, &len))
|
if (get_short_pathname(&tfname, &pbuf, &len) == FAIL)
|
||||||
return -1;
|
return FAIL;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
@@ -21232,8 +21265,8 @@ shortpath_for_partial(fnamep, bufp, fnamelen)
|
|||||||
* there's not a lot of point in guessing what it might be.
|
* there's not a lot of point in guessing what it might be.
|
||||||
*/
|
*/
|
||||||
len = tflen;
|
len = tflen;
|
||||||
if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == -1)
|
if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == FAIL)
|
||||||
return -1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count the paths backward to find the beginning of the desired string. */
|
/* Count the paths backward to find the beginning of the desired string. */
|
||||||
@@ -21257,7 +21290,7 @@ shortpath_for_partial(fnamep, bufp, fnamelen)
|
|||||||
if (p >= tfname)
|
if (p >= tfname)
|
||||||
*p = '~';
|
*p = '~';
|
||||||
else
|
else
|
||||||
return -1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
++p;
|
++p;
|
||||||
@@ -21268,7 +21301,7 @@ shortpath_for_partial(fnamep, bufp, fnamelen)
|
|||||||
*bufp = pbuf;
|
*bufp = pbuf;
|
||||||
*fnamep = p;
|
*fnamep = p;
|
||||||
|
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
#endif /* WIN3264 */
|
#endif /* WIN3264 */
|
||||||
|
|
||||||
@@ -21276,7 +21309,7 @@ shortpath_for_partial(fnamep, bufp, fnamelen)
|
|||||||
* Adjust a filename, according to a string of modifiers.
|
* Adjust a filename, according to a string of modifiers.
|
||||||
* *fnamep must be NUL terminated when called. When returning, the length is
|
* *fnamep must be NUL terminated when called. When returning, the length is
|
||||||
* determined by *fnamelen.
|
* determined by *fnamelen.
|
||||||
* Returns valid flags.
|
* Returns VALID_ flags or -1 for failure.
|
||||||
* When there is an error, *fnamep is set to NULL.
|
* When there is an error, *fnamep is set to NULL.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -21488,7 +21521,7 @@ repeat:
|
|||||||
*/
|
*/
|
||||||
if (!has_fullname && !vim_isAbsName(*fnamep))
|
if (!has_fullname && !vim_isAbsName(*fnamep))
|
||||||
{
|
{
|
||||||
if (shortpath_for_partial(fnamep, bufp, fnamelen) == -1)
|
if (shortpath_for_partial(fnamep, bufp, fnamelen) == FAIL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -21498,7 +21531,7 @@ repeat:
|
|||||||
/* Simple case, already have the full-name
|
/* Simple case, already have the full-name
|
||||||
* Nearly always shorter, so try first time. */
|
* Nearly always shorter, so try first time. */
|
||||||
l = *fnamelen;
|
l = *fnamelen;
|
||||||
if (!get_short_pathname(fnamep, bufp, &l))
|
if (get_short_pathname(fnamep, bufp, &l) == FAIL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (l == 0)
|
if (l == 0)
|
||||||
@@ -21506,7 +21539,7 @@ repeat:
|
|||||||
/* Couldn't find the filename.. search the paths.
|
/* Couldn't find the filename.. search the paths.
|
||||||
*/
|
*/
|
||||||
l = *fnamelen;
|
l = *fnamelen;
|
||||||
if (shortpath_for_invalid_fname(fnamep, bufp, &l ) == -1)
|
if (shortpath_for_invalid_fname(fnamep, bufp, &l) == FAIL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*fnamelen = l;
|
*fnamelen = l;
|
||||||
|
@@ -666,6 +666,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
304,
|
||||||
/**/
|
/**/
|
||||||
303,
|
303,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user