4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Shortpath_for_invalid_fname() does not work correctly and is
13 Solution: Clean up shortpath_for_invalid_fname(). (mostly by Yegappan
18 *** ../vim-7.1.303/src/eval.c Wed May 28 16:48:01 2008
19 --- src/eval.c Wed May 28 16:35:51 2008
22 static int shortpath_for_partial __ARGS((char_u **fnamep, char_u **bufp, int *fnamelen));
25 ! * Get the short pathname of a file.
26 ! * Returns 1 on success. *fnamelen is 0 for nonexistent path.
29 get_short_pathname(fnamep, bufp, fnamelen)
31 static int shortpath_for_partial __ARGS((char_u **fnamep, char_u **bufp, int *fnamelen));
34 ! * Get the short path (8.3) for the filename in "fnamep".
35 ! * Only works for a valid file name.
36 ! * When the path gets longer "fnamep" is changed and the allocated buffer
38 ! * *fnamelen is the length of "fnamep" and set to 0 for a nonexistent path.
39 ! * Returns OK on success, FAIL on failure.
42 get_short_pathname(fnamep, bufp, fnamelen)
53 l = GetShortPathName(*fnamep, *fnamep, len);
56 /* If that doesn't work (not enough space), then save the string
57 ! * and try again with a new buffer big enough
59 newbuf = vim_strnsave(*fnamep, l);
64 *fnamep = *bufp = newbuf;
66 ! l = GetShortPathName(*fnamep,*fnamep,l+1);
68 ! /* Really should always succeed, as the buffer is big enough */
76 ! * Create a short path name. Returns the length of the buffer it needs.
77 ! * Doesn't copy over the end of the buffer passed in.
80 shortpath_for_invalid_fname(fname, bufp, fnamelen)
89 l = GetShortPathName(*fnamep, *fnamep, len);
92 /* If that doesn't work (not enough space), then save the string
93 ! * and try again with a new buffer big enough. */
94 newbuf = vim_strnsave(*fnamep, l);
99 *fnamep = *bufp = newbuf;
101 ! /* Really should always succeed, as the buffer is big enough. */
102 ! l = GetShortPathName(*fnamep, *fnamep, l+1);
110 ! * Get the short path (8.3) for the filename in "fname". The converted
111 ! * path is returned in "bufp".
113 ! * Some of the directories specified in "fname" may not exist. This function
114 ! * will shorten the existing directories at the beginning of the path and then
115 ! * append the remaining non-existing path.
117 ! * fname - Pointer to the filename to shorten. On return, contains the
118 ! * pointer to the shortened pathname
119 ! * bufp - Pointer to an allocated buffer for the filename.
120 ! * fnamelen - Length of the filename pointed to by fname
122 ! * Returns OK on success (or nothing done) and FAIL on failure (out of memory).
125 shortpath_for_invalid_fname(fname, bufp, fnamelen)
131 ! char_u *s, *p, *pbuf2, *pbuf3;
133 ! int len, len2, plen, slen;
137 ! pbuf2 = vim_strnsave(*fname, len2);
140 ! s = pbuf2 + len2 - 1; /* Find the end */
144 ! if (after_pathsep(pbuf2, s + 1))
153 ! /* Go back one path-separator */
154 ! while (s > pbuf2 && !after_pathsep(pbuf2, s + 1))
163 ! /* Remember the character that is about to be splatted */
165 ! *s = 0; /* get_short_pathname requires a null-terminated string */
167 ! /* Try it in situ */
169 ! if (!get_short_pathname(&p, &pbuf3, &plen))
174 ! *s = ch; /* Preserve the string */
175 ! } while (plen == 0);
179 ! /* Remember the length of the new string. */
180 ! *fnamelen = len = plen + slen;
184 ! /* If there's not enough space in the currently allocated string,
185 ! * then copy it to a buffer big enough.
187 ! *fname= *bufp = vim_strnsave(p, len);
193 ! /* Transfer pbuf2 to being the main buffer (it's big enough) */
194 ! *fname = *bufp = pbuf2;
196 ! strncpy(*fname, p, plen);
199 ! /* Concat the next bit */
200 ! strncpy(*fname + plen, s, slen);
201 ! (*fname)[len] = '\0';
209 * Get a pathname for a partial path.
212 shortpath_for_partial(fnamep, bufp, fnamelen)
217 ! char_u *short_fname, *save_fname, *pbuf_unused;
218 ! char_u *endp, *save_endp;
221 ! int new_len, sfx_len;
225 ! old_len = *fnamelen;
226 ! save_fname = vim_strnsave(*fname, old_len);
227 ! pbuf_unused = NULL;
228 ! short_fname = NULL;
230 ! endp = save_fname + old_len - 1; /* Find the end of the copy */
234 ! * Try shortening the supplied path till it succeeds by removing one
235 ! * directory at a time from the tail of the path.
240 ! /* go back one path-separator */
241 ! while (endp > save_fname && !after_pathsep(save_fname, endp + 1))
243 ! if (endp <= save_fname)
244 ! break; /* processed the complete path */
247 ! * Replace the path separator with a NUL and try to shorten the
252 ! short_fname = save_fname;
253 ! len = STRLEN(short_fname) + 1;
254 ! if (get_short_pathname(&short_fname, &pbuf_unused, &len) == FAIL)
259 ! *endp = ch; /* preserve the string */
262 ! break; /* successfully shortened the path */
264 ! /* failed to shorten the path. Skip the path separator */
271 ! * Succeeded in shortening the path. Now concatenate the shortened
272 ! * path with the remaining path at the tail.
275 ! /* Compute the length of the new path. */
276 ! sfx_len = (int)(save_endp - endp) + 1;
277 ! new_len = len + sfx_len;
279 ! *fnamelen = new_len;
281 ! if (new_len > old_len)
283 ! /* There is not enough space in the currently allocated string,
284 ! * copy it to a buffer big enough. */
285 ! *fname = *bufp = vim_strnsave(short_fname, new_len);
294 ! /* Transfer short_fname to the main buffer (it's big enough),
295 ! * unless get_short_pathname() did its work in-place. */
296 ! *fname = *bufp = save_fname;
297 ! if (short_fname != save_fname)
298 ! vim_strncpy(save_fname, short_fname, len);
302 ! /* concat the not-shortened part of the path */
303 ! vim_strncpy(*fname + len, endp, sfx_len);
304 ! (*fname)[new_len] = NUL;
308 ! vim_free(pbuf_unused);
309 ! vim_free(save_fname);
315 * Get a pathname for a partial path.
316 + * Returns OK for success, FAIL for failure.
319 shortpath_for_partial(fnamep, bufp, fnamelen)
323 len = tflen = (int)STRLEN(tfname);
325 ! if (!get_short_pathname(&tfname, &pbuf, &len))
332 len = tflen = (int)STRLEN(tfname);
334 ! if (get_short_pathname(&tfname, &pbuf, &len) == FAIL)
341 * there's not a lot of point in guessing what it might be.
344 ! if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == -1)
348 /* Count the paths backward to find the beginning of the desired string. */
350 * there's not a lot of point in guessing what it might be.
353 ! if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == FAIL)
357 /* Count the paths backward to find the beginning of the desired string. */
394 * Adjust a filename, according to a string of modifiers.
395 * *fnamep must be NUL terminated when called. When returning, the length is
396 * determined by *fnamelen.
397 ! * Returns valid flags.
398 * When there is an error, *fnamep is set to NULL.
402 * Adjust a filename, according to a string of modifiers.
403 * *fnamep must be NUL terminated when called. When returning, the length is
404 * determined by *fnamelen.
405 ! * Returns VALID_ flags or -1 for failure.
406 * When there is an error, *fnamep is set to NULL.
412 if (!has_fullname && !vim_isAbsName(*fnamep))
414 ! if (shortpath_for_partial(fnamep, bufp, fnamelen) == -1)
420 if (!has_fullname && !vim_isAbsName(*fnamep))
422 ! if (shortpath_for_partial(fnamep, bufp, fnamelen) == FAIL)
428 /* Simple case, already have the full-name
429 * Nearly always shorter, so try first time. */
431 ! if (!get_short_pathname(fnamep, bufp, &l))
436 /* Simple case, already have the full-name
437 * Nearly always shorter, so try first time. */
439 ! if (get_short_pathname(fnamep, bufp, &l) == FAIL)
445 /* Couldn't find the filename.. search the paths.
448 ! if (shortpath_for_invalid_fname(fnamep, bufp, &l ) == -1)
453 /* Couldn't find the filename.. search the paths.
456 ! if (shortpath_for_invalid_fname(fnamep, bufp, &l) == FAIL)
460 *** ../vim-7.1.303/src/version.c Thu May 29 15:33:13 2008
461 --- src/version.c Thu May 29 21:41:55 2008
465 { /* Add new patch number below this line */
471 "The future's already arrived - it's just not evenly distributed yet."
474 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
475 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
476 \\\ download, build and distribute -- http://www.A-A-P.org ///
477 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///