Mercurial > vim
comparison src/findfile.c @ 29863:62350f19d4ed v9.0.0270
patch 9.0.0270: some values of 'path' and 'tags' invalid in the tiny version
Commit: https://github.com/vim/vim/commit/2bd9dbc19fc67395cfa1226dda7326071ab22464
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 25 18:12:06 2022 +0100
patch 9.0.0270: some values of 'path' and 'tags' invalid in the tiny version
Problem: Some values of 'path' and 'tags' do not work in the tiny version.
Solution: Graduate the +path_extra feature.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 25 Aug 2022 19:15:03 +0200 |
parents | 31c598083364 |
children | 58fb880f3607 |
comparison
equal
deleted
inserted
replaced
29862:ae8c7b51bb54 | 29863:62350f19d4ed |
---|---|
65 struct ff_stack *ffs_prev; | 65 struct ff_stack *ffs_prev; |
66 | 66 |
67 // the fix part (no wildcards) and the part containing the wildcards | 67 // the fix part (no wildcards) and the part containing the wildcards |
68 // of the search path | 68 // of the search path |
69 char_u *ffs_fix_path; | 69 char_u *ffs_fix_path; |
70 #ifdef FEAT_PATH_EXTRA | |
71 char_u *ffs_wc_path; | 70 char_u *ffs_wc_path; |
72 #endif | |
73 | 71 |
74 // files/dirs found in the above directory, matched by the first wildcard | 72 // files/dirs found in the above directory, matched by the first wildcard |
75 // of wc_part | 73 // of wc_part |
76 char_u **ffs_filearray; | 74 char_u **ffs_filearray; |
77 int ffs_filearray_size; | 75 int ffs_filearray_size; |
95 */ | 93 */ |
96 typedef struct ff_visited | 94 typedef struct ff_visited |
97 { | 95 { |
98 struct ff_visited *ffv_next; | 96 struct ff_visited *ffv_next; |
99 | 97 |
100 #ifdef FEAT_PATH_EXTRA | |
101 // Visited directories are different if the wildcard string are | 98 // Visited directories are different if the wildcard string are |
102 // different. So we have to save it. | 99 // different. So we have to save it. |
103 char_u *ffv_wc_path; | 100 char_u *ffv_wc_path; |
104 #endif | 101 |
105 // for unix use inode etc for comparison (needed because of links), else | 102 // for unix use inode etc for comparison (needed because of links), else |
106 // use filename. | 103 // use filename. |
107 #ifdef UNIX | 104 #ifdef UNIX |
108 int ffv_dev_valid; // ffv_dev and ffv_ino were set | 105 int ffv_dev_valid; // ffv_dev and ffv_ino were set |
109 dev_t ffv_dev; // device number | 106 dev_t ffv_dev; // device number |
171 ff_visited_list_hdr_T *ffsc_visited_lists_list; | 168 ff_visited_list_hdr_T *ffsc_visited_lists_list; |
172 ff_visited_list_hdr_T *ffsc_dir_visited_lists_list; | 169 ff_visited_list_hdr_T *ffsc_dir_visited_lists_list; |
173 char_u *ffsc_file_to_search; | 170 char_u *ffsc_file_to_search; |
174 char_u *ffsc_start_dir; | 171 char_u *ffsc_start_dir; |
175 char_u *ffsc_fix_path; | 172 char_u *ffsc_fix_path; |
176 #ifdef FEAT_PATH_EXTRA | |
177 char_u *ffsc_wc_path; | 173 char_u *ffsc_wc_path; |
178 int ffsc_level; | 174 int ffsc_level; |
179 char_u **ffsc_stopdirs_v; | 175 char_u **ffsc_stopdirs_v; |
180 #endif | |
181 int ffsc_find_what; | 176 int ffsc_find_what; |
182 int ffsc_tagfile; | 177 int ffsc_tagfile; |
183 } ff_search_ctx_T; | 178 } ff_search_ctx_T; |
184 | 179 |
185 // locally needed functions | 180 // locally needed functions |
186 #ifdef FEAT_PATH_EXTRA | |
187 static int ff_check_visited(ff_visited_T **, char_u *, char_u *); | 181 static int ff_check_visited(ff_visited_T **, char_u *, char_u *); |
188 #else | |
189 static int ff_check_visited(ff_visited_T **, char_u *); | |
190 #endif | |
191 static void vim_findfile_free_visited(void *search_ctx_arg); | 182 static void vim_findfile_free_visited(void *search_ctx_arg); |
192 static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp); | 183 static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp); |
193 static void ff_free_visited_list(ff_visited_T *vl); | 184 static void ff_free_visited_list(ff_visited_T *vl); |
194 static ff_visited_list_hdr_T* ff_get_visited_list(char_u *, ff_visited_list_hdr_T **list_headp); | 185 static ff_visited_list_hdr_T* ff_get_visited_list(char_u *, ff_visited_list_hdr_T **list_headp); |
195 | 186 |
196 static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr); | 187 static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr); |
197 static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx); | 188 static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx); |
198 static void ff_clear(ff_search_ctx_T *search_ctx); | 189 static void ff_clear(ff_search_ctx_T *search_ctx); |
199 static void ff_free_stack_element(ff_stack_T *stack_ptr); | 190 static void ff_free_stack_element(ff_stack_T *stack_ptr); |
200 #ifdef FEAT_PATH_EXTRA | |
201 static ff_stack_T *ff_create_stack_element(char_u *, char_u *, int, int); | 191 static ff_stack_T *ff_create_stack_element(char_u *, char_u *, int, int); |
202 #else | |
203 static ff_stack_T *ff_create_stack_element(char_u *, int, int); | |
204 #endif | |
205 #ifdef FEAT_PATH_EXTRA | |
206 static int ff_path_in_stoplist(char_u *, int, char_u **); | 192 static int ff_path_in_stoplist(char_u *, int, char_u **); |
207 #endif | |
208 | 193 |
209 static char_u *ff_expand_buffer = NULL; // used for expanding filenames | 194 static char_u *ff_expand_buffer = NULL; // used for expanding filenames |
210 | 195 |
211 #if 0 | 196 #if 0 |
212 /* | 197 /* |
304 int find_what, | 289 int find_what, |
305 void *search_ctx_arg, | 290 void *search_ctx_arg, |
306 int tagfile, // expanding names of tags files | 291 int tagfile, // expanding names of tags files |
307 char_u *rel_fname) // file name to use for "." | 292 char_u *rel_fname) // file name to use for "." |
308 { | 293 { |
309 #ifdef FEAT_PATH_EXTRA | |
310 char_u *wc_part; | 294 char_u *wc_part; |
311 #endif | |
312 ff_stack_T *sptr; | 295 ff_stack_T *sptr; |
313 ff_search_ctx_T *search_ctx; | 296 ff_search_ctx_T *search_ctx; |
314 | 297 |
315 // If a search context is given by the caller, reuse it, else allocate a | 298 // If a search context is given by the caller, reuse it, else allocate a |
316 // new one. | 299 // new one. |
407 && search_ctx->ffsc_start_dir[1] == ':') | 390 && search_ctx->ffsc_start_dir[1] == ':') |
408 search_ctx->ffsc_start_dir[2] = NUL; | 391 search_ctx->ffsc_start_dir[2] = NUL; |
409 #endif | 392 #endif |
410 } | 393 } |
411 | 394 |
412 #ifdef FEAT_PATH_EXTRA | |
413 /* | 395 /* |
414 * If stopdirs are given, split them into an array of pointers. | 396 * If stopdirs are given, split them into an array of pointers. |
415 * If this fails (mem allocation), there is no upward search at all or a | 397 * If this fails (mem allocation), there is no upward search at all or a |
416 * stop directory is not recognized -> continue silently. | 398 * stop directory is not recognized -> continue silently. |
417 * If stopdirs just contains a ";" or is empty, | 399 * If stopdirs just contains a ";" or is empty, |
462 | 444 |
463 } while (walker != NULL); | 445 } while (walker != NULL); |
464 search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; | 446 search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; |
465 } | 447 } |
466 } | 448 } |
467 #endif | 449 |
468 | |
469 #ifdef FEAT_PATH_EXTRA | |
470 search_ctx->ffsc_level = level; | 450 search_ctx->ffsc_level = level; |
471 | 451 |
472 /* | 452 /* |
473 * split into: | 453 * split into: |
474 * -fix path | 454 * -fix path |
529 | 509 |
530 if (search_ctx->ffsc_wc_path == NULL) | 510 if (search_ctx->ffsc_wc_path == NULL) |
531 goto error_return; | 511 goto error_return; |
532 } | 512 } |
533 else | 513 else |
534 #endif | |
535 search_ctx->ffsc_fix_path = vim_strsave(path); | 514 search_ctx->ffsc_fix_path = vim_strsave(path); |
536 | 515 |
537 if (search_ctx->ffsc_start_dir == NULL) | 516 if (search_ctx->ffsc_start_dir == NULL) |
538 { | 517 { |
539 // store the fix part as startdir. | 518 // store the fix part as startdir. |
563 if (mch_isdir(buf)) | 542 if (mch_isdir(buf)) |
564 { | 543 { |
565 STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); | 544 STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); |
566 add_pathsep(ff_expand_buffer); | 545 add_pathsep(ff_expand_buffer); |
567 } | 546 } |
568 #ifdef FEAT_PATH_EXTRA | |
569 else | 547 else |
570 { | 548 { |
571 char_u *p = gettail(search_ctx->ffsc_fix_path); | 549 char_u *p = gettail(search_ctx->ffsc_fix_path); |
572 char_u *wc_path = NULL; | 550 char_u *wc_path = NULL; |
573 char_u *temp = NULL; | 551 char_u *temp = NULL; |
610 vim_free(search_ctx->ffsc_wc_path); | 588 vim_free(search_ctx->ffsc_wc_path); |
611 vim_free(wc_path); | 589 vim_free(wc_path); |
612 search_ctx->ffsc_wc_path = temp; | 590 search_ctx->ffsc_wc_path = temp; |
613 } | 591 } |
614 } | 592 } |
615 #endif | |
616 vim_free(buf); | 593 vim_free(buf); |
617 } | 594 } |
618 | 595 |
619 sptr = ff_create_stack_element(ff_expand_buffer, | 596 sptr = ff_create_stack_element(ff_expand_buffer, |
620 #ifdef FEAT_PATH_EXTRA | 597 search_ctx->ffsc_wc_path, level, 0); |
621 search_ctx->ffsc_wc_path, | |
622 #endif | |
623 level, 0); | |
624 | 598 |
625 if (sptr == NULL) | 599 if (sptr == NULL) |
626 goto error_return; | 600 goto error_return; |
627 | 601 |
628 ff_push(search_ctx, sptr); | 602 ff_push(search_ctx, sptr); |
641 */ | 615 */ |
642 vim_findfile_cleanup(search_ctx); | 616 vim_findfile_cleanup(search_ctx); |
643 return NULL; | 617 return NULL; |
644 } | 618 } |
645 | 619 |
646 #if defined(FEAT_PATH_EXTRA) || defined(PROTO) | |
647 /* | 620 /* |
648 * Get the stopdir string. Check that ';' is not escaped. | 621 * Get the stopdir string. Check that ';' is not escaped. |
649 */ | 622 */ |
650 char_u * | 623 char_u * |
651 vim_findfile_stopdir(char_u *buf) | 624 vim_findfile_stopdir(char_u *buf) |
670 } | 643 } |
671 else if (*r_ptr == NUL) | 644 else if (*r_ptr == NUL) |
672 r_ptr = NULL; | 645 r_ptr = NULL; |
673 return r_ptr; | 646 return r_ptr; |
674 } | 647 } |
675 #endif | |
676 | 648 |
677 /* | 649 /* |
678 * Clean up the given search context. Can handle a NULL pointer. | 650 * Clean up the given search context. Can handle a NULL pointer. |
679 */ | 651 */ |
680 void | 652 void |
702 */ | 674 */ |
703 char_u * | 675 char_u * |
704 vim_findfile(void *search_ctx_arg) | 676 vim_findfile(void *search_ctx_arg) |
705 { | 677 { |
706 char_u *file_path; | 678 char_u *file_path; |
707 #ifdef FEAT_PATH_EXTRA | |
708 char_u *rest_of_wildcards; | 679 char_u *rest_of_wildcards; |
709 char_u *path_end = NULL; | 680 char_u *path_end = NULL; |
710 #endif | |
711 ff_stack_T *stackp; | 681 ff_stack_T *stackp; |
712 int len; | 682 int len; |
713 int i; | 683 int i; |
714 char_u *p; | 684 char_u *p; |
715 char_u *suf; | 685 char_u *suf; |
725 * return a found filename. | 695 * return a found filename. |
726 */ | 696 */ |
727 if ((file_path = alloc(MAXPATHL)) == NULL) | 697 if ((file_path = alloc(MAXPATHL)) == NULL) |
728 return NULL; | 698 return NULL; |
729 | 699 |
730 #ifdef FEAT_PATH_EXTRA | |
731 // store the end of the start dir -- needed for upward search | 700 // store the end of the start dir -- needed for upward search |
732 if (search_ctx->ffsc_start_dir != NULL) | 701 if (search_ctx->ffsc_start_dir != NULL) |
733 path_end = &search_ctx->ffsc_start_dir[ | 702 path_end = &search_ctx->ffsc_start_dir[ |
734 STRLEN(search_ctx->ffsc_start_dir)]; | 703 STRLEN(search_ctx->ffsc_start_dir)]; |
735 #endif | 704 |
736 | |
737 #ifdef FEAT_PATH_EXTRA | |
738 // upward search loop | 705 // upward search loop |
739 for (;;) | 706 for (;;) |
740 { | 707 { |
741 #endif | |
742 // downward search loop | 708 // downward search loop |
743 for (;;) | 709 for (;;) |
744 { | 710 { |
745 // check if user wants to stop the search | 711 // check if user wants to stop the search |
746 ui_breakcheck(); | 712 ui_breakcheck(); |
772 * first time (hence stackp->ff_filearray == NULL) | 738 * first time (hence stackp->ff_filearray == NULL) |
773 */ | 739 */ |
774 if (stackp->ffs_filearray == NULL | 740 if (stackp->ffs_filearray == NULL |
775 && ff_check_visited(&search_ctx->ffsc_dir_visited_list | 741 && ff_check_visited(&search_ctx->ffsc_dir_visited_list |
776 ->ffvl_visited_list, | 742 ->ffvl_visited_list, |
777 stackp->ffs_fix_path | 743 stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) |
778 #ifdef FEAT_PATH_EXTRA | |
779 , stackp->ffs_wc_path | |
780 #endif | |
781 ) == FAIL) | |
782 { | 744 { |
783 #ifdef FF_VERBOSE | 745 #ifdef FF_VERBOSE |
784 if (p_verbose >= 5) | 746 if (p_verbose >= 5) |
785 { | 747 { |
786 verbose_enter_scroll(); | 748 verbose_enter_scroll(); |
857 { | 819 { |
858 ff_free_stack_element(stackp); | 820 ff_free_stack_element(stackp); |
859 goto fail; | 821 goto fail; |
860 } | 822 } |
861 | 823 |
862 #ifdef FEAT_PATH_EXTRA | |
863 rest_of_wildcards = stackp->ffs_wc_path; | 824 rest_of_wildcards = stackp->ffs_wc_path; |
864 if (*rest_of_wildcards != NUL) | 825 if (*rest_of_wildcards != NUL) |
865 { | 826 { |
866 len = (int)STRLEN(file_path); | 827 len = (int)STRLEN(file_path); |
867 if (STRNCMP(rest_of_wildcards, "**", 2) == 0) | 828 if (STRNCMP(rest_of_wildcards, "**", 2) == 0) |
917 | 878 |
918 file_path[len] = NUL; | 879 file_path[len] = NUL; |
919 if (vim_ispathsep(*rest_of_wildcards)) | 880 if (vim_ispathsep(*rest_of_wildcards)) |
920 rest_of_wildcards++; | 881 rest_of_wildcards++; |
921 } | 882 } |
922 #endif | |
923 | 883 |
924 /* | 884 /* |
925 * Expand wildcards like "*" and "$VAR". | 885 * Expand wildcards like "*" and "$VAR". |
926 * If the path is a URL don't try this. | 886 * If the path is a URL don't try this. |
927 */ | 887 */ |
945 EW_DIR|EW_ADDSLASH|EW_SILENT|EW_NOTWILD); | 905 EW_DIR|EW_ADDSLASH|EW_SILENT|EW_NOTWILD); |
946 | 906 |
947 stackp->ffs_filearray_cur = 0; | 907 stackp->ffs_filearray_cur = 0; |
948 stackp->ffs_stage = 0; | 908 stackp->ffs_stage = 0; |
949 } | 909 } |
950 #ifdef FEAT_PATH_EXTRA | |
951 else | 910 else |
952 rest_of_wildcards = &stackp->ffs_wc_path[ | 911 rest_of_wildcards = &stackp->ffs_wc_path[ |
953 STRLEN(stackp->ffs_wc_path)]; | 912 STRLEN(stackp->ffs_wc_path)]; |
954 #endif | |
955 | 913 |
956 if (stackp->ffs_stage == 0) | 914 if (stackp->ffs_stage == 0) |
957 { | 915 { |
958 // this is the first time we work on this directory | 916 // this is the first time we work on this directory |
959 #ifdef FEAT_PATH_EXTRA | |
960 if (*rest_of_wildcards == NUL) | 917 if (*rest_of_wildcards == NUL) |
961 #endif | |
962 { | 918 { |
963 /* | 919 /* |
964 * We don't have further wildcards to expand, so we have to | 920 * We don't have further wildcards to expand, so we have to |
965 * check for the final file now. | 921 * check for the final file now. |
966 */ | 922 */ |
1006 || ((search_ctx->ffsc_find_what | 962 || ((search_ctx->ffsc_find_what |
1007 == FINDFILE_DIR) | 963 == FINDFILE_DIR) |
1008 == mch_isdir(file_path))))) | 964 == mch_isdir(file_path))))) |
1009 #ifndef FF_VERBOSE | 965 #ifndef FF_VERBOSE |
1010 && (ff_check_visited( | 966 && (ff_check_visited( |
1011 &search_ctx->ffsc_visited_list->ffvl_visited_list, | 967 &search_ctx->ffsc_visited_list |
1012 file_path | 968 ->ffvl_visited_list, |
1013 #ifdef FEAT_PATH_EXTRA | 969 file_path, (char_u *)"") == OK) |
1014 , (char_u *)"" | |
1015 #endif | |
1016 ) == OK) | |
1017 #endif | 970 #endif |
1018 ) | 971 ) |
1019 { | 972 { |
1020 #ifdef FF_VERBOSE | 973 #ifdef FF_VERBOSE |
1021 if (ff_check_visited( | 974 if (ff_check_visited( |
1022 &search_ctx->ffsc_visited_list->ffvl_visited_list, | 975 &search_ctx->ffsc_visited_list |
1023 file_path | 976 ->ffvl_visited_list, |
1024 #ifdef FEAT_PATH_EXTRA | 977 file_path, (char_u *)"") == FAIL) |
1025 , (char_u *)"" | |
1026 #endif | |
1027 ) == FAIL) | |
1028 { | 978 { |
1029 if (p_verbose >= 5) | 979 if (p_verbose >= 5) |
1030 { | 980 { |
1031 verbose_enter_scroll(); | 981 verbose_enter_scroll(); |
1032 smsg("Already: %s", | 982 smsg("Already: %s", |
1072 copy_option_part(&suf, file_path + len, | 1022 copy_option_part(&suf, file_path + len, |
1073 MAXPATHL - len, ","); | 1023 MAXPATHL - len, ","); |
1074 } | 1024 } |
1075 } | 1025 } |
1076 } | 1026 } |
1077 #ifdef FEAT_PATH_EXTRA | |
1078 else | 1027 else |
1079 { | 1028 { |
1080 /* | 1029 /* |
1081 * still wildcards left, push the directories for further | 1030 * still wildcards left, push the directories for further |
1082 * search | 1031 * search |
1092 stackp->ffs_filearray[i], | 1041 stackp->ffs_filearray[i], |
1093 rest_of_wildcards, | 1042 rest_of_wildcards, |
1094 stackp->ffs_level - 1, 0)); | 1043 stackp->ffs_level - 1, 0)); |
1095 } | 1044 } |
1096 } | 1045 } |
1097 #endif | |
1098 stackp->ffs_filearray_cur = 0; | 1046 stackp->ffs_filearray_cur = 0; |
1099 stackp->ffs_stage = 1; | 1047 stackp->ffs_stage = 1; |
1100 } | 1048 } |
1101 | 1049 |
1102 #ifdef FEAT_PATH_EXTRA | |
1103 /* | 1050 /* |
1104 * if wildcards contains '**' we have to descent till we reach the | 1051 * if wildcards contains '**' we have to descent till we reach the |
1105 * leaves of the directory tree. | 1052 * leaves of the directory tree. |
1106 */ | 1053 */ |
1107 if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) | 1054 if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) |
1117 ff_push(search_ctx, | 1064 ff_push(search_ctx, |
1118 ff_create_stack_element(stackp->ffs_filearray[i], | 1065 ff_create_stack_element(stackp->ffs_filearray[i], |
1119 stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); | 1066 stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); |
1120 } | 1067 } |
1121 } | 1068 } |
1122 #endif | |
1123 | 1069 |
1124 // we are done with the current directory | 1070 // we are done with the current directory |
1125 ff_free_stack_element(stackp); | 1071 ff_free_stack_element(stackp); |
1126 | 1072 |
1127 } | 1073 } |
1128 | 1074 |
1129 #ifdef FEAT_PATH_EXTRA | |
1130 // If we reached this, we didn't find anything downwards. | 1075 // If we reached this, we didn't find anything downwards. |
1131 // Let's check if we should do an upward search. | 1076 // Let's check if we should do an upward search. |
1132 if (search_ctx->ffsc_start_dir | 1077 if (search_ctx->ffsc_start_dir |
1133 && search_ctx->ffsc_stopdirs_v != NULL && !got_int) | 1078 && search_ctx->ffsc_stopdirs_v != NULL && !got_int) |
1134 { | 1079 { |
1171 ff_push(search_ctx, sptr); | 1116 ff_push(search_ctx, sptr); |
1172 } | 1117 } |
1173 else | 1118 else |
1174 break; | 1119 break; |
1175 } | 1120 } |
1176 #endif | |
1177 | 1121 |
1178 fail: | 1122 fail: |
1179 vim_free(file_path); | 1123 vim_free(file_path); |
1180 return NULL; | 1124 return NULL; |
1181 } | 1125 } |
1220 ff_visited_T *vp; | 1164 ff_visited_T *vp; |
1221 | 1165 |
1222 while (vl != NULL) | 1166 while (vl != NULL) |
1223 { | 1167 { |
1224 vp = vl->ffv_next; | 1168 vp = vl->ffv_next; |
1225 #ifdef FEAT_PATH_EXTRA | |
1226 vim_free(vl->ffv_wc_path); | 1169 vim_free(vl->ffv_wc_path); |
1227 #endif | |
1228 vim_free(vl); | 1170 vim_free(vl); |
1229 vl = vp; | 1171 vl = vp; |
1230 } | 1172 } |
1231 vl = NULL; | 1173 vl = NULL; |
1232 } | 1174 } |
1296 *list_headp = retptr; | 1238 *list_headp = retptr; |
1297 | 1239 |
1298 return retptr; | 1240 return retptr; |
1299 } | 1241 } |
1300 | 1242 |
1301 #ifdef FEAT_PATH_EXTRA | |
1302 /* | 1243 /* |
1303 * check if two wildcard paths are equal. Returns TRUE or FALSE. | 1244 * check if two wildcard paths are equal. Returns TRUE or FALSE. |
1304 * They are equal if: | 1245 * They are equal if: |
1305 * - both paths are NULL | 1246 * - both paths are NULL |
1306 * - they have the same length | 1247 * - they have the same length |
1337 i += mb_ptr2len(s1 + i); | 1278 i += mb_ptr2len(s1 + i); |
1338 j += mb_ptr2len(s2 + j); | 1279 j += mb_ptr2len(s2 + j); |
1339 } | 1280 } |
1340 return s1[i] == s2[j]; | 1281 return s1[i] == s2[j]; |
1341 } | 1282 } |
1342 #endif | |
1343 | 1283 |
1344 /* | 1284 /* |
1345 * maintains the list of already visited files and dirs | 1285 * maintains the list of already visited files and dirs |
1346 * returns FAIL if the given file/dir is already in the list | 1286 * returns FAIL if the given file/dir is already in the list |
1347 * returns OK if it is newly added | 1287 * returns OK if it is newly added |
1351 * never. | 1291 * never. |
1352 */ | 1292 */ |
1353 static int | 1293 static int |
1354 ff_check_visited( | 1294 ff_check_visited( |
1355 ff_visited_T **visited_list, | 1295 ff_visited_T **visited_list, |
1356 char_u *fname | 1296 char_u *fname, |
1357 #ifdef FEAT_PATH_EXTRA | 1297 char_u *wc_path) |
1358 , char_u *wc_path | |
1359 #endif | |
1360 ) | |
1361 { | 1298 { |
1362 ff_visited_T *vp; | 1299 ff_visited_T *vp; |
1363 #ifdef UNIX | 1300 #ifdef UNIX |
1364 stat_T st; | 1301 stat_T st; |
1365 int url = FALSE; | 1302 int url = FALSE; |
1395 : | 1332 : |
1396 #endif | 1333 #endif |
1397 fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0 | 1334 fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0 |
1398 ) | 1335 ) |
1399 { | 1336 { |
1400 #ifdef FEAT_PATH_EXTRA | |
1401 // are the wildcard parts equal | 1337 // are the wildcard parts equal |
1402 if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) | 1338 if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) |
1403 #endif | |
1404 // already visited | 1339 // already visited |
1405 return FAIL; | 1340 return FAIL; |
1406 } | 1341 } |
1407 } | 1342 } |
1408 | 1343 |
1427 #endif | 1362 #endif |
1428 STRCPY(vp->ffv_fname, ff_expand_buffer); | 1363 STRCPY(vp->ffv_fname, ff_expand_buffer); |
1429 #ifdef UNIX | 1364 #ifdef UNIX |
1430 } | 1365 } |
1431 #endif | 1366 #endif |
1432 #ifdef FEAT_PATH_EXTRA | |
1433 if (wc_path != NULL) | 1367 if (wc_path != NULL) |
1434 vp->ffv_wc_path = vim_strsave(wc_path); | 1368 vp->ffv_wc_path = vim_strsave(wc_path); |
1435 else | 1369 else |
1436 vp->ffv_wc_path = NULL; | 1370 vp->ffv_wc_path = NULL; |
1437 #endif | |
1438 | 1371 |
1439 vp->ffv_next = *visited_list; | 1372 vp->ffv_next = *visited_list; |
1440 *visited_list = vp; | 1373 *visited_list = vp; |
1441 } | 1374 } |
1442 | 1375 |
1447 * create stack element from given path pieces | 1380 * create stack element from given path pieces |
1448 */ | 1381 */ |
1449 static ff_stack_T * | 1382 static ff_stack_T * |
1450 ff_create_stack_element( | 1383 ff_create_stack_element( |
1451 char_u *fix_part, | 1384 char_u *fix_part, |
1452 #ifdef FEAT_PATH_EXTRA | |
1453 char_u *wc_part, | 1385 char_u *wc_part, |
1454 #endif | |
1455 int level, | 1386 int level, |
1456 int star_star_empty) | 1387 int star_star_empty) |
1457 { | 1388 { |
1458 ff_stack_T *new; | 1389 ff_stack_T *new; |
1459 | 1390 |
1472 // the following saves NULL pointer checks in vim_findfile | 1403 // the following saves NULL pointer checks in vim_findfile |
1473 if (fix_part == NULL) | 1404 if (fix_part == NULL) |
1474 fix_part = (char_u *)""; | 1405 fix_part = (char_u *)""; |
1475 new->ffs_fix_path = vim_strsave(fix_part); | 1406 new->ffs_fix_path = vim_strsave(fix_part); |
1476 | 1407 |
1477 #ifdef FEAT_PATH_EXTRA | |
1478 if (wc_part == NULL) | 1408 if (wc_part == NULL) |
1479 wc_part = (char_u *)""; | 1409 wc_part = (char_u *)""; |
1480 new->ffs_wc_path = vim_strsave(wc_part); | 1410 new->ffs_wc_path = vim_strsave(wc_part); |
1481 #endif | 1411 |
1482 | 1412 if (new->ffs_fix_path == NULL || new->ffs_wc_path == NULL) |
1483 if (new->ffs_fix_path == NULL | |
1484 #ifdef FEAT_PATH_EXTRA | |
1485 || new->ffs_wc_path == NULL | |
1486 #endif | |
1487 ) | |
1488 { | 1413 { |
1489 ff_free_stack_element(new); | 1414 ff_free_stack_element(new); |
1490 new = NULL; | 1415 new = NULL; |
1491 } | 1416 } |
1492 | 1417 |
1530 static void | 1455 static void |
1531 ff_free_stack_element(ff_stack_T *stack_ptr) | 1456 ff_free_stack_element(ff_stack_T *stack_ptr) |
1532 { | 1457 { |
1533 // vim_free handles possible NULL pointers | 1458 // vim_free handles possible NULL pointers |
1534 vim_free(stack_ptr->ffs_fix_path); | 1459 vim_free(stack_ptr->ffs_fix_path); |
1535 #ifdef FEAT_PATH_EXTRA | |
1536 vim_free(stack_ptr->ffs_wc_path); | 1460 vim_free(stack_ptr->ffs_wc_path); |
1537 #endif | |
1538 | 1461 |
1539 if (stack_ptr->ffs_filearray != NULL) | 1462 if (stack_ptr->ffs_filearray != NULL) |
1540 FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); | 1463 FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); |
1541 | 1464 |
1542 vim_free(stack_ptr); | 1465 vim_free(stack_ptr); |
1555 ff_free_stack_element(sptr); | 1478 ff_free_stack_element(sptr); |
1556 | 1479 |
1557 vim_free(search_ctx->ffsc_file_to_search); | 1480 vim_free(search_ctx->ffsc_file_to_search); |
1558 vim_free(search_ctx->ffsc_start_dir); | 1481 vim_free(search_ctx->ffsc_start_dir); |
1559 vim_free(search_ctx->ffsc_fix_path); | 1482 vim_free(search_ctx->ffsc_fix_path); |
1560 #ifdef FEAT_PATH_EXTRA | |
1561 vim_free(search_ctx->ffsc_wc_path); | 1483 vim_free(search_ctx->ffsc_wc_path); |
1562 #endif | 1484 |
1563 | |
1564 #ifdef FEAT_PATH_EXTRA | |
1565 if (search_ctx->ffsc_stopdirs_v != NULL) | 1485 if (search_ctx->ffsc_stopdirs_v != NULL) |
1566 { | 1486 { |
1567 int i = 0; | 1487 int i = 0; |
1568 | 1488 |
1569 while (search_ctx->ffsc_stopdirs_v[i] != NULL) | 1489 while (search_ctx->ffsc_stopdirs_v[i] != NULL) |
1572 i++; | 1492 i++; |
1573 } | 1493 } |
1574 vim_free(search_ctx->ffsc_stopdirs_v); | 1494 vim_free(search_ctx->ffsc_stopdirs_v); |
1575 } | 1495 } |
1576 search_ctx->ffsc_stopdirs_v = NULL; | 1496 search_ctx->ffsc_stopdirs_v = NULL; |
1577 #endif | |
1578 | 1497 |
1579 // reset everything | 1498 // reset everything |
1580 search_ctx->ffsc_file_to_search = NULL; | 1499 search_ctx->ffsc_file_to_search = NULL; |
1581 search_ctx->ffsc_start_dir = NULL; | 1500 search_ctx->ffsc_start_dir = NULL; |
1582 search_ctx->ffsc_fix_path = NULL; | 1501 search_ctx->ffsc_fix_path = NULL; |
1583 #ifdef FEAT_PATH_EXTRA | |
1584 search_ctx->ffsc_wc_path = NULL; | 1502 search_ctx->ffsc_wc_path = NULL; |
1585 search_ctx->ffsc_level = 0; | 1503 search_ctx->ffsc_level = 0; |
1586 #endif | 1504 } |
1587 } | 1505 |
1588 | |
1589 #ifdef FEAT_PATH_EXTRA | |
1590 /* | 1506 /* |
1591 * check if the given path is in the stopdirs | 1507 * check if the given path is in the stopdirs |
1592 * returns TRUE if yes else FALSE | 1508 * returns TRUE if yes else FALSE |
1593 */ | 1509 */ |
1594 static int | 1510 static int |
1621 return TRUE; | 1537 return TRUE; |
1622 } | 1538 } |
1623 } | 1539 } |
1624 return FALSE; | 1540 return FALSE; |
1625 } | 1541 } |
1626 #endif | |
1627 | 1542 |
1628 /* | 1543 /* |
1629 * Find the file name "ptr[len]" in the path. Also finds directory names. | 1544 * Find the file name "ptr[len]" in the path. Also finds directory names. |
1630 * | 1545 * |
1631 * On the first call set the parameter 'first' to TRUE to initialize | 1546 * On the first call set the parameter 'first' to TRUE to initialize |
1871 | 1786 |
1872 // copy next path | 1787 // copy next path |
1873 buf[0] = 0; | 1788 buf[0] = 0; |
1874 copy_option_part(&dir, buf, MAXPATHL, " ,"); | 1789 copy_option_part(&dir, buf, MAXPATHL, " ,"); |
1875 | 1790 |
1876 # ifdef FEAT_PATH_EXTRA | |
1877 // get the stopdir string | 1791 // get the stopdir string |
1878 r_ptr = vim_findfile_stopdir(buf); | 1792 r_ptr = vim_findfile_stopdir(buf); |
1879 # else | |
1880 r_ptr = NULL; | |
1881 # endif | |
1882 fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, | 1793 fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, |
1883 r_ptr, 100, FALSE, find_what, | 1794 r_ptr, 100, FALSE, find_what, |
1884 fdip_search_ctx, FALSE, rel_fname); | 1795 fdip_search_ctx, FALSE, rel_fname); |
1885 if (fdip_search_ctx != NULL) | 1796 if (fdip_search_ctx != NULL) |
1886 did_findfile_init = TRUE; | 1797 did_findfile_init = TRUE; |