Mercurial > vim
comparison src/misc1.c @ 2549:c210e31a2ec5 vim73
More fixes for :find completion. (mostly by Nazri Ramliy)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 13 Aug 2010 13:36:15 +0200 |
parents | 7a547db7070d |
children | 7850c8c12347 |
comparison
equal
deleted
inserted
replaced
2548:0bb74f626ba7 | 2549:c210e31a2ec5 |
---|---|
4409 #endif | 4409 #endif |
4410 } | 4410 } |
4411 | 4411 |
4412 /* | 4412 /* |
4413 * Get the tail of a path: the file name. | 4413 * Get the tail of a path: the file name. |
4414 * When the path ends in a path separator the tail is the NUL after it. | |
4414 * Fail safe: never returns NULL. | 4415 * Fail safe: never returns NULL. |
4415 */ | 4416 */ |
4416 char_u * | 4417 char_u * |
4417 gettail(fname) | 4418 gettail(fname) |
4418 char_u *fname; | 4419 char_u *fname; |
4427 p1 = p2 + 1; | 4428 p1 = p2 + 1; |
4428 mb_ptr_adv(p2); | 4429 mb_ptr_adv(p2); |
4429 } | 4430 } |
4430 return p1; | 4431 return p1; |
4431 } | 4432 } |
4433 | |
4434 #if defined(FEAT_SEARCHPATH) | |
4435 static char_u *gettail_dir __ARGS((char_u *fname)); | |
4436 | |
4437 /* | |
4438 * Return the end of the directory name, on the first path | |
4439 * separator: | |
4440 * "/path/file", "/path/dir/", "/path//dir", "/file" | |
4441 * ^ ^ ^ ^ | |
4442 */ | |
4443 static char_u * | |
4444 gettail_dir(fname) | |
4445 char_u *fname; | |
4446 { | |
4447 char_u *dir_end = fname; | |
4448 char_u *next_dir_end = fname; | |
4449 int look_for_sep = TRUE; | |
4450 char_u *p; | |
4451 | |
4452 for (p = fname; *p != NUL; ) | |
4453 { | |
4454 if (vim_ispathsep(*p)) | |
4455 { | |
4456 if (look_for_sep) | |
4457 { | |
4458 next_dir_end = p; | |
4459 look_for_sep = FALSE; | |
4460 } | |
4461 } | |
4462 else | |
4463 { | |
4464 if (!look_for_sep) | |
4465 dir_end = next_dir_end; | |
4466 look_for_sep = TRUE; | |
4467 } | |
4468 mb_ptr_adv(p); | |
4469 } | |
4470 return dir_end; | |
4471 } | |
4472 #endif | |
4432 | 4473 |
4433 /* | 4474 /* |
4434 * Get pointer to tail of "fname", including path separators. Putting a NUL | 4475 * Get pointer to tail of "fname", including path separators. Putting a NUL |
4435 * here leaves the directory name. Takes care of "c:/" and "//". | 4476 * here leaves the directory name. Takes care of "c:/" and "//". |
4436 * Always returns a valid pointer. | 4477 * Always returns a valid pointer. |
9386 } | 9427 } |
9387 } | 9428 } |
9388 | 9429 |
9389 /* Skip to the file or directory name */ | 9430 /* Skip to the file or directory name */ |
9390 if (cutoff != NULL) | 9431 if (cutoff != NULL) |
9391 while ( | 9432 while (vim_ispathsep(*cutoff)) |
9392 # if defined(MSWIN) || defined(MSDOS) | |
9393 *cutoff == '/' | |
9394 #else | |
9395 vim_ispathsep(*cutoff) | |
9396 #endif | |
9397 ) | |
9398 mb_ptr_adv(cutoff); | 9433 mb_ptr_adv(cutoff); |
9399 | 9434 |
9400 return cutoff; | 9435 return cutoff; |
9401 } | 9436 } |
9402 | 9437 |
9463 | 9498 |
9464 for (i = 0; i < gap->ga_len; i++) | 9499 for (i = 0; i < gap->ga_len; i++) |
9465 { | 9500 { |
9466 char_u *path = fnames[i]; | 9501 char_u *path = fnames[i]; |
9467 int is_in_curdir; | 9502 int is_in_curdir; |
9468 char_u *dir_end = gettail(path); | 9503 char_u *dir_end = gettail_dir(path); |
9469 char_u *pathsep_p; | 9504 char_u *pathsep_p; |
9470 char_u *path_cutoff; | 9505 char_u *path_cutoff; |
9471 | 9506 |
9472 len = (int)STRLEN(path); | 9507 len = (int)STRLEN(path); |
9473 while (dir_end > path && | |
9474 # if defined(MSWIN) || defined(MSDOS) | |
9475 *dir_end != '/' | |
9476 #else | |
9477 !vim_ispathsep(*dir_end) | |
9478 #endif | |
9479 ) | |
9480 mb_ptr_back(path, dir_end); | |
9481 is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0 | 9508 is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0 |
9482 && curdir[dir_end - path] == NUL; | 9509 && curdir[dir_end - path] == NUL; |
9483 | 9510 |
9484 if (is_in_curdir) | 9511 if (is_in_curdir) |
9485 in_curdir[i] = vim_strsave(path); | 9512 in_curdir[i] = vim_strsave(path); |
9515 * c:\foo\bar\file.txt c:\foo\bar .\file.txt | 9542 * c:\foo\bar\file.txt c:\foo\bar .\file.txt |
9516 * /file.txt / /file.txt | 9543 * /file.txt / /file.txt |
9517 * c:\file.txt c:\ .\file.txt | 9544 * c:\file.txt c:\ .\file.txt |
9518 */ | 9545 */ |
9519 short_name = shorten_fname(path, curdir); | 9546 short_name = shorten_fname(path, curdir); |
9520 if (short_name != NULL && short_name > path + 1) | 9547 if (short_name != NULL && short_name > path + 1 |
9548 #if defined(MSWIN) || defined(MSDOS) | |
9549 /* | |
9550 * On windows, | |
9551 * | |
9552 * shorten_fname("c:\a\a.txt", "c:\a\b") | |
9553 * | |
9554 * returns "\a\a.txt", which is not really the short | |
9555 * name, hence: | |
9556 */ | |
9557 && !vim_ispathsep(*short_name) | |
9558 #endif | |
9559 ) | |
9521 { | 9560 { |
9522 STRCPY(path, "."); | 9561 STRCPY(path, "."); |
9523 add_pathsep(path); | 9562 add_pathsep(path); |
9524 STRCAT(path, short_name); | 9563 STRCAT(path, short_name); |
9525 } | 9564 } |
9533 char_u *path = in_curdir[i]; | 9572 char_u *path = in_curdir[i]; |
9534 | 9573 |
9535 if (path == NULL) | 9574 if (path == NULL) |
9536 continue; | 9575 continue; |
9537 /* | 9576 /* |
9538 * If the file is in the current directory, | 9577 * If the {filename} is not unique, |
9539 * and it is not unique, | |
9540 * reduce it to ./{filename} | 9578 * reduce it to ./{filename} |
9541 * FIXME ^ Is this portable? | 9579 * FIXME ^ Is this portable? |
9542 * else reduce it to {filename} | 9580 * else reduce it to {filename} |
9543 * | |
9544 * Note: If the full filename is /curdir/foo/bar/{filename}, we don't | |
9545 * want to shorten it to ./foo/bar/{filename} yet because 'path' might | |
9546 * contain ". / * *", in which case the shortened filename could be | |
9547 * shorter than ./foo/bar/{filename}. | |
9548 */ | 9581 */ |
9549 short_name = shorten_fname(path, curdir); | 9582 short_name = shorten_fname(path, curdir); |
9550 if (short_name == NULL) | 9583 if (short_name == NULL) |
9551 short_name = path; | 9584 short_name = path; |
9552 if (is_unique(short_name, gap, i)) | 9585 if (is_unique(short_name, gap, i)) |
9824 addfile(&ga, t, flags); | 9857 addfile(&ga, t, flags); |
9825 vim_free(t); | 9858 vim_free(t); |
9826 } | 9859 } |
9827 | 9860 |
9828 #if defined(FEAT_SEARCHPATH) | 9861 #if defined(FEAT_SEARCHPATH) |
9829 if (flags & EW_PATH) | 9862 if (ga.ga_len > 0 && (flags & EW_PATH)) |
9830 uniquefy_paths(&ga, p); | 9863 uniquefy_paths(&ga, p); |
9831 #endif | 9864 #endif |
9832 if (p != pat[i]) | 9865 if (p != pat[i]) |
9833 vim_free(p); | 9866 vim_free(p); |
9834 } | 9867 } |