]> git.pld-linux.org Git - packages/vim.git/blame - 7.1.304
- new
[packages/vim.git] / 7.1.304
CommitLineData
60bfb38b
AG
1To: vim-dev@vim.org
2Subject: Patch 7.1.304
3Fcc: outbox
4From: Bram Moolenaar <Bram@moolenaar.net>
5Mime-Version: 1.0
6Content-Type: text/plain; charset=ISO-8859-1
7Content-Transfer-Encoding: 8bit
8------------
9
10Patch 7.1.304
11Problem: Shortpath_for_invalid_fname() does not work correctly and is
12 unnecessary complex.
13Solution: Clean up shortpath_for_invalid_fname(). (mostly by Yegappan
14 Lakshmanan)
15Files: src/eval.c
16
17
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
20***************
21*** 21068,21075 ****
22 static int shortpath_for_partial __ARGS((char_u **fnamep, char_u **bufp, int *fnamelen));
23
24 /*
25! * Get the short pathname of a file.
26! * Returns 1 on success. *fnamelen is 0 for nonexistent path.
27 */
28 static int
29 get_short_pathname(fnamep, bufp, fnamelen)
30--- 21476,21487 ----
31 static int shortpath_for_partial __ARGS((char_u **fnamep, char_u **bufp, int *fnamelen));
32
33 /*
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
37! * is put in "bufp".
38! * *fnamelen is the length of "fnamep" and set to 0 for a nonexistent path.
39! * Returns OK on success, FAIL on failure.
40 */
41 static int
42 get_short_pathname(fnamep, bufp, fnamelen)
43***************
44*** 21077,21112 ****
45 char_u **bufp;
46 int *fnamelen;
47 {
48! int l,len;
49 char_u *newbuf;
50
51 len = *fnamelen;
52-
53 l = GetShortPathName(*fnamep, *fnamep, len);
54 if (l > len - 1)
55 {
56 /* If that doesn't work (not enough space), then save the string
57! * and try again with a new buffer big enough
58! */
59 newbuf = vim_strnsave(*fnamep, l);
60 if (newbuf == NULL)
61! return 0;
62
63 vim_free(*bufp);
64 *fnamep = *bufp = newbuf;
65
66! l = GetShortPathName(*fnamep,*fnamep,l+1);
67!
68! /* Really should always succeed, as the buffer is big enough */
69 }
70
71 *fnamelen = l;
72! return 1;
73 }
74
75 /*
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.
78 */
79 static int
80 shortpath_for_invalid_fname(fname, bufp, fnamelen)
81--- 21489,21532 ----
82 char_u **bufp;
83 int *fnamelen;
84 {
85! int l, len;
86 char_u *newbuf;
87
88 len = *fnamelen;
89 l = GetShortPathName(*fnamep, *fnamep, len);
90 if (l > len - 1)
91 {
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);
95 if (newbuf == NULL)
96! return FAIL;
97
98 vim_free(*bufp);
99 *fnamep = *bufp = newbuf;
100
101! /* Really should always succeed, as the buffer is big enough. */
102! l = GetShortPathName(*fnamep, *fnamep, l+1);
103 }
104
105 *fnamelen = l;
106! return OK;
107 }
108
109 /*
110! * Get the short path (8.3) for the filename in "fname". The converted
111! * path is returned in "bufp".
112! *
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.
116! *
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
121! *
122! * Returns OK on success (or nothing done) and FAIL on failure (out of memory).
123 */
124 static int
125 shortpath_for_invalid_fname(fname, bufp, fnamelen)
126***************
127*** 21114,21198 ****
128 char_u **bufp;
129 int *fnamelen;
130 {
131! char_u *s, *p, *pbuf2, *pbuf3;
132 char_u ch;
133! int len, len2, plen, slen;
134
135 /* Make a copy */
136! len2 = *fnamelen;
137! pbuf2 = vim_strnsave(*fname, len2);
138! pbuf3 = NULL;
139!
140! s = pbuf2 + len2 - 1; /* Find the end */
141! slen = 1;
142! plen = len2;
143!
144! if (after_pathsep(pbuf2, s + 1))
145! {
146! --s;
147! ++slen;
148! --plen;
149! }
150
151! do
152 {
153! /* Go back one path-separator */
154! while (s > pbuf2 && !after_pathsep(pbuf2, s + 1))
155! {
156! --s;
157! ++slen;
158! --plen;
159! }
160! if (s <= pbuf2)
161! break;
162
163! /* Remember the character that is about to be splatted */
164! ch = *s;
165! *s = 0; /* get_short_pathname requires a null-terminated string */
166!
167! /* Try it in situ */
168! p = pbuf2;
169! if (!get_short_pathname(&p, &pbuf3, &plen))
170 {
171! vim_free(pbuf2);
172! return -1;
173 }
174! *s = ch; /* Preserve the string */
175! } while (plen == 0);
176
177! if (plen > 0)
178 {
179! /* Remember the length of the new string. */
180! *fnamelen = len = plen + slen;
181 vim_free(*bufp);
182! if (len > len2)
183 {
184! /* If there's not enough space in the currently allocated string,
185! * then copy it to a buffer big enough.
186! */
187! *fname= *bufp = vim_strnsave(p, len);
188 if (*fname == NULL)
189! return -1;
190 }
191 else
192 {
193! /* Transfer pbuf2 to being the main buffer (it's big enough) */
194! *fname = *bufp = pbuf2;
195! if (p != pbuf2)
196! strncpy(*fname, p, plen);
197! pbuf2 = NULL;
198! }
199! /* Concat the next bit */
200! strncpy(*fname + plen, s, slen);
201! (*fname)[len] = '\0';
202 }
203! vim_free(pbuf3);
204! vim_free(pbuf2);
205! return 0;
206 }
207
208 /*
209 * Get a pathname for a partial path.
210 */
211 static int
212 shortpath_for_partial(fnamep, bufp, fnamelen)
213--- 21534,21639 ----
214 char_u **bufp;
215 int *fnamelen;
216 {
217! char_u *short_fname, *save_fname, *pbuf_unused;
218! char_u *endp, *save_endp;
219 char_u ch;
220! int old_len, len;
221! int new_len, sfx_len;
222! int retval = OK;
223
224 /* Make a copy */
225! old_len = *fnamelen;
226! save_fname = vim_strnsave(*fname, old_len);
227! pbuf_unused = NULL;
228! short_fname = NULL;
229
230! endp = save_fname + old_len - 1; /* Find the end of the copy */
231! save_endp = endp;
232!
233! /*
234! * Try shortening the supplied path till it succeeds by removing one
235! * directory at a time from the tail of the path.
236! */
237! len = 0;
238! for (;;)
239 {
240! /* go back one path-separator */
241! while (endp > save_fname && !after_pathsep(save_fname, endp + 1))
242! --endp;
243! if (endp <= save_fname)
244! break; /* processed the complete path */
245
246! /*
247! * Replace the path separator with a NUL and try to shorten the
248! * resulting path.
249! */
250! ch = *endp;
251! *endp = 0;
252! short_fname = save_fname;
253! len = STRLEN(short_fname) + 1;
254! if (get_short_pathname(&short_fname, &pbuf_unused, &len) == FAIL)
255 {
256! retval = FAIL;
257! goto theend;
258 }
259! *endp = ch; /* preserve the string */
260!
261! if (len > 0)
262! break; /* successfully shortened the path */
263
264! /* failed to shorten the path. Skip the path separator */
265! --endp;
266! }
267!
268! if (len > 0)
269 {
270! /*
271! * Succeeded in shortening the path. Now concatenate the shortened
272! * path with the remaining path at the tail.
273! */
274!
275! /* Compute the length of the new path. */
276! sfx_len = (int)(save_endp - endp) + 1;
277! new_len = len + sfx_len;
278!
279! *fnamelen = new_len;
280 vim_free(*bufp);
281! if (new_len > old_len)
282 {
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);
286 if (*fname == NULL)
287! {
288! retval = FAIL;
289! goto theend;
290! }
291 }
292 else
293 {
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);
299! save_fname = NULL;
300! }
301!
302! /* concat the not-shortened part of the path */
303! vim_strncpy(*fname + len, endp, sfx_len);
304! (*fname)[new_len] = NUL;
305 }
306!
307! theend:
308! vim_free(pbuf_unused);
309! vim_free(save_fname);
310!
311! return retval;
312 }
313
314 /*
315 * Get a pathname for a partial path.
316+ * Returns OK for success, FAIL for failure.
317 */
318 static int
319 shortpath_for_partial(fnamep, bufp, fnamelen)
320***************
321*** 21222,21229 ****
322
323 len = tflen = (int)STRLEN(tfname);
324
325! if (!get_short_pathname(&tfname, &pbuf, &len))
326! return -1;
327
328 if (len == 0)
329 {
330--- 21663,21670 ----
331
332 len = tflen = (int)STRLEN(tfname);
333
334! if (get_short_pathname(&tfname, &pbuf, &len) == FAIL)
335! return FAIL;
336
337 if (len == 0)
338 {
339***************
340*** 21232,21239 ****
341 * there's not a lot of point in guessing what it might be.
342 */
343 len = tflen;
344! if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == -1)
345! return -1;
346 }
347
348 /* Count the paths backward to find the beginning of the desired string. */
349--- 21673,21680 ----
350 * there's not a lot of point in guessing what it might be.
351 */
352 len = tflen;
353! if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == FAIL)
354! return FAIL;
355 }
356
357 /* Count the paths backward to find the beginning of the desired string. */
358***************
359*** 21257,21263 ****
360 if (p >= tfname)
361 *p = '~';
362 else
363! return -1;
364 }
365 else
366 ++p;
367--- 21698,21704 ----
368 if (p >= tfname)
369 *p = '~';
370 else
371! return FAIL;
372 }
373 else
374 ++p;
375***************
376*** 21268,21274 ****
377 *bufp = pbuf;
378 *fnamep = p;
379
380! return 0;
381 }
382 #endif /* WIN3264 */
383
384--- 21709,21715 ----
385 *bufp = pbuf;
386 *fnamep = p;
387
388! return OK;
389 }
390 #endif /* WIN3264 */
391
392***************
393*** 21276,21282 ****
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.
399 */
400 int
401--- 21717,21723 ----
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.
407 */
408 int
409***************
410*** 21488,21494 ****
411 */
412 if (!has_fullname && !vim_isAbsName(*fnamep))
413 {
414! if (shortpath_for_partial(fnamep, bufp, fnamelen) == -1)
415 return -1;
416 }
417 else
418--- 21929,21935 ----
419 */
420 if (!has_fullname && !vim_isAbsName(*fnamep))
421 {
422! if (shortpath_for_partial(fnamep, bufp, fnamelen) == FAIL)
423 return -1;
424 }
425 else
426***************
427*** 21498,21504 ****
428 /* Simple case, already have the full-name
429 * Nearly always shorter, so try first time. */
430 l = *fnamelen;
431! if (!get_short_pathname(fnamep, bufp, &l))
432 return -1;
433
434 if (l == 0)
435--- 21939,21945 ----
436 /* Simple case, already have the full-name
437 * Nearly always shorter, so try first time. */
438 l = *fnamelen;
439! if (get_short_pathname(fnamep, bufp, &l) == FAIL)
440 return -1;
441
442 if (l == 0)
443***************
444*** 21506,21512 ****
445 /* Couldn't find the filename.. search the paths.
446 */
447 l = *fnamelen;
448! if (shortpath_for_invalid_fname(fnamep, bufp, &l ) == -1)
449 return -1;
450 }
451 *fnamelen = l;
452--- 21947,21953 ----
453 /* Couldn't find the filename.. search the paths.
454 */
455 l = *fnamelen;
456! if (shortpath_for_invalid_fname(fnamep, bufp, &l) == FAIL)
457 return -1;
458 }
459 *fnamelen = l;
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
462***************
463*** 668,669 ****
464--- 673,676 ----
465 { /* Add new patch number below this line */
466+ /**/
467+ 304,
468 /**/
469
470--
471"The future's already arrived - it's just not evenly distributed yet."
472 -- William Gibson
473
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 ///
This page took 0.070407 seconds and 4 git commands to generate.