Mercurial > vim
annotate src/findfile.c @ 17873:d50a5faa75bd v8.1.1933
patch 8.1.1933: the eval.c file is too big
Commit: https://github.com/vim/vim/commit/0522ba0359c96a8c2a4fc8fca0d3b58e49dda759
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 27 22:48:30 2019 +0200
patch 8.1.1933: the eval.c file is too big
Problem: The eval.c file is too big.
Solution: Move code related to variables to evalvars.c. (Yegappan
Lakshmanan, closes #4868)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 27 Aug 2019 23:00:04 +0200 |
parents | 0f7ae8010787 |
children | 46f95606b9ec |
rev | line source |
---|---|
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * findfile.c: Search for files in directories listed in 'path' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 * File searching functions for 'path', 'tags' and 'cdpath' options. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 * External visible functions: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * vim_findfile_init() creates/initialises the search context |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 * vim_findfile_free_visited() free list of visited files/dirs of search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 * context |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * vim_findfile() find a file in the search context |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 * vim_findfile_cleanup() cleanup/free search context created by |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 * vim_findfile_init() |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 * All static functions and variables start with 'ff_' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 * In general it works like this: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 * First you create yourself a search context by calling vim_findfile_init(). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 * It is possible to give a search context from a previous call to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 * vim_findfile_init(), so it can be reused. After this you call vim_findfile() |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 * until you are satisfied with the result or it returns NULL. On every call it |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 * returns the next file which matches the conditions given to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 * vim_findfile_init(). If it doesn't find a next file it returns NULL. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 * It is possible to call vim_findfile_init() again to reinitialise your search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 * with some new parameters. Don't forget to pass your old search context to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 * it, so it can reuse it and especially reuse the list of already visited |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 * directories. If you want to delete the list of already visited directories |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 * simply call vim_findfile_free_visited(). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 * When you are done call vim_findfile_cleanup() to free the search context. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 * The function vim_findfile_init() has a long comment, which describes the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 * needed parameters. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 * ATTENTION: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 * ========== |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 * Also we use an allocated search context here, this functions are NOT |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 * thread-safe!!!!! |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 * To minimize parameter passing (or because I'm to lazy), only the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 * external visible functions get a search context as a parameter. This is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 * then assigned to a static global, which is used throughout the local |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 * functions. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 * type for the directory search stack |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 typedef struct ff_stack |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 struct ff_stack *ffs_prev; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 // the fix part (no wildcards) and the part containing the wildcards |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 // of the search path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 char_u *ffs_fix_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 char_u *ffs_wc_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 // files/dirs found in the above directory, matched by the first wildcard |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 // of wc_part |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 char_u **ffs_filearray; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 int ffs_filearray_size; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 char_u ffs_filearray_cur; // needed for partly handled dirs |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 // to store status of partly handled directories |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 // 0: we work on this directory for the first time |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 // 1: this directory was partly searched in an earlier step |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 int ffs_stage; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 // How deep are we in the directory tree? |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 // Counts backward from value of level parameter to vim_findfile_init |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 int ffs_level; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 // Did we already expand '**' to an empty string? |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 int ffs_star_star_empty; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 } ff_stack_T; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 * type for already visited directories or files. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 typedef struct ff_visited |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 struct ff_visited *ffv_next; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 // Visited directories are different if the wildcard string are |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 // different. So we have to save it. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 char_u *ffv_wc_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 // for unix use inode etc for comparison (needed because of links), else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 // use filename. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 int ffv_dev_valid; // ffv_dev and ffv_ino were set |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 dev_t ffv_dev; // device number |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 ino_t ffv_ino; // inode number |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 // The memory for this struct is allocated according to the length of |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 // ffv_fname. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 char_u ffv_fname[1]; // actually longer |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 } ff_visited_T; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 * We might have to manage several visited lists during a search. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 * This is especially needed for the tags option. If tags is set to: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 * "./++/tags,./++/TAGS,++/tags" (replace + with *) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 * So we have to do 3 searches: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 * 1) search from the current files directory downward for the file "tags" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 * 2) search from the current files directory downward for the file "TAGS" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 * 3) search from Vims current directory downwards for the file "tags" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 * As you can see, the first and the third search are for the same file, so for |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 * the third search we can use the visited list of the first search. For the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 * second search we must start from a empty visited list. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 * The struct ff_visited_list_hdr is used to manage a linked list of already |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 * visited lists. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 typedef struct ff_visited_list_hdr |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 struct ff_visited_list_hdr *ffvl_next; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 // the filename the attached visited list is for |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 char_u *ffvl_filename; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 ff_visited_T *ffvl_visited_list; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 } ff_visited_list_hdr_T; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 * '**' can be expanded to several directory levels. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 * Set the default maximum depth. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 #define FF_MAX_STAR_STAR_EXPAND ((char_u)30) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 * The search context: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 * ffsc_stack_ptr: the stack for the dirs to search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 * ffsc_visited_list: the currently active visited list |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 * ffsc_dir_visited_list: the currently active visited list for search dirs |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 * ffsc_visited_lists_list: the list of all visited lists |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 * ffsc_dir_visited_lists_list: the list of all visited lists for search dirs |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 * ffsc_file_to_search: the file to search for |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 * ffsc_start_dir: the starting directory, if search path was relative |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 * ffsc_fix_path: the fix part of the given path (without wildcards) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 * Needed for upward search. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 * ffsc_wc_path: the part of the given path containing wildcards |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 * ffsc_level: how many levels of dirs to search downwards |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 * ffsc_stopdirs_v: array of stop directories for upward search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 * ffsc_find_what: FINDFILE_BOTH, FINDFILE_DIR or FINDFILE_FILE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 * ffsc_tagfile: searching for tags file, don't use 'suffixesadd' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 typedef struct ff_search_ctx_T |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 ff_stack_T *ffsc_stack_ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 ff_visited_list_hdr_T *ffsc_visited_list; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 ff_visited_list_hdr_T *ffsc_dir_visited_list; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 ff_visited_list_hdr_T *ffsc_visited_lists_list; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 ff_visited_list_hdr_T *ffsc_dir_visited_lists_list; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 char_u *ffsc_file_to_search; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 char_u *ffsc_start_dir; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 char_u *ffsc_fix_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 char_u *ffsc_wc_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 int ffsc_level; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 char_u **ffsc_stopdirs_v; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 int ffsc_find_what; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 int ffsc_tagfile; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 } ff_search_ctx_T; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 // locally needed functions |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 static int ff_check_visited(ff_visited_T **, char_u *, char_u *); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 #else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 static int ff_check_visited(ff_visited_T **, char_u *); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 #endif |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
191 static void vim_findfile_free_visited(void *search_ctx_arg); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 static void ff_free_visited_list(ff_visited_T *vl); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 static ff_visited_list_hdr_T* ff_get_visited_list(char_u *, ff_visited_list_hdr_T **list_headp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 static void ff_clear(ff_search_ctx_T *search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 static void ff_free_stack_element(ff_stack_T *stack_ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 static ff_stack_T *ff_create_stack_element(char_u *, char_u *, int, int); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 #else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 static ff_stack_T *ff_create_stack_element(char_u *, int, int); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 static int ff_path_in_stoplist(char_u *, int, char_u **); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 static char_u e_pathtoolong[] = N_("E854: path too long for completion"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 static char_u *ff_expand_buffer = NULL; // used for expanding filenames |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 #if 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 * if someone likes findfirst/findnext, here are the functions |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 * NOT TESTED!! |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 static void *ff_fn_search_context = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 vim_findfirst(char_u *path, char_u *filename, int level) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 ff_fn_search_context = |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 vim_findfile_init(path, filename, NULL, level, TRUE, FALSE, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 ff_fn_search_context, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 if (NULL == ff_fn_search_context) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 return vim_findnext() |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 vim_findnext(void) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 char_u *ret = vim_findfile(ff_fn_search_context); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 if (NULL == ret) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 vim_findfile_cleanup(ff_fn_search_context); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 ff_fn_search_context = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 return ret; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 * Initialization routine for vim_findfile(). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 * Returns the newly allocated search context or NULL if an error occurred. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 * Don't forget to clean up by calling vim_findfile_cleanup() if you are done |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 * with the search context. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 * Find the file 'filename' in the directory 'path'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 * The parameter 'path' may contain wildcards. If so only search 'level' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 * directories deep. The parameter 'level' is the absolute maximum and is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 * not related to restricts given to the '**' wildcard. If 'level' is 100 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 * and you use '**200' vim_findfile() will stop after 100 levels. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 * 'filename' cannot contain wildcards! It is used as-is, no backslashes to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 * escape special characters. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 * If 'stopdirs' is not NULL and nothing is found downward, the search is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 * restarted on the next higher directory level. This is repeated until the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 * start-directory of a search is contained in 'stopdirs'. 'stopdirs' has the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 * format ";*<dirname>*\(;<dirname>\)*;\=$". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 * If the 'path' is relative, the starting dir for the search is either VIM's |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 * current dir or if the path starts with "./" the current files dir. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 * If the 'path' is absolute, the starting dir is that part of the path before |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 * the first wildcard. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 * Upward search is only done on the starting dir. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 * If 'free_visited' is TRUE the list of already visited files/directories is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 * cleared. Set this to FALSE if you just want to search from another |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 * directory, but want to be sure that no directory from a previous search is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 * searched again. This is useful if you search for a file at different places. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 * The list of visited files/dirs can also be cleared with the function |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 * vim_findfile_free_visited(). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 * Set the parameter 'find_what' to FINDFILE_DIR if you want to search for |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 * directories only, FINDFILE_FILE for files only, FINDFILE_BOTH for both. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 * A search context returned by a previous call to vim_findfile_init() can be |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 * passed in the parameter "search_ctx_arg". This context is reused and |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 * reinitialized with the new parameters. The list of already visited |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 * directories from this context is only deleted if the parameter |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 * "free_visited" is true. Be aware that the passed "search_ctx_arg" is freed |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 * if the reinitialization fails. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 * If you don't have a search context from a previous call "search_ctx_arg" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 * must be NULL. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 * This function silently ignores a few errors, vim_findfile() will have |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 * limited functionality then. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 void * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 vim_findfile_init( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 char_u *path, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 char_u *filename, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 char_u *stopdirs UNUSED, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 int level, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 int free_visited, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 int find_what, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 void *search_ctx_arg, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 int tagfile, // expanding names of tags files |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 char_u *rel_fname) // file name to use for "." |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 char_u *wc_part; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 ff_stack_T *sptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 ff_search_ctx_T *search_ctx; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 // If a search context is given by the caller, reuse it, else allocate a |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 // new one. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 if (search_ctx_arg != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 search_ctx = search_ctx_arg; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
323 search_ctx = ALLOC_ONE(ff_search_ctx_T); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 if (search_ctx == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 vim_memset(search_ctx, 0, sizeof(ff_search_ctx_T)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 search_ctx->ffsc_find_what = find_what; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 search_ctx->ffsc_tagfile = tagfile; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 // clear the search context, but NOT the visited lists |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 ff_clear(search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 // clear visited list if wanted |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 if (free_visited == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 vim_findfile_free_visited(search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 // Reuse old visited lists. Get the visited list for the given |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 // filename. If no list for the current filename exists, creates a new |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 // one. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 search_ctx->ffsc_visited_list = ff_get_visited_list(filename, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 &search_ctx->ffsc_visited_lists_list); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 if (search_ctx->ffsc_visited_list == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 &search_ctx->ffsc_dir_visited_lists_list); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 if (search_ctx->ffsc_dir_visited_list == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 if (ff_expand_buffer == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
354 ff_expand_buffer = alloc(MAXPATHL); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 if (ff_expand_buffer == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 // Store information on starting dir now if path is relative. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 // If path is absolute, we do that later. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 if (path[0] == '.' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 && (vim_ispathsep(path[1]) || path[1] == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 && rel_fname != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 int len = (int)(gettail(rel_fname) - rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 // Make the start dir an absolute path name. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 vim_strncpy(ff_expand_buffer, rel_fname, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 if (search_ctx->ffsc_start_dir == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 if (*++path != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 ++path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 else if (*path == NUL || !vim_isAbsName(path)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 #ifdef BACKSLASH_IN_FILENAME |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 // "c:dir" needs "c:" to be expanded, otherwise use current dir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 if (*path != NUL && path[1] == ':') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 char_u drive[3]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 drive[0] = path[0]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 drive[1] = ':'; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 drive[2] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 if (vim_FullName(drive, ff_expand_buffer, MAXPATHL, TRUE) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 path += 2; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 if (mch_dirname(ff_expand_buffer, MAXPATHL) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 if (search_ctx->ffsc_start_dir == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 #ifdef BACKSLASH_IN_FILENAME |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 // A path that starts with "/dir" is relative to the drive, not to the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 // directory (but not for "//machine/dir"). Only use the drive name. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 if ((*path == '/' || *path == '\\') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 && path[1] != path[0] |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 && search_ctx->ffsc_start_dir[1] == ':') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 search_ctx->ffsc_start_dir[2] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 * If stopdirs are given, split them into an array of pointers. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 * If this fails (mem allocation), there is no upward search at all or a |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 * stop directory is not recognized -> continue silently. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 * If stopdirs just contains a ";" or is empty, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 * search_ctx->ffsc_stopdirs_v will only contain a NULL pointer. This |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 * is handled as unlimited upward search. See function |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 * ff_path_in_stoplist() for details. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 if (stopdirs != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 char_u *walker = stopdirs; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 int dircount; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 while (*walker == ';') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 walker++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 dircount = 1; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
434 search_ctx->ffsc_stopdirs_v = ALLOC_ONE(char_u *); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 if (search_ctx->ffsc_stopdirs_v != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 do |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 char_u *helper; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 void *ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 helper = walker; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 ptr = vim_realloc(search_ctx->ffsc_stopdirs_v, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 (dircount + 1) * sizeof(char_u *)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 if (ptr) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 search_ctx->ffsc_stopdirs_v = ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 // ignore, keep what we have and continue |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 walker = vim_strchr(walker, ';'); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 if (walker) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 search_ctx->ffsc_stopdirs_v[dircount-1] = |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 vim_strnsave(helper, (int)(walker - helper)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 walker++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 // this might be "", which means ascent till top |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 // of directory tree. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 search_ctx->ffsc_stopdirs_v[dircount-1] = |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 vim_strsave(helper); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 dircount++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 } while (walker != NULL); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 search_ctx->ffsc_level = level; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 * split into: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 * -fix path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 * -wildcard_stuff (might be NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 wc_part = vim_strchr(path, '*'); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 if (wc_part != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 int llevel; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 int len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 char *errpt; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 // save the fix part of the path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 search_ctx->ffsc_fix_path = vim_strnsave(path, (int)(wc_part - path)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 * copy wc_path and add restricts to the '**' wildcard. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 * The octet after a '**' is used as a (binary) counter. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 * So '**3' is transposed to '**^C' ('^C' is ASCII value 3) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 * or '**76' is transposed to '**N'( 'N' is ASCII value 76). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 * For EBCDIC you get different character values. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 * If no restrict is given after '**' the default is used. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 * Due to this technique the path looks awful if you print it as a |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 * string. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 len = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 while (*wc_part != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 if (len + 5 >= MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 emsg(_(e_pathtoolong)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 if (STRNCMP(wc_part, "**", 2) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 ff_expand_buffer[len++] = *wc_part++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 ff_expand_buffer[len++] = *wc_part++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 llevel = strtol((char *)wc_part, &errpt, 10); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 ff_expand_buffer[len++] = llevel; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 else if ((char_u *)errpt != wc_part && llevel == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 // restrict is 0 -> remove already added '**' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 len -= 2; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 ff_expand_buffer[len++] = FF_MAX_STAR_STAR_EXPAND; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 wc_part = (char_u *)errpt; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 if (*wc_part != NUL && !vim_ispathsep(*wc_part)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 semsg(_("E343: Invalid path: '**[number]' must be at the end of the path or be followed by '%s'."), PATHSEPSTR); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 ff_expand_buffer[len++] = *wc_part++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 ff_expand_buffer[len] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 if (search_ctx->ffsc_wc_path == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 search_ctx->ffsc_fix_path = vim_strsave(path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 if (search_ctx->ffsc_start_dir == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 // store the fix part as startdir. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 // This is needed if the parameter path is fully qualified. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 if (search_ctx->ffsc_start_dir == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 search_ctx->ffsc_fix_path[0] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 // create an absolute path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 if (STRLEN(search_ctx->ffsc_start_dir) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 + STRLEN(search_ctx->ffsc_fix_path) + 3 >= MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 emsg(_(e_pathtoolong)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 add_pathsep(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 int eb_len = (int)STRLEN(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 char_u *buf = alloc(eb_len |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 + (int)STRLEN(search_ctx->ffsc_fix_path) + 1); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 STRCPY(buf, ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 if (mch_isdir(buf)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 add_pathsep(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 char_u *p = gettail(search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 char_u *wc_path = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 char_u *temp = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 int len = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 if (p > search_ctx->ffsc_fix_path) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 len = (int)(p - search_ctx->ffsc_fix_path) - 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 add_pathsep(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 len = (int)STRLEN(search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 if (search_ctx->ffsc_wc_path != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 wc_path = vim_strsave(search_ctx->ffsc_wc_path); |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
592 temp = alloc(STRLEN(search_ctx->ffsc_wc_path) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 + STRLEN(search_ctx->ffsc_fix_path + len) |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
594 + 1); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 if (temp == NULL || wc_path == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 vim_free(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 vim_free(temp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 vim_free(wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 STRCPY(temp, search_ctx->ffsc_fix_path + len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 STRCAT(temp, search_ctx->ffsc_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 vim_free(search_ctx->ffsc_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 vim_free(wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 search_ctx->ffsc_wc_path = temp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 vim_free(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 sptr = ff_create_stack_element(ff_expand_buffer, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 search_ctx->ffsc_wc_path, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 level, 0); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 if (sptr == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 ff_push(search_ctx, sptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 search_ctx->ffsc_file_to_search = vim_strsave(filename); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 if (search_ctx->ffsc_file_to_search == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 goto error_return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 return search_ctx; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 error_return: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 * We clear the search context now! |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 * Even when the caller gave us a (perhaps valid) context we free it here, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 * as we might have already destroyed it. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 vim_findfile_cleanup(search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 #if defined(FEAT_PATH_EXTRA) || defined(PROTO) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 * Get the stopdir string. Check that ';' is not escaped. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 vim_findfile_stopdir(char_u *buf) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 char_u *r_ptr = buf; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 while (*r_ptr != NUL && *r_ptr != ';') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 if (r_ptr[0] == '\\' && r_ptr[1] == ';') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 // Overwrite the escape char, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 // use STRLEN(r_ptr) to move the trailing '\0'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 STRMOVE(r_ptr, r_ptr + 1); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 r_ptr++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 r_ptr++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 if (*r_ptr == ';') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 *r_ptr = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 r_ptr++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 else if (*r_ptr == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 r_ptr = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 return r_ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 * Clean up the given search context. Can handle a NULL pointer. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 vim_findfile_cleanup(void *ctx) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 if (ctx == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 vim_findfile_free_visited(ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 ff_clear(ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 vim_free(ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 * Find a file in a search context. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 * The search context was created with vim_findfile_init() above. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 * Return a pointer to an allocated file name or NULL if nothing found. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 * To get all matching files call this function until you get NULL. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 * If the passed search_context is NULL, NULL is returned. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 * The search algorithm is depth first. To change this replace the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 * stack with a list (don't forget to leave partly searched directories on the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 * top of the list). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 vim_findfile(void *search_ctx_arg) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 char_u *file_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 char_u *rest_of_wildcards; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 char_u *path_end = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 ff_stack_T *stackp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 #if defined(FEAT_SEARCHPATH) || defined(FEAT_PATH_EXTRA) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 int len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 int i; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 #ifdef FEAT_SEARCHPATH |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 char_u *suf; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 ff_search_ctx_T *search_ctx; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 if (search_ctx_arg == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 search_ctx = (ff_search_ctx_T *)search_ctx_arg; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 * filepath is used as buffer for various actions and as the storage to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 * return a found filename. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 */ |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
726 if ((file_path = alloc(MAXPATHL)) == NULL) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 // store the end of the start dir -- needed for upward search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 if (search_ctx->ffsc_start_dir != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 path_end = &search_ctx->ffsc_start_dir[ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 STRLEN(search_ctx->ffsc_start_dir)]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 // upward search loop |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 for (;;) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 // downward search loop |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 for (;;) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 // check if user user wants to stop the search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 ui_breakcheck(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 if (got_int) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 // get directory to work on from stack |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 stackp = ff_pop(search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 if (stackp == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 * TODO: decide if we leave this test in |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 * GOOD: don't search a directory(-tree) twice. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 * BAD: - check linked list for every new directory entered. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 * - check for double files also done below |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 * Here we check if we already searched this directory. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 * We already searched a directory if: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 * 1) The directory is the same. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 * 2) We would use the same wildcard string. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 * Good if you have links on same directory via several ways |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 * or you have selfreferences in directories (e.g. SuSE Linux 6.3: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 * /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 * This check is only needed for directories we work on for the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 * first time (hence stackp->ff_filearray == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 if (stackp->ffs_filearray == NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 && ff_check_visited(&search_ctx->ffsc_dir_visited_list |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 ->ffvl_visited_list, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 stackp->ffs_fix_path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 , stackp->ffs_wc_path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 ) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 #ifdef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 if (p_verbose >= 5) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 verbose_enter_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 smsg("Already Searched: %s (%s)", |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 stackp->ffs_fix_path, stackp->ffs_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 // don't overwrite this either |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 msg_puts("\n"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 verbose_leave_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 #ifdef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 else if (p_verbose >= 5) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 verbose_enter_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 smsg("Searching: %s (%s)", |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 stackp->ffs_fix_path, stackp->ffs_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 // don't overwrite this either |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 msg_puts("\n"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 verbose_leave_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 // check depth |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 if (stackp->ffs_level <= 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 file_path[0] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 * If no filearray till now expand wildcards |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 * The function expand_wildcards() can handle an array of paths |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 * and all possible expands are returned in one array. We use this |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 * to handle the expansion of '**' into an empty string. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 if (stackp->ffs_filearray == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 char_u *dirptrs[2]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 // we use filepath to build the path expand_wildcards() should |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 // expand. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 dirptrs[0] = file_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 dirptrs[1] = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 // if we have a start dir copy it in |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 if (!vim_isAbsName(stackp->ffs_fix_path) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 && search_ctx->ffsc_start_dir) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 if (STRLEN(search_ctx->ffsc_start_dir) + 1 < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 STRCPY(file_path, search_ctx->ffsc_start_dir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 add_pathsep(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 goto fail; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 // append the fix part of the search path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 STRCAT(file_path, stackp->ffs_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 add_pathsep(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 goto fail; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 rest_of_wildcards = stackp->ffs_wc_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 if (*rest_of_wildcards != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 len = (int)STRLEN(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 if (STRNCMP(rest_of_wildcards, "**", 2) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 // pointer to the restrict byte |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 // The restrict byte is not a character! |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 p = rest_of_wildcards + 2; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 if (*p > 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 (*p)--; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 if (len + 1 < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 file_path[len++] = '*'; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 goto fail; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 if (*p == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 // remove '**<numb> from wildcards |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 STRMOVE(rest_of_wildcards, rest_of_wildcards + 3); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 rest_of_wildcards += 3; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 if (stackp->ffs_star_star_empty == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 // if not done before, expand '**' to empty |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 stackp->ffs_star_star_empty = 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 dirptrs[1] = stackp->ffs_fix_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 * Here we copy until the next path separator or the end of |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 * the path. If we stop at a path separator, there is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 * still something else left. This is handled below by |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 * pushing every directory returned from expand_wildcards() |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 * on the stack again for further search. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 while (*rest_of_wildcards |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 && !vim_ispathsep(*rest_of_wildcards)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 if (len + 1 < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 file_path[len++] = *rest_of_wildcards++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 goto fail; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 file_path[len] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 if (vim_ispathsep(*rest_of_wildcards)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 rest_of_wildcards++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 * Expand wildcards like "*" and "$VAR". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 * If the path is a URL don't try this. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 if (path_with_url(dirptrs[0])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
929 stackp->ffs_filearray = ALLOC_ONE(char_u *); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 if (stackp->ffs_filearray != NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 && (stackp->ffs_filearray[0] |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 = vim_strsave(dirptrs[0])) != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 stackp->ffs_filearray_size = 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 stackp->ffs_filearray_size = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 // Add EW_NOTWILD because the expanded path may contain |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 // wildcard characters that are to be taken literally. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 // This is a bit of a hack. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 &stackp->ffs_filearray_size, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 &stackp->ffs_filearray, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 EW_DIR|EW_ADDSLASH|EW_SILENT|EW_NOTWILD); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 stackp->ffs_filearray_cur = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 stackp->ffs_stage = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 rest_of_wildcards = &stackp->ffs_wc_path[ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 STRLEN(stackp->ffs_wc_path)]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 if (stackp->ffs_stage == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 // this is the first time we work on this directory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 if (*rest_of_wildcards == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 * We don't have further wildcards to expand, so we have to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 * check for the final file now. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 for (i = stackp->ffs_filearray_cur; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 i < stackp->ffs_filearray_size; ++i) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 if (!path_with_url(stackp->ffs_filearray[i]) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 && !mch_isdir(stackp->ffs_filearray[i])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 continue; /* not a directory */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 // prepare the filename to be checked for existence |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 // below |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 if (STRLEN(stackp->ffs_filearray[i]) + 1 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 + STRLEN(search_ctx->ffsc_file_to_search) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 STRCPY(file_path, stackp->ffs_filearray[i]); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 add_pathsep(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 STRCAT(file_path, search_ctx->ffsc_file_to_search); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 goto fail; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 * Try without extra suffix and then with suffixes |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 * from 'suffixesadd'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 #ifdef FEAT_SEARCHPATH |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 len = (int)STRLEN(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 if (search_ctx->ffsc_tagfile) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 suf = (char_u *)""; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 suf = curbuf->b_p_sua; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 for (;;) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 // if file exists and we didn't already find it |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 if ((path_with_url(file_path) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 || (mch_getperm(file_path) >= 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 && (search_ctx->ffsc_find_what |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 == FINDFILE_BOTH |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 || ((search_ctx->ffsc_find_what |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 == FINDFILE_DIR) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 == mch_isdir(file_path))))) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 #ifndef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 && (ff_check_visited( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 &search_ctx->ffsc_visited_list->ffvl_visited_list, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 file_path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 , (char_u *)"" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 ) == OK) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 #ifdef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 if (ff_check_visited( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 &search_ctx->ffsc_visited_list->ffvl_visited_list, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 file_path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 , (char_u *)"" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 ) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 if (p_verbose >= 5) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 verbose_enter_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 smsg("Already: %s", |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 // don't overwrite this either |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 msg_puts("\n"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 verbose_leave_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 // push dir to examine rest of subdirs later |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 stackp->ffs_filearray_cur = i + 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 ff_push(search_ctx, stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 if (!path_with_url(file_path)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 simplify_filename(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 if (mch_dirname(ff_expand_buffer, MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 == OK) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 p = shorten_fname(file_path, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 if (p != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 STRMOVE(file_path, p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 #ifdef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 if (p_verbose >= 5) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 verbose_enter_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 smsg("HIT: %s", file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 // don't overwrite this either |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 msg_puts("\n"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 verbose_leave_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 return file_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 #ifdef FEAT_SEARCHPATH |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 // Not found or found already, try next suffix. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 if (*suf == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 copy_option_part(&suf, file_path + len, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 MAXPATHL - len, ","); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 * still wildcards left, push the directories for further |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 * search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 for (i = stackp->ffs_filearray_cur; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 i < stackp->ffs_filearray_size; ++i) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 if (!mch_isdir(stackp->ffs_filearray[i])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 continue; // not a directory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 ff_push(search_ctx, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 ff_create_stack_element( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 stackp->ffs_filearray[i], |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 rest_of_wildcards, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 stackp->ffs_level - 1, 0)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 stackp->ffs_filearray_cur = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 stackp->ffs_stage = 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 * if wildcards contains '**' we have to descent till we reach the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 * leaves of the directory tree. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 for (i = stackp->ffs_filearray_cur; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 i < stackp->ffs_filearray_size; ++i) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 if (fnamecmp(stackp->ffs_filearray[i], |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 stackp->ffs_fix_path) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 continue; // don't repush same directory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 if (!mch_isdir(stackp->ffs_filearray[i])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 continue; // not a directory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 ff_push(search_ctx, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 ff_create_stack_element(stackp->ffs_filearray[i], |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 // we are done with the current directory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 ff_free_stack_element(stackp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 // If we reached this, we didn't find anything downwards. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 // Let's check if we should do an upward search. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 if (search_ctx->ffsc_start_dir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 && search_ctx->ffsc_stopdirs_v != NULL && !got_int) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 ff_stack_T *sptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 // is the last starting directory in the stop list? |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 if (ff_path_in_stoplist(search_ctx->ffsc_start_dir, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 (int)(path_end - search_ctx->ffsc_start_dir), |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 search_ctx->ffsc_stopdirs_v) == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 // cut of last dir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 while (path_end > search_ctx->ffsc_start_dir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 && vim_ispathsep(*path_end)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 path_end--; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 while (path_end > search_ctx->ffsc_start_dir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 && !vim_ispathsep(path_end[-1])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 path_end--; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 *path_end = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 path_end--; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 if (*search_ctx->ffsc_start_dir == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 if (STRLEN(search_ctx->ffsc_start_dir) + 1 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 + STRLEN(search_ctx->ffsc_fix_path) < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 STRCPY(file_path, search_ctx->ffsc_start_dir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 add_pathsep(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 STRCAT(file_path, search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 goto fail; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 // create a new stack entry |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 sptr = ff_create_stack_element(file_path, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 if (sptr == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 ff_push(search_ctx, sptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 fail: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 vim_free(file_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 * Free the list of lists of visited files and directories |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 * Can handle it if the passed search_context is NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1190 static void |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 vim_findfile_free_visited(void *search_ctx_arg) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 ff_search_ctx_T *search_ctx; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 if (search_ctx_arg == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 search_ctx = (ff_search_ctx_T *)search_ctx_arg; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 vim_findfile_free_visited_list(&search_ctx->ffsc_visited_lists_list); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 vim_findfile_free_visited_list(&search_ctx->ffsc_dir_visited_lists_list); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 static void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 ff_visited_list_hdr_T *vp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 while (*list_headp != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 vp = (*list_headp)->ffvl_next; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 ff_free_visited_list((*list_headp)->ffvl_visited_list); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 vim_free((*list_headp)->ffvl_filename); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 vim_free(*list_headp); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 *list_headp = vp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 *list_headp = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 static void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 ff_free_visited_list(ff_visited_T *vl) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 ff_visited_T *vp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 while (vl != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 vp = vl->ffv_next; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 vim_free(vl->ffv_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 vim_free(vl); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 vl = vp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 vl = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 * Returns the already visited list for the given filename. If none is found it |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 * allocates a new one. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 static ff_visited_list_hdr_T* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 ff_get_visited_list( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 char_u *filename, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 ff_visited_list_hdr_T **list_headp) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 ff_visited_list_hdr_T *retptr = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 // check if a visited list for the given filename exists |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 if (*list_headp != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 retptr = *list_headp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 while (retptr != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 if (fnamecmp(filename, retptr->ffvl_filename) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 #ifdef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 if (p_verbose >= 5) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 verbose_enter_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 smsg("ff_get_visited_list: FOUND list for %s", |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 filename); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 // don't overwrite this either |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 msg_puts("\n"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 verbose_leave_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 return retptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 retptr = retptr->ffvl_next; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 #ifdef FF_VERBOSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 if (p_verbose >= 5) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 verbose_enter_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 smsg("ff_get_visited_list: new list for %s", filename); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 // don't overwrite this either |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 msg_puts("\n"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 verbose_leave_scroll(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 * if we reach this we didn't find a list and we have to allocate new list |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 */ |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1287 retptr = ALLOC_ONE(ff_visited_list_hdr_T); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 if (retptr == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 retptr->ffvl_visited_list = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 retptr->ffvl_filename = vim_strsave(filename); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 if (retptr->ffvl_filename == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 vim_free(retptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1297 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 retptr->ffvl_next = *list_headp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 *list_headp = retptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 return retptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 * check if two wildcard paths are equal. Returns TRUE or FALSE. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 * They are equal if: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 * - both paths are NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 * - they have the same length |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 * - char by char comparison is OK |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 * - the only differences are in the counters behind a '**', so |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 * '**\20' is equal to '**\24' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 static int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 ff_wc_equal(char_u *s1, char_u *s2) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 int i, j; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 int c1 = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 int c2 = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 int prev1 = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 int prev2 = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 if (s1 == s2) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 return TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 if (s1 == NULL || s2 == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 return FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 for (i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 c1 = PTR2CHAR(s1 + i); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 c2 = PTR2CHAR(s2 + j); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 if ((p_fic ? MB_TOLOWER(c1) != MB_TOLOWER(c2) : c1 != c2) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 && (prev1 != '*' || prev2 != '*')) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 return FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 prev2 = prev1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 prev1 = c1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 i += MB_PTR2LEN(s1 + i); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 j += MB_PTR2LEN(s2 + j); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 return s1[i] == s2[j]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 * maintains the list of already visited files and dirs |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 * returns FAIL if the given file/dir is already in the list |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 * returns OK if it is newly added |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 * TODO: What to do on memory allocation problems? |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 * -> return TRUE - Better the file is found several times instead of |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 * never. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1355 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 static int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 ff_check_visited( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 ff_visited_T **visited_list, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 char_u *fname |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 , char_u *wc_path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 ff_visited_T *vp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 stat_T st; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 int url = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 // For an URL we only compare the name, otherwise we compare the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 // device/inode (unix) or the full path name (not Unix). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 if (path_with_url(fname)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 vim_strncpy(ff_expand_buffer, fname, MAXPATHL - 1); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 url = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 ff_expand_buffer[0] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 if (mch_stat((char *)fname, &st) < 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 #else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 if (vim_FullName(fname, ff_expand_buffer, MAXPATHL, TRUE) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 return FAIL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 // check against list of already visited files |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 if ( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 !url ? (vp->ffv_dev_valid && vp->ffv_dev == st.st_dev |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 && vp->ffv_ino == st.st_ino) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 : |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 // are the wildcard parts equal |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 // already visited |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 return FAIL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 * New file/dir. Add it to the list of visited files/dirs. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 */ |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1415 vp = alloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer)); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 if (vp != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 if (!url) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 vp->ffv_dev_valid = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 vp->ffv_ino = st.st_ino; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 vp->ffv_dev = st.st_dev; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 vp->ffv_fname[0] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 vp->ffv_dev_valid = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 STRCPY(vp->ffv_fname, ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 #ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 if (wc_path != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 vp->ffv_wc_path = vim_strsave(wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 vp->ffv_wc_path = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 vp->ffv_next = *visited_list; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 *visited_list = vp; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 return OK; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 * create stack element from given path pieces |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 static ff_stack_T * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 ff_create_stack_element( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 char_u *fix_part, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 char_u *wc_part, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 int level, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 int star_star_empty) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 ff_stack_T *new; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1463 new = ALLOC_ONE(ff_stack_T); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 if (new == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 new->ffs_prev = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 new->ffs_filearray = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 new->ffs_filearray_size = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 new->ffs_filearray_cur = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 new->ffs_stage = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 new->ffs_level = level; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 new->ffs_star_star_empty = star_star_empty; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 // the following saves NULL pointer checks in vim_findfile |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 if (fix_part == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 fix_part = (char_u *)""; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 new->ffs_fix_path = vim_strsave(fix_part); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 if (wc_part == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 wc_part = (char_u *)""; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 new->ffs_wc_path = vim_strsave(wc_part); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 if (new->ffs_fix_path == NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 || new->ffs_wc_path == NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 ff_free_stack_element(new); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 new = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 return new; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 * Push a dir on the directory stack. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 static void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 // check for NULL pointer, not to return an error to the user, but |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 // to prevent a crash |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 if (stack_ptr != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 search_ctx->ffsc_stack_ptr = stack_ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 * Pop a dir from the directory stack. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 * Returns NULL if stack is empty. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 static ff_stack_T * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 ff_pop(ff_search_ctx_T *search_ctx) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 ff_stack_T *sptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 sptr = search_ctx->ffsc_stack_ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 if (search_ctx->ffsc_stack_ptr != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_prev; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 return sptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 * free the given stack element |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 static void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 ff_free_stack_element(ff_stack_T *stack_ptr) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 // vim_free handles possible NULL pointers |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 vim_free(stack_ptr->ffs_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 vim_free(stack_ptr->ffs_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 if (stack_ptr->ffs_filearray != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1543 FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 vim_free(stack_ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 * Clear the search context, but NOT the visited list. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 static void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 ff_clear(ff_search_ctx_T *search_ctx) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 ff_stack_T *sptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 // clear up stack |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1557 while ((sptr = ff_pop(search_ctx)) != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 ff_free_stack_element(sptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1560 vim_free(search_ctx->ffsc_file_to_search); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 vim_free(search_ctx->ffsc_start_dir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1562 vim_free(search_ctx->ffsc_fix_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 vim_free(search_ctx->ffsc_wc_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 if (search_ctx->ffsc_stopdirs_v != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 int i = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 while (search_ctx->ffsc_stopdirs_v[i] != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1573 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 vim_free(search_ctx->ffsc_stopdirs_v[i]); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1575 i++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 vim_free(search_ctx->ffsc_stopdirs_v); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 search_ctx->ffsc_stopdirs_v = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 // reset everything |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1583 search_ctx->ffsc_file_to_search = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 search_ctx->ffsc_start_dir = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 search_ctx->ffsc_fix_path = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1586 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 search_ctx->ffsc_wc_path = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 search_ctx->ffsc_level = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 #ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1593 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 * check if the given path is in the stopdirs |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 * returns TRUE if yes else FALSE |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 static int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 int i = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 // eat up trailing path separators, except the first |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 while (path_len > 1 && vim_ispathsep(path[path_len - 1])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 path_len--; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 // if no path consider it as match |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 if (path_len == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 return TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 for (i = 0; stopdirs_v[i] != NULL; i++) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 if ((int)STRLEN(stopdirs_v[i]) > path_len) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 // match for parent directory. So '/home' also matches |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 // '/home/r' would also match '/home/rks' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 if (fnamencmp(stopdirs_v[i], path, path_len) == 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 && vim_ispathsep(stopdirs_v[i][path_len])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 return TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 if (fnamecmp(stopdirs_v[i], path) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 return TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 return FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 #endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 #if defined(FEAT_SEARCHPATH) || defined(PROTO) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 * Find the file name "ptr[len]" in the path. Also finds directory names. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 * On the first call set the parameter 'first' to TRUE to initialize |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 * the search. For repeating calls to FALSE. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 * Repeating calls will return other files called 'ptr[len]' from the path. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 * Only on the first call 'ptr' and 'len' are used. For repeating calls they |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 * don't need valid values. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 * If nothing found on the first call the option FNAME_MESS will issue the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 * message: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 * 'Can't find file "<file>" in path' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 * On repeating calls: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 * 'No more file "<file>" found in path' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 * options: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 * FNAME_MESS give error message when not found |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 * Uses NameBuff[]! |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 * Returns an allocated string for the file name. NULL for error. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1655 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 find_file_in_path( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 char_u *ptr, // file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 int len, // length of file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 int options, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 int first, // use count'th matching file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 char_u *rel_fname) // file name searching relative to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 return find_file_in_path_option(ptr, len, options, first, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 FINDFILE_BOTH, rel_fname, curbuf->b_p_sua); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 static char_u *ff_file_to_find = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 static void *fdip_search_ctx = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 # if defined(EXITFREE) || defined(PROTO) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1674 void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 free_findfile(void) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1677 vim_free(ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 vim_findfile_cleanup(fdip_search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 vim_free(ff_expand_buffer); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1680 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 * Find the directory name "ptr[len]" in the path. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 * options: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 * FNAME_MESS give error message when not found |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 * FNAME_UNESC unescape backslashes. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 * Uses NameBuff[]! |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 * Returns an allocated string for the file name. NULL for error. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1693 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1695 find_directory_in_path( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1696 char_u *ptr, // file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1697 int len, // length of file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1698 int options, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1699 char_u *rel_fname) // file name searching relative to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1700 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 FINDFILE_DIR, rel_fname, (char_u *)""); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1703 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1704 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1705 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 find_file_in_path_option( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1707 char_u *ptr, // file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1708 int len, // length of file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1709 int options, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 int first, // use count'th matching file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1711 char_u *path_option, // p_path or p_cdpath |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 int find_what, // FINDFILE_FILE, _DIR or _BOTH |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 char_u *rel_fname, // file name we are looking relative to. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 char_u *suffixes) // list of suffixes, 'suffixesadd' option |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 static char_u *dir; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 static int did_findfile_init = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 char_u save_char; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 char_u *file_name = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 char_u *buf = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1721 int rel_to_curdir; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1722 # ifdef AMIGA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 struct Process *proc = (struct Process *)FindTask(0L); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 APTR save_winptr = proc->pr_WindowPtr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 // Avoid a requester here for a volume that doesn't exist. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 proc->pr_WindowPtr = (APTR)-1L; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1729 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1730 if (first == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1731 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1732 // copy file name into NameBuff, expanding environment variables |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 save_char = ptr[len]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1734 ptr[len] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 expand_env_esc(ptr, NameBuff, MAXPATHL, FALSE, TRUE, NULL); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 ptr[len] = save_char; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 vim_free(ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 ff_file_to_find = vim_strsave(NameBuff); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 if (ff_file_to_find == NULL) // out of memory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 file_name = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 goto theend; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1745 if (options & FNAME_UNESC) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 // Change all "\ " to " ". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 for (ptr = ff_file_to_find; *ptr != NUL; ++ptr) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 if (ptr[0] == '\\' && ptr[1] == ' ') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 mch_memmove(ptr, ptr + 1, STRLEN(ptr)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 rel_to_curdir = (ff_file_to_find[0] == '.' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 && (ff_file_to_find[1] == NUL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 || vim_ispathsep(ff_file_to_find[1]) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1757 || (ff_file_to_find[1] == '.' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1758 && (ff_file_to_find[2] == NUL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 || vim_ispathsep(ff_file_to_find[2]))))); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 if (vim_isAbsName(ff_file_to_find) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 // "..", "../path", "." and "./path": don't use the path_option |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 || rel_to_curdir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 # if defined(MSWIN) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 // handle "\tmp" as absolute path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 || vim_ispathsep(ff_file_to_find[0]) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 // handle "c:name" as absolute path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 || (ff_file_to_find[0] != NUL && ff_file_to_find[1] == ':') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 # ifdef AMIGA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 // handle ":tmp" as absolute path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 || ff_file_to_find[0] == ':' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 * Absolute path, no need to use "path_option". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 * If this is not a first call, return NULL. We already returned a |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 * filename on the first call. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 if (first == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 int l; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 int run; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 if (path_with_url(ff_file_to_find)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 file_name = vim_strsave(ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 goto theend; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 // When FNAME_REL flag given first use the directory of the file. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 // Otherwise or when this fails use the current directory. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 for (run = 1; run <= 2; ++run) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1794 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1795 l = (int)STRLEN(ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 if (run == 1 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 && rel_to_curdir |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1798 && (options & FNAME_REL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 && rel_fname != NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 && STRLEN(rel_fname) + l < MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 STRCPY(NameBuff, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 STRCPY(gettail(NameBuff), ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 l = (int)STRLEN(NameBuff); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 STRCPY(NameBuff, ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 run = 2; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 // When the file doesn't exist, try adding parts of |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 // 'suffixesadd'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 buf = suffixes; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 for (;;) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 if (mch_getperm(NameBuff) >= 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 && (find_what == FINDFILE_BOTH |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 || ((find_what == FINDFILE_DIR) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 == mch_isdir(NameBuff)))) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 file_name = vim_strsave(NameBuff); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 goto theend; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 if (*buf == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 copy_option_part(&buf, NameBuff + l, MAXPATHL - l, ","); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 * Loop over all paths in the 'path' or 'cdpath' option. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 * When "first" is set, first setup to the start of the option. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 * Otherwise continue to find the next match. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 if (first == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1840 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1841 // vim_findfile_free_visited can handle a possible NULL pointer |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 vim_findfile_free_visited(fdip_search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 dir = path_option; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 did_findfile_init = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 for (;;) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 if (did_findfile_init) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 file_name = vim_findfile(fdip_search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1852 if (file_name != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 did_findfile_init = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 char_u *r_ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 if (dir == NULL || *dir == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 // We searched all paths of the option, now we can |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 // free the search context. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 vim_findfile_cleanup(fdip_search_ctx); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 fdip_search_ctx = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1870 if ((buf = alloc(MAXPATHL)) == NULL) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 // copy next path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 buf[0] = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 copy_option_part(&dir, buf, MAXPATHL, " ,"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 # ifdef FEAT_PATH_EXTRA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 // get the stopdir string |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 r_ptr = vim_findfile_stopdir(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 # else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 r_ptr = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 r_ptr, 100, FALSE, find_what, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 fdip_search_ctx, FALSE, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 if (fdip_search_ctx != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 did_findfile_init = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 vim_free(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 if (file_name == NULL && (options & FNAME_MESS)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 if (first == TRUE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 if (find_what == FINDFILE_DIR) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 semsg(_("E344: Can't find directory \"%s\" in cdpath"), |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 semsg(_("E345: Can't find file \"%s\" in path"), |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 if (find_what == FINDFILE_DIR) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 semsg(_("E346: No more directory \"%s\" found in cdpath"), |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 semsg(_("E347: No more file \"%s\" found in path"), |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 ff_file_to_find); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 theend: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 # ifdef AMIGA |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 proc->pr_WindowPtr = save_winptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 return file_name; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 * Get the file name at the cursor. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 * If Visual mode is active, use the selected text if it's in one line. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 * Returns the name in allocated memory, NULL for failure. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 grab_file_name(long count, linenr_T *file_lnum) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 int options = FNAME_MESS|FNAME_EXP|FNAME_REL|FNAME_UNESC; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 if (VIsual_active) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 int len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 char_u *ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 if (get_visual_text(NULL, &ptr, &len) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 return find_file_name_in_path(ptr, len, options, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 count, curbuf->b_ffname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1941 return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 * Return the file name under or after the cursor. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 * The 'path' option is searched if the file name is not absolute. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 * The string returned has been alloc'ed and should be freed by the caller. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 * NULL is returned if the file name or file is not found. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 * options: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1952 * FNAME_MESS give error messages |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 * FNAME_EXP expand to path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 * FNAME_HYP check for hypertext link |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 * FNAME_INCL apply "includeexpr" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 file_name_at_cursor(int options, long count, linenr_T *file_lnum) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 return file_name_in_line(ml_get_curline(), |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1961 curwin->w_cursor.col, options, count, curbuf->b_ffname, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 file_lnum); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1963 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1966 * Return the name of the file under or after ptr[col]. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1967 * Otherwise like file_name_at_cursor(). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 file_name_in_line( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 char_u *line, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 int col, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 int options, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 long count, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 char_u *rel_fname, // file we are searching relative to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 linenr_T *file_lnum) // line number after the file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 char_u *ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 int len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 int in_type = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 int is_url = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 * search forward for what could be the start of a file name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 ptr = line + col; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 while (*ptr != NUL && !vim_isfilec(*ptr)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 MB_PTR_ADV(ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1989 if (*ptr == NUL) // nothing found |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 if (options & FNAME_MESS) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 emsg(_("E446: No file name under cursor")); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 return NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 * Search backward for first char of the file name. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 * Go one char back to ":" before "//" even when ':' is not in 'isfname'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 while (ptr > line) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2002 if (has_mbyte && (len = (*mb_head_off)(line, ptr - 1)) > 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 ptr -= len + 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 else if (vim_isfilec(ptr[-1]) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 || ((options & FNAME_HYP) && path_is_url(ptr - 1))) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 --ptr; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 * Search forward for the last char of the file name. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 * Also allow "://" when ':' is not in 'isfname'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2014 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 len = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2016 while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 || ((options & FNAME_HYP) && path_is_url(ptr + len)) |
15993
58610c4d785c
patch 8.1.1002: "gf" does not always work when URL has a port number
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2018 || (is_url && vim_strchr((char_u *)":?&=", ptr[len]) != NULL)) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 { |
15993
58610c4d785c
patch 8.1.1002: "gf" does not always work when URL has a port number
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2020 // After type:// we also include :, ?, & and = as valid characters, so that |
58610c4d785c
patch 8.1.1002: "gf" does not always work when URL has a port number
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2021 // http://google.com:8080?q=this&that=ok works. |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 if ((ptr[len] >= 'A' && ptr[len] <= 'Z') || (ptr[len] >= 'a' && ptr[len] <= 'z')) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 if (in_type && path_is_url(ptr + len + 1)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 is_url = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 in_type = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2030 if (ptr[len] == '\\') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2031 // Skip over the "\" in "\ ". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2032 ++len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2033 if (has_mbyte) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2034 len += (*mb_ptr2len)(ptr + len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2035 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 ++len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 * If there is trailing punctuation, remove it. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2041 * But don't remove "..", could be a directory name. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 if (len > 2 && vim_strchr((char_u *)".,:;!", ptr[len - 1]) != NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 && ptr[len - 2] != '.') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 --len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 if (file_lnum != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 // Get the number after the file name and a separator character |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 p = ptr + len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 p = skipwhite(p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 if (*p != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2055 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 if (!isdigit(*p)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 ++p; // skip the separator |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 p = skipwhite(p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 if (isdigit(*p)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 *file_lnum = (int)getdigits(&p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 return find_file_name_in_path(ptr, len, options, count, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2068 static char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2069 eval_includeexpr(char_u *ptr, int len) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 char_u *res; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 set_vim_var_string(VV_FNAME, ptr, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 res = eval_to_string_safe(curbuf->b_p_inex, NULL, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 set_vim_var_string(VV_FNAME, NULL, 0); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2077 return res; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 * Return the name of the file ptr[len] in 'path'. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 * Otherwise like file_name_at_cursor(). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 find_file_name_in_path( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 char_u *ptr, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 int len, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 int options, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 long count, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 char_u *rel_fname) // file we are searching relative to |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 char_u *file_name; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 int c; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2096 char_u *tofree = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 tofree = eval_includeexpr(ptr, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 if (tofree != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 ptr = tofree; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 len = (int)STRLEN(ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 if (options & FNAME_EXP) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 TRUE, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 * If the file could not be found in a normal way, try applying |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 * 'includeexpr' (unless done already). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 if (file_name == NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 && !(options & FNAME_INCL) && *curbuf->b_p_inex != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2122 tofree = eval_includeexpr(ptr, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 if (tofree != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 ptr = tofree; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 len = (int)STRLEN(ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2127 file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 TRUE, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 if (file_name == NULL && (options & FNAME_MESS)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 c = ptr[len]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 ptr[len] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 semsg(_("E447: Can't find file \"%s\" in path"), ptr); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 ptr[len] = c; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 // Repeat finding the file "count" times. This matters when it |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 // appears several times in the path. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 while (file_name != NULL && --count > 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 vim_free(file_name); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 file_name = vim_strnsave(ptr, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2151 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2152 vim_free(tofree); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2153 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2154 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2155 return file_name; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2158 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 * Return the end of the directory name, on the first path |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2160 * separator: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2161 * "/path/file", "/path/dir/", "/path//dir", "/file" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2162 * ^ ^ ^ ^ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2164 static char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2165 gettail_dir(char_u *fname) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2166 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2167 char_u *dir_end = fname; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2168 char_u *next_dir_end = fname; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2169 int look_for_sep = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2170 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2171 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2172 for (p = fname; *p != NUL; ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2173 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2174 if (vim_ispathsep(*p)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2175 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2176 if (look_for_sep) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 next_dir_end = p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 look_for_sep = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2180 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2181 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2182 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2183 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2184 if (!look_for_sep) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2185 dir_end = next_dir_end; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2186 look_for_sep = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2187 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2188 MB_PTR_ADV(p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2190 return dir_end; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2194 * return TRUE if 'c' is a path list separator. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 vim_ispathlistsep(int c) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2198 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 # ifdef UNIX |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2200 return (c == ':'); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2201 # else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 return (c == ';'); // might not be right for every system... |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2203 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2205 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2207 * Moves "*psep" back to the previous path separator in "path". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 * Returns FAIL is "*psep" ends up at the beginning of "path". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2210 static int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 find_previous_pathsep(char_u *path, char_u **psep) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 // skip the current separator |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 if (*psep > path && vim_ispathsep(**psep)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 --*psep; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 // find the previous separator |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 while (*psep > path) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2220 if (vim_ispathsep(**psep)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2221 return OK; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2222 MB_PTR_BACK(path, *psep); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2224 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 return FAIL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2228 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2229 * Returns TRUE if "maybe_unique" is unique wrt other_paths in "gap". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2230 * "maybe_unique" is the end portion of "((char_u **)gap->ga_data)[i]". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2232 static int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 is_unique(char_u *maybe_unique, garray_T *gap, int i) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 int j; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 int candidate_len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 int other_path_len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 char_u **other_paths = (char_u **)gap->ga_data; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 char_u *rival; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2240 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2241 for (j = 0; j < gap->ga_len; j++) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 if (j == i) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2244 continue; // don't compare it with itself |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 candidate_len = (int)STRLEN(maybe_unique); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 other_path_len = (int)STRLEN(other_paths[j]); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 if (other_path_len < candidate_len) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 continue; // it's different when it's shorter |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 rival = other_paths[j] + other_path_len - candidate_len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 if (fnamecmp(maybe_unique, rival) == 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 && (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 return FALSE; // match |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2256 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 return TRUE; // no match found |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 * Split the 'path' option into an array of strings in garray_T. Relative |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 * paths are expanded to their equivalent fullpath. This includes the "." |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 * (relative to current buffer directory) and empty path (relative to current |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 * directory) notations. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 * TODO: handle upward search (;) and path limiter (**N) notations by |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 * expanding each into their equivalent path(s). |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 static void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 expand_path_option(char_u *curdir, garray_T *gap) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 char_u *path_option = *curbuf->b_p_path == NUL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 ? p_path : curbuf->b_p_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2274 char_u *buf; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 int len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2278 if ((buf = alloc(MAXPATHL)) == NULL) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 while (*path_option != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2283 copy_option_part(&path_option, buf, MAXPATHL, " ,"); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2286 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2287 // Relative to current buffer: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2288 // "/path/file" + "." -> "/path/" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 // "/path/file" + "./subdir" -> "/path/subdir" |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2290 if (curbuf->b_ffname == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2292 p = gettail(curbuf->b_ffname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 len = (int)(p - curbuf->b_ffname); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2294 if (len + (int)STRLEN(buf) >= MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2295 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2296 if (buf[1] == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2297 buf[len] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2298 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2299 STRMOVE(buf + len, buf + 2); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2300 mch_memmove(buf, curbuf->b_ffname, len); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2301 simplify_filename(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2302 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2303 else if (buf[0] == NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2304 // relative to current directory |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2305 STRCPY(buf, curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2306 else if (path_with_url(buf)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 // URL can't be used here |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 else if (!mch_isFullName(buf)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2310 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 // Expand relative path to their full path equivalent |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 len = (int)STRLEN(curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 if (len + (int)STRLEN(buf) + 3 > MAXPATHL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 STRMOVE(buf + len + 1, buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2316 STRCPY(buf, curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 buf[len] = PATHSEP; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 simplify_filename(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 if (ga_grow(gap, 1) == FAIL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 # if defined(MSWIN) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2325 // Avoid the path ending in a backslash, it fails when a comma is |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 // appended. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 len = (int)STRLEN(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 if (buf[len - 1] == '\\') |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 buf[len - 1] = '/'; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2330 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 p = vim_strsave(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 if (p == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 ((char_u **)gap->ga_data)[gap->ga_len++] = p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2336 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2337 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2338 vim_free(buf); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2339 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2340 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2341 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2342 * Returns a pointer to the file or directory name in "fname" that matches the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2343 * longest path in "ga"p, or NULL if there is no match. For example: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2344 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2345 * path: /foo/bar/baz |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2346 * fname: /foo/bar/baz/quux.txt |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2347 * returns: ^this |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2348 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2349 static char_u * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2350 get_path_cutoff(char_u *fname, garray_T *gap) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2351 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2352 int i; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2353 int maxlen = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2354 char_u **path_part = (char_u **)gap->ga_data; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2355 char_u *cutoff = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2356 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2357 for (i = 0; i < gap->ga_len; i++) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2358 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2359 int j = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2361 while ((fname[j] == path_part[i][j] |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2362 # if defined(MSWIN) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2363 || (vim_ispathsep(fname[j]) && vim_ispathsep(path_part[i][j])) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2364 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2365 ) && fname[j] != NUL && path_part[i][j] != NUL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2366 j++; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2367 if (j > maxlen) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2368 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2369 maxlen = j; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2370 cutoff = &fname[j]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2371 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2372 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2373 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2374 // skip to the file or directory name |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2375 if (cutoff != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2376 while (vim_ispathsep(*cutoff)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2377 MB_PTR_ADV(cutoff); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2378 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2379 return cutoff; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2380 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2381 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2382 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2383 * Sorts, removes duplicates and modifies all the fullpath names in "gap" so |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2384 * that they are unique with respect to each other while conserving the part |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2385 * that matches the pattern. Beware, this is at least O(n^2) wrt "gap->ga_len". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2386 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2387 void |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2388 uniquefy_paths(garray_T *gap, char_u *pattern) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2389 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2390 int i; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2391 int len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2392 char_u **fnames = (char_u **)gap->ga_data; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2393 int sort_again = FALSE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2394 char_u *pat; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2395 char_u *file_pattern; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2396 char_u *curdir; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2397 regmatch_T regmatch; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2398 garray_T path_ga; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2399 char_u **in_curdir = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2400 char_u *short_name; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2401 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2402 remove_duplicates(gap); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2403 ga_init2(&path_ga, (int)sizeof(char_u *), 1); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2404 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2405 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 * We need to prepend a '*' at the beginning of file_pattern so that the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 * regex matches anywhere in the path. FIXME: is this valid for all |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2408 * possible patterns? |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2410 len = (int)STRLEN(pattern); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 file_pattern = alloc(len + 2); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2412 if (file_pattern == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2413 return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2414 file_pattern[0] = '*'; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2415 file_pattern[1] = NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2416 STRCAT(file_pattern, pattern); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2417 pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2418 vim_free(file_pattern); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2419 if (pat == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2420 return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2421 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2422 regmatch.rm_ic = TRUE; // always ignore case |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2424 vim_free(pat); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2425 if (regmatch.regprog == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2426 return; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2428 if ((curdir = alloc(MAXPATHL)) == NULL) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2429 goto theend; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2430 mch_dirname(curdir, MAXPATHL); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 expand_path_option(curdir, &path_ga); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2432 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2433 in_curdir = ALLOC_CLEAR_MULT(char_u *, gap->ga_len); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2434 if (in_curdir == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 goto theend; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2436 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2437 for (i = 0; i < gap->ga_len && !got_int; i++) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2438 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2439 char_u *path = fnames[i]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2440 int is_in_curdir; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2441 char_u *dir_end = gettail_dir(path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2442 char_u *pathsep_p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2443 char_u *path_cutoff; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2444 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2445 len = (int)STRLEN(path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2446 is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2447 && curdir[dir_end - path] == NUL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2448 if (is_in_curdir) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2449 in_curdir[i] = vim_strsave(path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2450 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2451 // Shorten the filename while maintaining its uniqueness |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2452 path_cutoff = get_path_cutoff(path, &path_ga); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2453 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2454 // Don't assume all files can be reached without path when search |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2455 // pattern starts with star star slash, so only remove path_cutoff |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2456 // when possible. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2457 if (pattern[0] == '*' && pattern[1] == '*' |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2458 && vim_ispathsep_nocolon(pattern[2]) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2459 && path_cutoff != NULL |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2460 && vim_regexec(®match, path_cutoff, (colnr_T)0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2461 && is_unique(path_cutoff, gap, i)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2462 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2463 sort_again = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2464 mch_memmove(path, path_cutoff, STRLEN(path_cutoff) + 1); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2465 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2466 else |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2467 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2468 // Here all files can be reached without path, so get shortest |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2469 // unique path. We start at the end of the path. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2470 pathsep_p = path + len - 1; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2471 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2472 while (find_previous_pathsep(path, &pathsep_p)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2473 if (vim_regexec(®match, pathsep_p + 1, (colnr_T)0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2474 && is_unique(pathsep_p + 1, gap, i) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2475 && path_cutoff != NULL && pathsep_p + 1 >= path_cutoff) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2476 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2477 sort_again = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2478 mch_memmove(path, pathsep_p + 1, STRLEN(pathsep_p)); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2479 break; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2480 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2481 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2482 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2483 if (mch_isFullName(path)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2484 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2485 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2486 * Last resort: shorten relative to curdir if possible. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2487 * 'possible' means: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2488 * 1. It is under the current directory. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2489 * 2. The result is actually shorter than the original. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 * |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2491 * Before curdir After |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2492 * /foo/bar/file.txt /foo/bar ./file.txt |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2493 * c:\foo\bar\file.txt c:\foo\bar .\file.txt |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2494 * /file.txt / /file.txt |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2495 * c:\file.txt c:\ .\file.txt |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2496 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 short_name = shorten_fname(path, curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2498 if (short_name != NULL && short_name > path + 1 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2499 # if defined(MSWIN) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2500 // On windows, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2501 // shorten_fname("c:\a\a.txt", "c:\a\b") |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2502 // returns "\a\a.txt", which is not really the short |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2503 // name, hence: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2504 && !vim_ispathsep(*short_name) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2505 # endif |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2506 ) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2507 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2508 STRCPY(path, "."); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2509 add_pathsep(path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2510 STRMOVE(path + STRLEN(path), short_name); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2511 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2512 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2513 ui_breakcheck(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2514 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2515 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2516 // Shorten filenames in /in/current/directory/{filename} |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2517 for (i = 0; i < gap->ga_len && !got_int; i++) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2518 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2519 char_u *rel_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2520 char_u *path = in_curdir[i]; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2521 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2522 if (path == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2523 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2524 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2525 // If the {filename} is not unique, change it to ./{filename}. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2526 // Else reduce it to {filename} |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2527 short_name = shorten_fname(path, curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2528 if (short_name == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2529 short_name = path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2530 if (is_unique(short_name, gap, i)) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2531 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2532 STRCPY(fnames[i], short_name); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2533 continue; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2534 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2535 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2536 rel_path = alloc(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2); |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2537 if (rel_path == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2538 goto theend; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2539 STRCPY(rel_path, "."); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2540 add_pathsep(rel_path); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2541 STRCAT(rel_path, short_name); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2542 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2543 vim_free(fnames[i]); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2544 fnames[i] = rel_path; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2545 sort_again = TRUE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2546 ui_breakcheck(); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2547 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2548 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2549 theend: |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2550 vim_free(curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2551 if (in_curdir != NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2552 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2553 for (i = 0; i < gap->ga_len; i++) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2554 vim_free(in_curdir[i]); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2555 vim_free(in_curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2556 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2557 ga_clear_strings(&path_ga); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2558 vim_regfree(regmatch.regprog); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2559 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2560 if (sort_again) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2561 remove_duplicates(gap); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2562 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2563 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2564 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2565 * Calls globpath() with 'path' values for the given pattern and stores the |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2566 * result in "gap". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2567 * Returns the total number of matches. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2568 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2569 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2570 expand_in_path( |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2571 garray_T *gap, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2572 char_u *pattern, |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2573 int flags) // EW_* flags |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2574 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2575 char_u *curdir; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2576 garray_T path_ga; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2577 char_u *paths = NULL; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2578 int glob_flags = 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2579 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16188
diff
changeset
|
2580 if ((curdir = alloc(MAXPATHL)) == NULL) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2581 return 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2582 mch_dirname(curdir, MAXPATHL); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2583 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2584 ga_init2(&path_ga, (int)sizeof(char_u *), 1); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2585 expand_path_option(curdir, &path_ga); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2586 vim_free(curdir); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2587 if (path_ga.ga_len == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2588 return 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2589 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2590 paths = ga_concat_strings(&path_ga, ","); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2591 ga_clear_strings(&path_ga); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2592 if (paths == NULL) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2593 return 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2594 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2595 if (flags & EW_ICASE) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2596 glob_flags |= WILD_ICASE; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2597 if (flags & EW_ADDSLASH) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2598 glob_flags |= WILD_ADD_SLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2599 globpath(paths, pattern, gap, glob_flags); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2600 vim_free(paths); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2601 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2602 return gap->ga_len; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2603 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2604 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2605 #endif // FEAT_SEARCHPATH |
16188
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2606 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2607 /* |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2608 * Converts a file name into a canonical form. It simplifies a file name into |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2609 * its simplest form by stripping out unneeded components, if any. The |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2610 * resulting file name is simplified in place and will either be the same |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2611 * length as that supplied, or shorter. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2612 */ |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2613 void |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2614 simplify_filename(char_u *filename) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2615 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2616 #ifndef AMIGA // Amiga doesn't have "..", it uses "/" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2617 int components = 0; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2618 char_u *p, *tail, *start; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2619 int stripping_disabled = FALSE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2620 int relative = TRUE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2621 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2622 p = filename; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2623 # ifdef BACKSLASH_IN_FILENAME |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2624 if (p[1] == ':') // skip "x:" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2625 p += 2; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2626 # endif |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2627 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2628 if (vim_ispathsep(*p)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2629 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2630 relative = FALSE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2631 do |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2632 ++p; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2633 while (vim_ispathsep(*p)); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2634 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2635 start = p; // remember start after "c:/" or "/" or "///" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2636 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2637 do |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2638 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2639 // At this point "p" is pointing to the char following a single "/" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2640 // or "p" is at the "start" of the (absolute or relative) path name. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2641 # ifdef VMS |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2642 // VMS allows device:[path] - don't strip the [ in directory |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2643 if ((*p == '[' || *p == '<') && p > filename && p[-1] == ':') |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2644 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2645 // :[ or :< composition: vms directory component |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2646 ++components; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2647 p = getnextcomp(p + 1); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2648 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2649 // allow remote calls as host"user passwd"::device:[path] |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2650 else if (p[0] == ':' && p[1] == ':' && p > filename && p[-1] == '"' ) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2651 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2652 // ":: composition: vms host/passwd component |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2653 ++components; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2654 p = getnextcomp(p + 2); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2655 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2656 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2657 # endif |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2658 if (vim_ispathsep(*p)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2659 STRMOVE(p, p + 1); // remove duplicate "/" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2660 else if (p[0] == '.' && (vim_ispathsep(p[1]) || p[1] == NUL)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2661 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2662 if (p == start && relative) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2663 p += 1 + (p[1] != NUL); // keep single "." or leading "./" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2664 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2665 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2666 // Strip "./" or ".///". If we are at the end of the file name |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2667 // and there is no trailing path separator, either strip "/." if |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2668 // we are after "start", or strip "." if we are at the beginning |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2669 // of an absolute path name . |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2670 tail = p + 1; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2671 if (p[1] != NUL) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2672 while (vim_ispathsep(*tail)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2673 MB_PTR_ADV(tail); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2674 else if (p > start) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2675 --p; // strip preceding path separator |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2676 STRMOVE(p, tail); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2677 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2678 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2679 else if (p[0] == '.' && p[1] == '.' && |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2680 (vim_ispathsep(p[2]) || p[2] == NUL)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2681 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2682 // Skip to after ".." or "../" or "..///". |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2683 tail = p + 2; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2684 while (vim_ispathsep(*tail)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2685 MB_PTR_ADV(tail); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2686 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2687 if (components > 0) // strip one preceding component |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2688 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2689 int do_strip = FALSE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2690 char_u saved_char; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2691 stat_T st; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2692 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2693 /* Don't strip for an erroneous file name. */ |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2694 if (!stripping_disabled) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2695 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2696 // If the preceding component does not exist in the file |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2697 // system, we strip it. On Unix, we don't accept a symbolic |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2698 // link that refers to a non-existent file. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2699 saved_char = p[-1]; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2700 p[-1] = NUL; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2701 # ifdef UNIX |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2702 if (mch_lstat((char *)filename, &st) < 0) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2703 # else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2704 if (mch_stat((char *)filename, &st) < 0) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2705 # endif |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2706 do_strip = TRUE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2707 p[-1] = saved_char; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2708 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2709 --p; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2710 // Skip back to after previous '/'. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2711 while (p > start && !after_pathsep(start, p)) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2712 MB_PTR_BACK(start, p); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2713 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2714 if (!do_strip) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2715 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2716 // If the component exists in the file system, check |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2717 // that stripping it won't change the meaning of the |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2718 // file name. First get information about the |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2719 // unstripped file name. This may fail if the component |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2720 // to strip is not a searchable directory (but a regular |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2721 // file, for instance), since the trailing "/.." cannot |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2722 // be applied then. We don't strip it then since we |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2723 // don't want to replace an erroneous file name by |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2724 // a valid one, and we disable stripping of later |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2725 // components. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2726 saved_char = *tail; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2727 *tail = NUL; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2728 if (mch_stat((char *)filename, &st) >= 0) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2729 do_strip = TRUE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2730 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2731 stripping_disabled = TRUE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2732 *tail = saved_char; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2733 # ifdef UNIX |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2734 if (do_strip) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2735 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2736 stat_T new_st; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2737 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2738 // On Unix, the check for the unstripped file name |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2739 // above works also for a symbolic link pointing to |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2740 // a searchable directory. But then the parent of |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2741 // the directory pointed to by the link must be the |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2742 // same as the stripped file name. (The latter |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2743 // exists in the file system since it is the |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2744 // component's parent directory.) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2745 if (p == start && relative) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2746 (void)mch_stat(".", &new_st); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2747 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2748 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2749 saved_char = *p; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2750 *p = NUL; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2751 (void)mch_stat((char *)filename, &new_st); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2752 *p = saved_char; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2753 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2754 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2755 if (new_st.st_ino != st.st_ino || |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2756 new_st.st_dev != st.st_dev) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2757 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2758 do_strip = FALSE; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2759 // We don't disable stripping of later |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2760 // components since the unstripped path name is |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2761 // still valid. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2762 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2763 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2764 # endif |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2765 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2766 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2767 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2768 if (!do_strip) |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2769 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2770 // Skip the ".." or "../" and reset the counter for the |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2771 // components that might be stripped later on. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2772 p = tail; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2773 components = 0; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2774 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2775 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2776 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2777 // Strip previous component. If the result would get empty |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2778 // and there is no trailing path separator, leave a single |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2779 // "." instead. If we are at the end of the file name and |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2780 // there is no trailing path separator and a preceding |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2781 // component is left after stripping, strip its trailing |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2782 // path separator as well. |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2783 if (p == start && relative && tail[-1] == '.') |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2784 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2785 *p++ = '.'; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2786 *p = NUL; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2787 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2788 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2789 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2790 if (p > start && tail[-1] == '.') |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2791 --p; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2792 STRMOVE(p, tail); // strip previous component |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2793 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2794 |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2795 --components; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2796 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2797 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2798 else if (p == start && !relative) // leading "/.." or "/../" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2799 STRMOVE(p, tail); // strip ".." or "../" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2800 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2801 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2802 if (p == start + 2 && p[-2] == '.') // leading "./../" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2803 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2804 STRMOVE(p - 2, p); // strip leading "./" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2805 tail -= 2; |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2806 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2807 p = tail; // skip to char after ".." or "../" |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2808 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2809 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2810 else |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2811 { |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2812 ++components; // simple path component |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2813 p = getnextcomp(p); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2814 } |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2815 } while (*p != NUL); |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2816 #endif // !AMIGA |
848d4c6e391e
patch 8.1.1099: the do_tag() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
15993
diff
changeset
|
2817 } |