Mercurial > vim
annotate src/tag.c @ 10603:df1abc85b169 v8.0.0191
patch 8.0.0191: can't build with Ruby on some systems
commit https://github.com/vim/vim/commit/4f391796b7de78a434a2cc7107034603df414905
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 15 16:59:07 2017 +0100
patch 8.0.0191: can't build with Ruby on some systems
Problem: Some systems do not have ruby_sysinit(), causing the build to
fail.
Solution: Clean up how ruby_sysinit() and NtInitialize() are used. (Taro
Muraoka)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 15 Jan 2017 17:00:05 +0100 |
parents | 1b09db809d3f |
children | 6bff81438f27 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9949
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Code to handle tags and the tag stack | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * Structure to hold pointers to various items in a tag line. | |
18 */ | |
19 typedef struct tag_pointers | |
20 { | |
21 /* filled in by parse_tag_line(): */ | |
22 char_u *tagname; /* start of tag name (skip "file:") */ | |
23 char_u *tagname_end; /* char after tag name */ | |
24 char_u *fname; /* first char of file name */ | |
25 char_u *fname_end; /* char after file name */ | |
26 char_u *command; /* first char of command */ | |
27 /* filled in by parse_match(): */ | |
28 char_u *command_end; /* first char after command */ | |
29 char_u *tag_fname; /* file name of the tags file */ | |
30 #ifdef FEAT_EMACS_TAGS | |
31 int is_etag; /* TRUE for emacs tag */ | |
32 #endif | |
33 char_u *tagkind; /* "kind:" value */ | |
34 char_u *tagkind_end; /* end of tagkind */ | |
35 } tagptrs_T; | |
36 | |
37 /* | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
38 * The matching tags are first stored in one of the ht_match[] hash tables. In |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
39 * which one depends on the priority of the match. |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
40 * At the end, all the matches from ht_match[] are concatenated, to make a list |
7 | 41 * sorted on priority. |
42 */ | |
43 #define MT_ST_CUR 0 /* static match in current file */ | |
44 #define MT_GL_CUR 1 /* global match in current file */ | |
45 #define MT_GL_OTH 2 /* global match in other file */ | |
46 #define MT_ST_OTH 3 /* static match in other file */ | |
47 #define MT_IC_ST_CUR 4 /* icase static match in current file */ | |
48 #define MT_IC_GL_CUR 5 /* icase global match in current file */ | |
49 #define MT_IC_GL_OTH 6 /* icase global match in other file */ | |
50 #define MT_IC_ST_OTH 7 /* icase static match in other file */ | |
51 #define MT_IC_OFF 4 /* add for icase match */ | |
52 #define MT_RE_OFF 8 /* add for regexp match */ | |
53 #define MT_MASK 7 /* mask for printing priority */ | |
54 #define MT_COUNT 16 | |
55 | |
56 static char *mt_names[MT_COUNT/2] = | |
57 {"FSC", "F C", "F ", "FS ", " SC", " C", " ", " S "}; | |
58 | |
59 #define NOTAGFILE 99 /* return value for jumpto_tag */ | |
60 static char_u *nofile_fname = NULL; /* fname for NOTAGFILE error */ | |
61 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
62 static void taglen_advance(int l); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
63 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
64 static int jumpto_tag(char_u *lbuf, int forceit, int keep_help); |
7 | 65 #ifdef FEAT_EMACS_TAGS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
66 static int parse_tag_line(char_u *lbuf, int is_etag, tagptrs_T *tagp); |
7 | 67 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
68 static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp); |
7 | 69 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
70 static int test_for_static(tagptrs_T *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
71 static int parse_match(char_u *lbuf, tagptrs_T *tagp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
72 static char_u *tag_full_fname(tagptrs_T *tagp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
73 static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand); |
7 | 74 #ifdef FEAT_EMACS_TAGS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
75 static int test_for_current(int, char_u *, char_u *, char_u *, char_u *); |
7 | 76 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
77 static int test_for_current(char_u *, char_u *, char_u *, char_u *); |
7 | 78 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
79 static int find_extra(char_u **pp); |
7 | 80 |
81 static char_u *bottommsg = (char_u *)N_("E555: at bottom of tag stack"); | |
82 static char_u *topmsg = (char_u *)N_("E556: at top of tag stack"); | |
83 | |
84 static char_u *tagmatchname = NULL; /* name of last used tag */ | |
85 | |
86 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
87 /* | |
88 * Tag for preview window is remembered separately, to avoid messing up the | |
89 * normal tagstack. | |
90 */ | |
1883 | 91 static taggy_T ptag_entry = {NULL, {INIT_POS_T(0, 0, 0), 0}, 0, 0}; |
7 | 92 #endif |
93 | |
94 /* | |
95 * Jump to tag; handling of tag commands and tag stack | |
96 * | |
97 * *tag != NUL: ":tag {tag}", jump to new tag, add to tag stack | |
98 * | |
99 * type == DT_TAG: ":tag [tag]", jump to newer position or same tag again | |
100 * type == DT_HELP: like DT_TAG, but don't use regexp. | |
101 * type == DT_POP: ":pop" or CTRL-T, jump to old position | |
102 * type == DT_NEXT: jump to next match of same tag | |
103 * type == DT_PREV: jump to previous match of same tag | |
104 * type == DT_FIRST: jump to first match of same tag | |
105 * type == DT_LAST: jump to last match of same tag | |
106 * type == DT_SELECT: ":tselect [tag]", select tag from a list of all matches | |
107 * type == DT_JUMP: ":tjump [tag]", jump to tag or select tag from a list | |
359 | 108 * type == DT_CSCOPE: use cscope to find the tag |
649 | 109 * type == DT_LTAG: use location list for displaying tag matches |
359 | 110 * type == DT_FREE: free cached matches |
7 | 111 * |
112 * for cscope, returns TRUE if we jumped to tag or aborted, FALSE otherwise | |
113 */ | |
114 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
115 do_tag( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
116 char_u *tag, /* tag (pattern) to jump to */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
117 int type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
118 int count, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
119 int forceit, /* :ta with ! */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
120 int verbose) /* print "tag not found" message */ |
7 | 121 { |
122 taggy_T *tagstack = curwin->w_tagstack; | |
123 int tagstackidx = curwin->w_tagstackidx; | |
124 int tagstacklen = curwin->w_tagstacklen; | |
125 int cur_match = 0; | |
126 int cur_fnum = curbuf->b_fnum; | |
127 int oldtagstackidx = tagstackidx; | |
128 int prevtagstackidx = tagstackidx; | |
129 int prev_num_matches; | |
130 int new_tag = FALSE; | |
131 int other_name; | |
132 int i, j, k; | |
133 int idx; | |
134 int ic; | |
135 char_u *p; | |
136 char_u *name; | |
137 int no_regexp = FALSE; | |
138 int error_cur_match = 0; | |
139 char_u *command_end; | |
140 int save_pos = FALSE; | |
141 fmark_T saved_fmark; | |
142 int taglen; | |
143 #ifdef FEAT_CSCOPE | |
144 int jumped_to_tag = FALSE; | |
145 #endif | |
146 tagptrs_T tagp, tagp2; | |
147 int new_num_matches; | |
148 char_u **new_matches; | |
149 int attr; | |
150 int use_tagstack; | |
151 int skip_msg = FALSE; | |
152 char_u *buf_ffname = curbuf->b_ffname; /* name to use for | |
153 priority computation */ | |
154 | |
155 /* remember the matches for the last used tag */ | |
156 static int num_matches = 0; | |
157 static int max_num_matches = 0; /* limit used for match search */ | |
158 static char_u **matches = NULL; | |
159 static int flags; | |
160 | |
359 | 161 #ifdef EXITFREE |
162 if (type == DT_FREE) | |
163 { | |
164 /* remove the list of matches */ | |
165 FreeWild(num_matches, matches); | |
166 # ifdef FEAT_CSCOPE | |
167 cs_free_tags(); | |
168 # endif | |
169 num_matches = 0; | |
170 return FALSE; | |
171 } | |
172 #endif | |
173 | |
7 | 174 if (type == DT_HELP) |
175 { | |
176 type = DT_TAG; | |
177 no_regexp = TRUE; | |
178 } | |
179 | |
180 prev_num_matches = num_matches; | |
181 free_string_option(nofile_fname); | |
182 nofile_fname = NULL; | |
183 | |
698 | 184 clearpos(&saved_fmark.mark); /* shutup gcc 4.0 */ |
185 saved_fmark.fnum = 0; | |
186 | |
7 | 187 /* |
188 * Don't add a tag to the tagstack if 'tagstack' has been reset. | |
189 */ | |
190 if ((!p_tgst && *tag != NUL)) | |
191 { | |
192 use_tagstack = FALSE; | |
193 new_tag = TRUE; | |
8930
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
194 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
195 if (g_do_tagpreview != 0) |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
196 { |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
197 vim_free(ptag_entry.tagname); |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
198 if ((ptag_entry.tagname = vim_strsave(tag)) == NULL) |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
199 goto end_do_tag; |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
200 } |
a2aca019ba48
commit https://github.com/vim/vim/commit/def5abe0a2727041ecee69afdccfca405333bd24
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
201 #endif |
7 | 202 } |
203 else | |
204 { | |
205 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 206 if (g_do_tagpreview != 0) |
7 | 207 use_tagstack = FALSE; |
208 else | |
209 #endif | |
210 use_tagstack = TRUE; | |
211 | |
212 /* new pattern, add to the tag stack */ | |
845 | 213 if (*tag != NUL |
214 && (type == DT_TAG || type == DT_SELECT || type == DT_JUMP | |
649 | 215 #ifdef FEAT_QUICKFIX |
216 || type == DT_LTAG | |
217 #endif | |
7 | 218 #ifdef FEAT_CSCOPE |
219 || type == DT_CSCOPE | |
220 #endif | |
221 )) | |
222 { | |
223 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 224 if (g_do_tagpreview != 0) |
7 | 225 { |
226 if (ptag_entry.tagname != NULL | |
227 && STRCMP(ptag_entry.tagname, tag) == 0) | |
228 { | |
229 /* Jumping to same tag: keep the current match, so that | |
230 * the CursorHold autocommand example works. */ | |
231 cur_match = ptag_entry.cur_match; | |
232 cur_fnum = ptag_entry.cur_fnum; | |
233 } | |
234 else | |
235 { | |
236 vim_free(ptag_entry.tagname); | |
237 if ((ptag_entry.tagname = vim_strsave(tag)) == NULL) | |
238 goto end_do_tag; | |
239 } | |
240 } | |
241 else | |
242 #endif | |
243 { | |
244 /* | |
245 * If the last used entry is not at the top, delete all tag | |
246 * stack entries above it. | |
247 */ | |
248 while (tagstackidx < tagstacklen) | |
249 vim_free(tagstack[--tagstacklen].tagname); | |
250 | |
251 /* if the tagstack is full: remove oldest entry */ | |
252 if (++tagstacklen > TAGSTACKSIZE) | |
253 { | |
254 tagstacklen = TAGSTACKSIZE; | |
255 vim_free(tagstack[0].tagname); | |
256 for (i = 1; i < tagstacklen; ++i) | |
257 tagstack[i - 1] = tagstack[i]; | |
258 --tagstackidx; | |
259 } | |
260 | |
261 /* | |
262 * put the tag name in the tag stack | |
263 */ | |
264 if ((tagstack[tagstackidx].tagname = vim_strsave(tag)) == NULL) | |
265 { | |
266 curwin->w_tagstacklen = tagstacklen - 1; | |
267 goto end_do_tag; | |
268 } | |
269 curwin->w_tagstacklen = tagstacklen; | |
270 | |
271 save_pos = TRUE; /* save the cursor position below */ | |
272 } | |
273 | |
274 new_tag = TRUE; | |
275 } | |
276 else | |
277 { | |
278 if ( | |
279 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 280 g_do_tagpreview != 0 ? ptag_entry.tagname == NULL : |
7 | 281 #endif |
282 tagstacklen == 0) | |
283 { | |
284 /* empty stack */ | |
285 EMSG(_(e_tagstack)); | |
286 goto end_do_tag; | |
287 } | |
288 | |
289 if (type == DT_POP) /* go to older position */ | |
290 { | |
291 #ifdef FEAT_FOLDING | |
292 int old_KeyTyped = KeyTyped; | |
293 #endif | |
294 if ((tagstackidx -= count) < 0) | |
295 { | |
296 EMSG(_(bottommsg)); | |
297 if (tagstackidx + count == 0) | |
298 { | |
299 /* We did [num]^T from the bottom of the stack */ | |
300 tagstackidx = 0; | |
301 goto end_do_tag; | |
302 } | |
303 /* We weren't at the bottom of the stack, so jump all the | |
304 * way to the bottom now. | |
305 */ | |
306 tagstackidx = 0; | |
307 } | |
308 else if (tagstackidx >= tagstacklen) /* count == 0? */ | |
309 { | |
310 EMSG(_(topmsg)); | |
311 goto end_do_tag; | |
312 } | |
313 | |
314 /* Make a copy of the fmark, autocommands may invalidate the | |
315 * tagstack before it's used. */ | |
316 saved_fmark = tagstack[tagstackidx].fmark; | |
317 if (saved_fmark.fnum != curbuf->b_fnum) | |
318 { | |
319 /* | |
320 * Jump to other file. If this fails (e.g. because the | |
321 * file was changed) keep original position in tag stack. | |
322 */ | |
323 if (buflist_getfile(saved_fmark.fnum, saved_fmark.mark.lnum, | |
324 GETF_SETMARK, forceit) == FAIL) | |
325 { | |
326 tagstackidx = oldtagstackidx; /* back to old posn */ | |
327 goto end_do_tag; | |
328 } | |
329 /* An BufReadPost autocommand may jump to the '" mark, but | |
330 * we don't what that here. */ | |
331 curwin->w_cursor.lnum = saved_fmark.mark.lnum; | |
332 } | |
333 else | |
334 { | |
335 setpcmark(); | |
336 curwin->w_cursor.lnum = saved_fmark.mark.lnum; | |
337 } | |
338 curwin->w_cursor.col = saved_fmark.mark.col; | |
339 curwin->w_set_curswant = TRUE; | |
340 check_cursor(); | |
341 #ifdef FEAT_FOLDING | |
342 if ((fdo_flags & FDO_TAG) && old_KeyTyped) | |
343 foldOpenCursor(); | |
344 #endif | |
345 | |
346 /* remove the old list of matches */ | |
347 FreeWild(num_matches, matches); | |
348 #ifdef FEAT_CSCOPE | |
349 cs_free_tags(); | |
350 #endif | |
351 num_matches = 0; | |
845 | 352 tag_freematch(); |
7 | 353 goto end_do_tag; |
354 } | |
355 | |
692 | 356 if (type == DT_TAG |
357 #if defined(FEAT_QUICKFIX) | |
845 | 358 || type == DT_LTAG |
692 | 359 #endif |
845 | 360 ) |
7 | 361 { |
362 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 363 if (g_do_tagpreview != 0) |
7 | 364 { |
365 cur_match = ptag_entry.cur_match; | |
366 cur_fnum = ptag_entry.cur_fnum; | |
367 } | |
368 else | |
369 #endif | |
370 { | |
371 /* ":tag" (no argument): go to newer pattern */ | |
372 save_pos = TRUE; /* save the cursor position below */ | |
373 if ((tagstackidx += count - 1) >= tagstacklen) | |
374 { | |
375 /* | |
376 * Beyond the last one, just give an error message and | |
377 * go to the last one. Don't store the cursor | |
1204 | 378 * position. |
7 | 379 */ |
380 tagstackidx = tagstacklen - 1; | |
381 EMSG(_(topmsg)); | |
382 save_pos = FALSE; | |
383 } | |
384 else if (tagstackidx < 0) /* must have been count == 0 */ | |
385 { | |
386 EMSG(_(bottommsg)); | |
387 tagstackidx = 0; | |
388 goto end_do_tag; | |
389 } | |
390 cur_match = tagstack[tagstackidx].cur_match; | |
391 cur_fnum = tagstack[tagstackidx].cur_fnum; | |
392 } | |
393 new_tag = TRUE; | |
394 } | |
395 else /* go to other matching tag */ | |
396 { | |
397 /* Save index for when selection is cancelled. */ | |
398 prevtagstackidx = tagstackidx; | |
399 | |
400 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 401 if (g_do_tagpreview != 0) |
7 | 402 { |
403 cur_match = ptag_entry.cur_match; | |
404 cur_fnum = ptag_entry.cur_fnum; | |
405 } | |
406 else | |
407 #endif | |
408 { | |
409 if (--tagstackidx < 0) | |
410 tagstackidx = 0; | |
411 cur_match = tagstack[tagstackidx].cur_match; | |
412 cur_fnum = tagstack[tagstackidx].cur_fnum; | |
413 } | |
414 switch (type) | |
415 { | |
416 case DT_FIRST: cur_match = count - 1; break; | |
417 case DT_SELECT: | |
418 case DT_JUMP: | |
419 #ifdef FEAT_CSCOPE | |
420 case DT_CSCOPE: | |
421 #endif | |
422 case DT_LAST: cur_match = MAXCOL - 1; break; | |
423 case DT_NEXT: cur_match += count; break; | |
424 case DT_PREV: cur_match -= count; break; | |
425 } | |
426 if (cur_match >= MAXCOL) | |
427 cur_match = MAXCOL - 1; | |
428 else if (cur_match < 0) | |
429 { | |
430 EMSG(_("E425: Cannot go before first matching tag")); | |
431 skip_msg = TRUE; | |
432 cur_match = 0; | |
433 cur_fnum = curbuf->b_fnum; | |
434 } | |
435 } | |
436 } | |
437 | |
438 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 439 if (g_do_tagpreview != 0) |
7 | 440 { |
441 if (type != DT_SELECT && type != DT_JUMP) | |
442 { | |
443 ptag_entry.cur_match = cur_match; | |
444 ptag_entry.cur_fnum = cur_fnum; | |
445 } | |
446 } | |
447 else | |
448 #endif | |
449 { | |
450 /* | |
451 * For ":tag [arg]" or ":tselect" remember position before the jump. | |
452 */ | |
453 saved_fmark = tagstack[tagstackidx].fmark; | |
454 if (save_pos) | |
455 { | |
456 tagstack[tagstackidx].fmark.mark = curwin->w_cursor; | |
457 tagstack[tagstackidx].fmark.fnum = curbuf->b_fnum; | |
458 } | |
459 | |
460 /* Curwin will change in the call to jumpto_tag() if ":stag" was | |
461 * used or an autocommand jumps to another window; store value of | |
462 * tagstackidx now. */ | |
463 curwin->w_tagstackidx = tagstackidx; | |
464 if (type != DT_SELECT && type != DT_JUMP) | |
465 { | |
466 curwin->w_tagstack[tagstackidx].cur_match = cur_match; | |
467 curwin->w_tagstack[tagstackidx].cur_fnum = cur_fnum; | |
468 } | |
469 } | |
470 } | |
471 | |
472 /* When not using the current buffer get the name of buffer "cur_fnum". | |
473 * Makes sure that the tag order doesn't change when using a remembered | |
474 * position for "cur_match". */ | |
475 if (cur_fnum != curbuf->b_fnum) | |
476 { | |
477 buf_T *buf = buflist_findnr(cur_fnum); | |
478 | |
479 if (buf != NULL) | |
480 buf_ffname = buf->b_ffname; | |
481 } | |
482 | |
483 /* | |
484 * Repeat searching for tags, when a file has not been found. | |
485 */ | |
486 for (;;) | |
487 { | |
488 /* | |
489 * When desired match not found yet, try to find it (and others). | |
490 */ | |
491 if (use_tagstack) | |
492 name = tagstack[tagstackidx].tagname; | |
493 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 494 else if (g_do_tagpreview != 0) |
7 | 495 name = ptag_entry.tagname; |
496 #endif | |
497 else | |
498 name = tag; | |
499 other_name = (tagmatchname == NULL || STRCMP(tagmatchname, name) != 0); | |
500 if (new_tag | |
501 || (cur_match >= num_matches && max_num_matches != MAXCOL) | |
502 || other_name) | |
503 { | |
504 if (other_name) | |
505 { | |
506 vim_free(tagmatchname); | |
507 tagmatchname = vim_strsave(name); | |
508 } | |
509 | |
6851 | 510 if (type == DT_TAG || type == DT_SELECT || type == DT_JUMP |
692 | 511 #if defined(FEAT_QUICKFIX) |
512 || type == DT_LTAG | |
513 #endif | |
514 ) | |
7 | 515 cur_match = MAXCOL - 1; |
516 max_num_matches = cur_match + 1; | |
517 | |
518 /* when the argument starts with '/', use it as a regexp */ | |
519 if (!no_regexp && *name == '/') | |
520 { | |
521 flags = TAG_REGEXP; | |
522 ++name; | |
523 } | |
524 else | |
525 flags = TAG_NOIC; | |
526 | |
527 #ifdef FEAT_CSCOPE | |
528 if (type == DT_CSCOPE) | |
529 flags = TAG_CSCOPE; | |
530 #endif | |
531 if (verbose) | |
532 flags |= TAG_VERBOSE; | |
533 if (find_tags(name, &new_num_matches, &new_matches, flags, | |
534 max_num_matches, buf_ffname) == OK | |
535 && new_num_matches < max_num_matches) | |
536 max_num_matches = MAXCOL; /* If less than max_num_matches | |
537 found: all matches found. */ | |
538 | |
539 /* If there already were some matches for the same name, move them | |
540 * to the start. Avoids that the order changes when using | |
541 * ":tnext" and jumping to another file. */ | |
542 if (!new_tag && !other_name) | |
543 { | |
544 /* Find the position of each old match in the new list. Need | |
545 * to use parse_match() to find the tag line. */ | |
546 idx = 0; | |
547 for (j = 0; j < num_matches; ++j) | |
548 { | |
549 parse_match(matches[j], &tagp); | |
550 for (i = idx; i < new_num_matches; ++i) | |
551 { | |
552 parse_match(new_matches[i], &tagp2); | |
553 if (STRCMP(tagp.tagname, tagp2.tagname) == 0) | |
554 { | |
555 p = new_matches[i]; | |
556 for (k = i; k > idx; --k) | |
557 new_matches[k] = new_matches[k - 1]; | |
558 new_matches[idx++] = p; | |
559 break; | |
560 } | |
561 } | |
562 } | |
563 } | |
564 FreeWild(num_matches, matches); | |
565 num_matches = new_num_matches; | |
566 matches = new_matches; | |
567 } | |
568 | |
569 if (num_matches <= 0) | |
570 { | |
571 if (verbose) | |
572 EMSG2(_("E426: tag not found: %s"), name); | |
573 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
574 g_do_tagpreview = 0; | |
575 #endif | |
576 } | |
577 else | |
578 { | |
579 int ask_for_selection = FALSE; | |
580 | |
581 #ifdef FEAT_CSCOPE | |
582 if (type == DT_CSCOPE && num_matches > 1) | |
583 { | |
584 cs_print_tags(); | |
585 ask_for_selection = TRUE; | |
586 } | |
587 else | |
588 #endif | |
6851 | 589 if (type == DT_TAG) |
590 /* | |
591 * If a count is supplied to the ":tag <name>" command, then | |
592 * jump to count'th matching tag. | |
593 */ | |
594 cur_match = count > 0 ? count - 1 : 0; | |
595 else if (type == DT_SELECT || (type == DT_JUMP && num_matches > 1)) | |
7 | 596 { |
597 /* | |
598 * List all the matching tags. | |
599 * Assume that the first match indicates how long the tags can | |
600 * be, and align the file names to that. | |
601 */ | |
602 parse_match(matches[0], &tagp); | |
603 taglen = (int)(tagp.tagname_end - tagp.tagname + 2); | |
604 if (taglen < 18) | |
605 taglen = 18; | |
606 if (taglen > Columns - 25) | |
607 taglen = MAXCOL; | |
608 if (msg_col == 0) | |
609 msg_didout = FALSE; /* overwrite previous message */ | |
610 msg_start(); | |
611 MSG_PUTS_ATTR(_(" # pri kind tag"), hl_attr(HLF_T)); | |
612 msg_clr_eos(); | |
613 taglen_advance(taglen); | |
614 MSG_PUTS_ATTR(_("file\n"), hl_attr(HLF_T)); | |
615 | |
1826 | 616 for (i = 0; i < num_matches && !got_int; ++i) |
7 | 617 { |
618 parse_match(matches[i], &tagp); | |
619 if (!new_tag && ( | |
620 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 621 (g_do_tagpreview != 0 |
7 | 622 && i == ptag_entry.cur_match) || |
623 #endif | |
624 (use_tagstack | |
625 && i == tagstack[tagstackidx].cur_match))) | |
626 *IObuff = '>'; | |
627 else | |
628 *IObuff = ' '; | |
273 | 629 vim_snprintf((char *)IObuff + 1, IOSIZE - 1, |
630 "%2d %s ", i + 1, | |
7 | 631 mt_names[matches[i][0] & MT_MASK]); |
632 msg_puts(IObuff); | |
633 if (tagp.tagkind != NULL) | |
634 msg_outtrans_len(tagp.tagkind, | |
635 (int)(tagp.tagkind_end - tagp.tagkind)); | |
636 msg_advance(13); | |
637 msg_outtrans_len_attr(tagp.tagname, | |
638 (int)(tagp.tagname_end - tagp.tagname), | |
639 hl_attr(HLF_T)); | |
640 msg_putchar(' '); | |
641 taglen_advance(taglen); | |
642 | |
643 /* Find out the actual file name. If it is long, truncate | |
644 * it and put "..." in the middle */ | |
645 p = tag_full_fname(&tagp); | |
646 if (p != NULL) | |
647 { | |
648 msg_puts_long_attr(p, hl_attr(HLF_D)); | |
649 vim_free(p); | |
650 } | |
651 if (msg_col > 0) | |
652 msg_putchar('\n'); | |
1826 | 653 if (got_int) |
654 break; | |
7 | 655 msg_advance(15); |
656 | |
657 /* print any extra fields */ | |
658 command_end = tagp.command_end; | |
659 if (command_end != NULL) | |
660 { | |
661 p = command_end + 3; | |
662 while (*p && *p != '\r' && *p != '\n') | |
663 { | |
664 while (*p == TAB) | |
665 ++p; | |
666 | |
667 /* skip "file:" without a value (static tag) */ | |
668 if (STRNCMP(p, "file:", 5) == 0 | |
669 && vim_isspace(p[5])) | |
670 { | |
671 p += 5; | |
672 continue; | |
673 } | |
674 /* skip "kind:<kind>" and "<kind>" */ | |
675 if (p == tagp.tagkind | |
676 || (p + 5 == tagp.tagkind | |
677 && STRNCMP(p, "kind:", 5) == 0)) | |
678 { | |
679 p = tagp.tagkind_end; | |
680 continue; | |
681 } | |
682 /* print all other extra fields */ | |
683 attr = hl_attr(HLF_CM); | |
684 while (*p && *p != '\r' && *p != '\n') | |
685 { | |
686 if (msg_col + ptr2cells(p) >= Columns) | |
687 { | |
688 msg_putchar('\n'); | |
1826 | 689 if (got_int) |
690 break; | |
7 | 691 msg_advance(15); |
692 } | |
693 p = msg_outtrans_one(p, attr); | |
694 if (*p == TAB) | |
695 { | |
696 msg_puts_attr((char_u *)" ", attr); | |
697 break; | |
698 } | |
699 if (*p == ':') | |
700 attr = 0; | |
701 } | |
702 } | |
703 if (msg_col > 15) | |
704 { | |
705 msg_putchar('\n'); | |
1826 | 706 if (got_int) |
707 break; | |
7 | 708 msg_advance(15); |
709 } | |
710 } | |
711 else | |
712 { | |
713 for (p = tagp.command; | |
714 *p && *p != '\r' && *p != '\n'; ++p) | |
715 ; | |
716 command_end = p; | |
717 } | |
718 | |
719 /* | |
720 * Put the info (in several lines) at column 15. | |
721 * Don't display "/^" and "?^". | |
722 */ | |
723 p = tagp.command; | |
724 if (*p == '/' || *p == '?') | |
725 { | |
726 ++p; | |
727 if (*p == '^') | |
728 ++p; | |
729 } | |
730 /* Remove leading whitespace from pattern */ | |
731 while (p != command_end && vim_isspace(*p)) | |
732 ++p; | |
733 | |
734 while (p != command_end) | |
735 { | |
736 if (msg_col + (*p == TAB ? 1 : ptr2cells(p)) > Columns) | |
737 msg_putchar('\n'); | |
1826 | 738 if (got_int) |
739 break; | |
7 | 740 msg_advance(15); |
741 | |
5792 | 742 /* skip backslash used for escaping a command char or |
743 * a backslash */ | |
744 if (*p == '\\' && (*(p + 1) == *tagp.command | |
10444
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
745 || *(p + 1) == '\\')) |
7 | 746 ++p; |
747 | |
748 if (*p == TAB) | |
749 { | |
750 msg_putchar(' '); | |
751 ++p; | |
752 } | |
753 else | |
754 p = msg_outtrans_one(p, 0); | |
755 | |
756 /* don't display the "$/;\"" and "$?;\"" */ | |
757 if (p == command_end - 2 && *p == '$' | |
758 && *(p + 1) == *tagp.command) | |
759 break; | |
760 /* don't display matching '/' or '?' */ | |
761 if (p == command_end - 1 && *p == *tagp.command | |
762 && (*p == '/' || *p == '?')) | |
763 break; | |
764 } | |
765 if (msg_col) | |
766 msg_putchar('\n'); | |
767 ui_breakcheck(); | |
768 } | |
1826 | 769 if (got_int) |
770 got_int = FALSE; /* only stop the listing */ | |
7 | 771 ask_for_selection = TRUE; |
772 } | |
649 | 773 #if defined(FEAT_QUICKFIX) && defined(FEAT_EVAL) |
692 | 774 else if (type == DT_LTAG) |
649 | 775 { |
776 list_T *list; | |
777 char_u tag_name[128 + 1]; | |
2770 | 778 char_u *fname; |
779 char_u *cmd; | |
649 | 780 |
781 /* | |
782 * Add the matching tags to the location list for the current | |
783 * window. | |
784 */ | |
785 | |
2770 | 786 fname = alloc(MAXPATHL + 1); |
787 cmd = alloc(CMDBUFFSIZE + 1); | |
649 | 788 list = list_alloc(); |
2770 | 789 if (list == NULL || fname == NULL || cmd == NULL) |
790 { | |
791 vim_free(cmd); | |
792 vim_free(fname); | |
793 if (list != NULL) | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
794 list_free(list); |
649 | 795 goto end_do_tag; |
2770 | 796 } |
649 | 797 |
798 for (i = 0; i < num_matches; ++i) | |
799 { | |
800 int len, cmd_len; | |
801 long lnum; | |
802 dict_T *dict; | |
803 | |
804 parse_match(matches[i], &tagp); | |
805 | |
806 /* Save the tag name */ | |
835 | 807 len = (int)(tagp.tagname_end - tagp.tagname); |
649 | 808 if (len > 128) |
809 len = 128; | |
810 vim_strncpy(tag_name, tagp.tagname, len); | |
811 tag_name[len] = NUL; | |
812 | |
813 /* Save the tag file name */ | |
814 p = tag_full_fname(&tagp); | |
815 if (p == NULL) | |
816 continue; | |
2768 | 817 vim_strncpy(fname, p, MAXPATHL); |
649 | 818 vim_free(p); |
819 | |
820 /* | |
821 * Get the line number or the search pattern used to locate | |
822 * the tag. | |
823 */ | |
824 lnum = 0; | |
825 if (isdigit(*tagp.command)) | |
826 /* Line number is used to locate the tag */ | |
827 lnum = atol((char *)tagp.command); | |
828 else | |
829 { | |
830 char_u *cmd_start, *cmd_end; | |
831 | |
832 /* Search pattern is used to locate the tag */ | |
833 | |
834 /* Locate the end of the command */ | |
835 cmd_start = tagp.command; | |
836 cmd_end = tagp.command_end; | |
837 if (cmd_end == NULL) | |
838 { | |
839 for (p = tagp.command; | |
840 *p && *p != '\r' && *p != '\n'; ++p) | |
841 ; | |
842 cmd_end = p; | |
843 } | |
692 | 844 |
649 | 845 /* |
846 * Now, cmd_end points to the character after the | |
847 * command. Adjust it to point to the last | |
848 * character of the command. | |
849 */ | |
850 cmd_end--; | |
851 | |
852 /* | |
853 * Skip the '/' and '?' characters at the | |
854 * beginning and end of the search pattern. | |
855 */ | |
856 if (*cmd_start == '/' || *cmd_start == '?') | |
857 cmd_start++; | |
858 | |
859 if (*cmd_end == '/' || *cmd_end == '?') | |
860 cmd_end--; | |
861 | |
862 len = 0; | |
863 cmd[0] = NUL; | |
864 | |
865 /* | |
866 * If "^" is present in the tag search pattern, then | |
867 * copy it first. | |
868 */ | |
869 if (*cmd_start == '^') | |
870 { | |
871 STRCPY(cmd, "^"); | |
872 cmd_start++; | |
873 len++; | |
874 } | |
875 | |
876 /* | |
877 * Precede the tag pattern with \V to make it very | |
878 * nomagic. | |
879 */ | |
880 STRCAT(cmd, "\\V"); | |
881 len += 2; | |
882 | |
835 | 883 cmd_len = (int)(cmd_end - cmd_start + 1); |
649 | 884 if (cmd_len > (CMDBUFFSIZE - 5)) |
885 cmd_len = CMDBUFFSIZE - 5; | |
886 STRNCAT(cmd, cmd_start, cmd_len); | |
887 len += cmd_len; | |
888 | |
889 if (cmd[len - 1] == '$') | |
890 { | |
692 | 891 /* |
649 | 892 * Replace '$' at the end of the search pattern |
893 * with '\$' | |
894 */ | |
895 cmd[len - 1] = '\\'; | |
896 cmd[len] = '$'; | |
897 len++; | |
898 } | |
899 | |
900 cmd[len] = NUL; | |
901 } | |
902 | |
903 if ((dict = dict_alloc()) == NULL) | |
904 continue; | |
905 if (list_append_dict(list, dict) == FAIL) | |
906 { | |
907 vim_free(dict); | |
908 continue; | |
909 } | |
910 | |
911 dict_add_nr_str(dict, "text", 0L, tag_name); | |
912 dict_add_nr_str(dict, "filename", 0L, fname); | |
913 dict_add_nr_str(dict, "lnum", lnum, NULL); | |
914 if (lnum == 0) | |
915 dict_add_nr_str(dict, "pattern", 0L, cmd); | |
916 } | |
917 | |
2533 | 918 vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag); |
9850
67781bb0a61a
commit https://github.com/vim/vim/commit/d823fa910cca43fec3c31c030ee908a14c272640
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
919 set_errorlist(curwin, list, ' ', IObuff, NULL); |
649 | 920 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
921 list_free(list); |
2770 | 922 vim_free(fname); |
923 vim_free(cmd); | |
692 | 924 |
925 cur_match = 0; /* Jump to the first tag */ | |
649 | 926 } |
927 #endif | |
7 | 928 |
929 if (ask_for_selection == TRUE) | |
930 { | |
931 /* | |
932 * Ask to select a tag from the list. | |
933 */ | |
373 | 934 i = prompt_for_number(NULL); |
7 | 935 if (i <= 0 || i > num_matches || got_int) |
936 { | |
937 /* no valid choice: don't change anything */ | |
938 if (use_tagstack) | |
939 { | |
940 tagstack[tagstackidx].fmark = saved_fmark; | |
941 tagstackidx = prevtagstackidx; | |
942 } | |
943 #ifdef FEAT_CSCOPE | |
944 cs_free_tags(); | |
945 jumped_to_tag = TRUE; | |
946 #endif | |
947 break; | |
948 } | |
949 cur_match = i - 1; | |
950 } | |
951 | |
952 if (cur_match >= num_matches) | |
953 { | |
954 /* Avoid giving this error when a file wasn't found and we're | |
955 * looking for a match in another file, which wasn't found. | |
956 * There will be an EMSG("file doesn't exist") below then. */ | |
957 if ((type == DT_NEXT || type == DT_FIRST) | |
958 && nofile_fname == NULL) | |
959 { | |
960 if (num_matches == 1) | |
961 EMSG(_("E427: There is only one matching tag")); | |
962 else | |
963 EMSG(_("E428: Cannot go beyond last matching tag")); | |
964 skip_msg = TRUE; | |
965 } | |
966 cur_match = num_matches - 1; | |
967 } | |
968 if (use_tagstack) | |
969 { | |
970 tagstack[tagstackidx].cur_match = cur_match; | |
971 tagstack[tagstackidx].cur_fnum = cur_fnum; | |
972 ++tagstackidx; | |
973 } | |
974 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 975 else if (g_do_tagpreview != 0) |
7 | 976 { |
977 ptag_entry.cur_match = cur_match; | |
978 ptag_entry.cur_fnum = cur_fnum; | |
979 } | |
980 #endif | |
981 | |
982 /* | |
983 * Only when going to try the next match, report that the previous | |
984 * file didn't exist. Otherwise an EMSG() is given below. | |
985 */ | |
986 if (nofile_fname != NULL && error_cur_match != cur_match) | |
273 | 987 smsg((char_u *)_("File \"%s\" does not exist"), nofile_fname); |
7 | 988 |
989 | |
990 ic = (matches[cur_match][0] & MT_IC_OFF); | |
6851 | 991 if (type != DT_TAG && type != DT_SELECT && type != DT_JUMP |
7 | 992 #ifdef FEAT_CSCOPE |
993 && type != DT_CSCOPE | |
994 #endif | |
995 && (num_matches > 1 || ic) | |
996 && !skip_msg) | |
997 { | |
998 /* Give an indication of the number of matching tags */ | |
999 sprintf((char *)IObuff, _("tag %d of %d%s"), | |
1000 cur_match + 1, | |
1001 num_matches, | |
1002 max_num_matches != MAXCOL ? _(" or more") : ""); | |
1003 if (ic) | |
1004 STRCAT(IObuff, _(" Using tag with different case!")); | |
1005 if ((num_matches > prev_num_matches || new_tag) | |
1006 && num_matches > 1) | |
1007 { | |
1008 if (ic) | |
1009 msg_attr(IObuff, hl_attr(HLF_W)); | |
1010 else | |
1011 msg(IObuff); | |
1012 msg_scroll = TRUE; /* don't overwrite this message */ | |
1013 } | |
1014 else | |
1015 give_warning(IObuff, ic); | |
1016 if (ic && !msg_scrolled && msg_silent == 0) | |
1017 { | |
1018 out_flush(); | |
1019 ui_delay(1000L, TRUE); | |
1020 } | |
1021 } | |
1022 | |
589 | 1023 #ifdef FEAT_AUTOCMD |
1024 /* Let the SwapExists event know what tag we are jumping to. */ | |
1025 vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name); | |
1026 set_vim_var_string(VV_SWAPCOMMAND, IObuff, -1); | |
1027 #endif | |
1028 | |
7 | 1029 /* |
1030 * Jump to the desired match. | |
1031 */ | |
589 | 1032 i = jumpto_tag(matches[cur_match], forceit, type != DT_CSCOPE); |
1033 | |
1034 #ifdef FEAT_AUTOCMD | |
1035 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
1036 #endif | |
1037 | |
1038 if (i == NOTAGFILE) | |
7 | 1039 { |
1040 /* File not found: try again with another matching tag */ | |
1041 if ((type == DT_PREV && cur_match > 0) | |
1042 || ((type == DT_TAG || type == DT_NEXT | |
1043 || type == DT_FIRST) | |
1044 && (max_num_matches != MAXCOL | |
1045 || cur_match < num_matches - 1))) | |
1046 { | |
1047 error_cur_match = cur_match; | |
1048 if (use_tagstack) | |
1049 --tagstackidx; | |
1050 if (type == DT_PREV) | |
1051 --cur_match; | |
1052 else | |
1053 { | |
1054 type = DT_NEXT; | |
1055 ++cur_match; | |
1056 } | |
1057 continue; | |
1058 } | |
1059 EMSG2(_("E429: File \"%s\" does not exist"), nofile_fname); | |
1060 } | |
1061 else | |
1062 { | |
1063 /* We may have jumped to another window, check that | |
1064 * tagstackidx is still valid. */ | |
1065 if (use_tagstack && tagstackidx > curwin->w_tagstacklen) | |
1066 tagstackidx = curwin->w_tagstackidx; | |
1067 #ifdef FEAT_CSCOPE | |
1068 jumped_to_tag = TRUE; | |
1069 #endif | |
1070 } | |
1071 } | |
1072 break; | |
1073 } | |
1074 | |
1075 end_do_tag: | |
1076 /* Only store the new index when using the tagstack and it's valid. */ | |
1077 if (use_tagstack && tagstackidx <= curwin->w_tagstacklen) | |
1078 curwin->w_tagstackidx = tagstackidx; | |
1079 #ifdef FEAT_WINDOWS | |
1080 postponed_split = 0; /* don't split next time */ | |
9949
30be4b26a37e
commit https://github.com/vim/vim/commit/358308dd99abdd56c6540339e505585d8db7bdfe
Christian Brabandt <cb@256bit.org>
parents:
9913
diff
changeset
|
1081 # ifdef FEAT_QUICKFIX |
30be4b26a37e
commit https://github.com/vim/vim/commit/358308dd99abdd56c6540339e505585d8db7bdfe
Christian Brabandt <cb@256bit.org>
parents:
9913
diff
changeset
|
1082 g_do_tagpreview = 0; /* don't do tag preview next time */ |
30be4b26a37e
commit https://github.com/vim/vim/commit/358308dd99abdd56c6540339e505585d8db7bdfe
Christian Brabandt <cb@256bit.org>
parents:
9913
diff
changeset
|
1083 # endif |
7 | 1084 #endif |
1085 | |
1086 #ifdef FEAT_CSCOPE | |
1087 return jumped_to_tag; | |
1088 #else | |
1089 return FALSE; | |
1090 #endif | |
1091 } | |
1092 | |
1093 /* | |
1094 * Free cached tags. | |
1095 */ | |
1096 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1097 tag_freematch(void) |
7 | 1098 { |
1099 vim_free(tagmatchname); | |
1100 tagmatchname = NULL; | |
1101 } | |
1102 | |
1103 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1104 taglen_advance(int l) |
7 | 1105 { |
1106 if (l == MAXCOL) | |
1107 { | |
1108 msg_putchar('\n'); | |
1109 msg_advance(24); | |
1110 } | |
1111 else | |
1112 msg_advance(13 + l); | |
1113 } | |
1114 | |
1115 /* | |
1116 * Print the tag stack | |
1117 */ | |
1118 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1119 do_tags(exarg_T *eap UNUSED) |
7 | 1120 { |
1121 int i; | |
1122 char_u *name; | |
1123 taggy_T *tagstack = curwin->w_tagstack; | |
1124 int tagstackidx = curwin->w_tagstackidx; | |
1125 int tagstacklen = curwin->w_tagstacklen; | |
1126 | |
1127 /* Highlight title */ | |
1128 MSG_PUTS_TITLE(_("\n # TO tag FROM line in file/text")); | |
1129 for (i = 0; i < tagstacklen; ++i) | |
1130 { | |
1131 if (tagstack[i].tagname != NULL) | |
1132 { | |
1133 name = fm_getname(&(tagstack[i].fmark), 30); | |
1134 if (name == NULL) /* file name not available */ | |
1135 continue; | |
1136 | |
1137 msg_putchar('\n'); | |
1138 sprintf((char *)IObuff, "%c%2d %2d %-15s %5ld ", | |
1139 i == tagstackidx ? '>' : ' ', | |
1140 i + 1, | |
1141 tagstack[i].cur_match + 1, | |
1142 tagstack[i].tagname, | |
1143 tagstack[i].fmark.mark.lnum); | |
1144 msg_outtrans(IObuff); | |
1145 msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum | |
1146 ? hl_attr(HLF_D) : 0); | |
1147 vim_free(name); | |
1148 } | |
1149 out_flush(); /* show one line at a time */ | |
1150 } | |
1151 if (tagstackidx == tagstacklen) /* idx at top of stack */ | |
1152 MSG_PUTS("\n>"); | |
1153 } | |
1154 | |
1155 /* When not using a CR for line separator, use vim_fgets() to read tag lines. | |
1156 * For the Mac use tag_fgets(). It can handle any line separator, but is much | |
1157 * slower than vim_fgets(). | |
1158 */ | |
1159 #ifndef USE_CR | |
1160 # define tag_fgets vim_fgets | |
1161 #endif | |
1162 | |
1163 #ifdef FEAT_TAG_BINS | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
1164 static int tag_strnicmp(char_u *s1, char_u *s2, size_t len); |
7 | 1165 |
1166 /* | |
1167 * Compare two strings, for length "len", ignoring case the ASCII way. | |
1168 * return 0 for match, < 0 for smaller, > 0 for bigger | |
1169 * Make sure case is folded to uppercase in comparison (like for 'sort -f') | |
1170 */ | |
1171 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1172 tag_strnicmp(char_u *s1, char_u *s2, size_t len) |
7 | 1173 { |
1174 int i; | |
1175 | |
1176 while (len > 0) | |
1177 { | |
1178 i = (int)TOUPPER_ASC(*s1) - (int)TOUPPER_ASC(*s2); | |
1179 if (i != 0) | |
1180 return i; /* this character different */ | |
1181 if (*s1 == NUL) | |
1182 break; /* strings match until NUL */ | |
1183 ++s1; | |
1184 ++s2; | |
1185 --len; | |
1186 } | |
1187 return 0; /* strings match */ | |
1188 } | |
1189 #endif | |
1190 | |
1191 /* | |
1192 * Structure to hold info about the tag pattern being used. | |
1193 */ | |
1194 typedef struct | |
1195 { | |
1196 char_u *pat; /* the pattern */ | |
1197 int len; /* length of pat[] */ | |
1198 char_u *head; /* start of pattern head */ | |
1199 int headlen; /* length of head[] */ | |
1200 regmatch_T regmatch; /* regexp program, may be NULL */ | |
1201 } pat_T; | |
1202 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
1203 static void prepare_pats(pat_T *pats, int has_re); |
7 | 1204 |
1205 /* | |
1206 * Extract info from the tag search pattern "pats->pat". | |
1207 */ | |
1208 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1209 prepare_pats(pat_T *pats, int has_re) |
7 | 1210 { |
1211 pats->head = pats->pat; | |
1212 pats->headlen = pats->len; | |
1213 if (has_re) | |
1214 { | |
1215 /* When the pattern starts with '^' or "\\<", binary searching can be | |
1216 * used (much faster). */ | |
1217 if (pats->pat[0] == '^') | |
1218 pats->head = pats->pat + 1; | |
1219 else if (pats->pat[0] == '\\' && pats->pat[1] == '<') | |
1220 pats->head = pats->pat + 2; | |
1221 if (pats->head == pats->pat) | |
1222 pats->headlen = 0; | |
1223 else | |
1224 for (pats->headlen = 0; pats->head[pats->headlen] != NUL; | |
1225 ++pats->headlen) | |
1226 if (vim_strchr((char_u *)(p_magic ? ".[~*\\$" : "\\$"), | |
1227 pats->head[pats->headlen]) != NULL) | |
1228 break; | |
1229 if (p_tl != 0 && pats->headlen > p_tl) /* adjust for 'taglength' */ | |
1230 pats->headlen = p_tl; | |
1231 } | |
1232 | |
1233 if (has_re) | |
1234 pats->regmatch.regprog = vim_regcomp(pats->pat, p_magic ? RE_MAGIC : 0); | |
1235 else | |
1236 pats->regmatch.regprog = NULL; | |
1237 } | |
1238 | |
1239 /* | |
1240 * find_tags() - search for tags in tags files | |
1241 * | |
1242 * Return FAIL if search completely failed (*num_matches will be 0, *matchesp | |
1243 * will be NULL), OK otherwise. | |
1244 * | |
1245 * There is a priority in which type of tag is recognized. | |
1246 * | |
1247 * 6. A static or global tag with a full matching tag for the current file. | |
1248 * 5. A global tag with a full matching tag for another file. | |
1249 * 4. A static tag with a full matching tag for another file. | |
1250 * 3. A static or global tag with an ignore-case matching tag for the | |
1251 * current file. | |
1252 * 2. A global tag with an ignore-case matching tag for another file. | |
1253 * 1. A static tag with an ignore-case matching tag for another file. | |
1254 * | |
1255 * Tags in an emacs-style tags file are always global. | |
1256 * | |
1257 * flags: | |
1258 * TAG_HELP only search for help tags | |
1259 * TAG_NAMES only return name of tag | |
1260 * TAG_REGEXP use "pat" as a regexp | |
1261 * TAG_NOIC don't always ignore case | |
1262 * TAG_KEEP_LANG keep language | |
1263 */ | |
1264 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1265 find_tags( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1266 char_u *pat, /* pattern to search for */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1267 int *num_matches, /* return: number of matches found */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1268 char_u ***matchesp, /* return: array of matches found */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1269 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1270 int mincount, /* MAXCOL: find all matches |
7 | 1271 other: minimal number of matches */ |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1272 char_u *buf_ffname) /* name of buffer for priority */ |
7 | 1273 { |
1274 FILE *fp; | |
1275 char_u *lbuf; /* line buffer */ | |
3131 | 1276 int lbuf_size = LSIZE; /* length of lbuf */ |
7 | 1277 char_u *tag_fname; /* name of tag file */ |
692 | 1278 tagname_T tn; /* info for get_tagfname() */ |
7 | 1279 int first_file; /* trying first tag file */ |
1280 tagptrs_T tagp; | |
1281 int did_open = FALSE; /* did open a tag file */ | |
1282 int stop_searching = FALSE; /* stop when match found or error */ | |
1283 int retval = FAIL; /* return value */ | |
1284 int is_static; /* current tag line is static */ | |
1285 int is_current; /* file name matches */ | |
1286 int eof = FALSE; /* found end-of-file */ | |
1287 char_u *p; | |
1288 char_u *s; | |
1289 int i; | |
1290 #ifdef FEAT_TAG_BINS | |
3131 | 1291 int tag_file_sorted = NUL; /* !_TAG_FILE_SORTED value */ |
7 | 1292 struct tag_search_info /* Binary search file offsets */ |
1293 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1294 off_T low_offset; /* offset for first char of first line that |
7 | 1295 could match */ |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1296 off_T high_offset; /* offset of char after last line that could |
7 | 1297 match */ |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1298 off_T curr_offset; /* Current file offset in search range */ |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1299 off_T curr_offset_used; /* curr_offset used when skipping back */ |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1300 off_T match_offset; /* Where the binary search found a tag */ |
7 | 1301 int low_char; /* first char at low_offset */ |
1302 int high_char; /* first char at high_offset */ | |
1303 } search_info; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1304 off_T filesize; |
7 | 1305 int tagcmp; |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1306 off_T offset; |
7 | 1307 int round; |
1308 #endif | |
1309 enum | |
1310 { | |
1311 TS_START, /* at start of file */ | |
1312 TS_LINEAR /* linear searching forward, till EOF */ | |
1313 #ifdef FEAT_TAG_BINS | |
1314 , TS_BINARY, /* binary searching */ | |
1315 TS_SKIP_BACK, /* skipping backwards */ | |
1316 TS_STEP_FORWARD /* stepping forwards */ | |
1317 #endif | |
1318 } state; /* Current search state */ | |
1319 | |
1320 int cmplen; | |
1321 int match; /* matches */ | |
1322 int match_no_ic = 0;/* matches with rm_ic == FALSE */ | |
1323 int match_re; /* match with regexp */ | |
1324 int matchoff = 0; | |
5513 | 1325 int save_emsg_off; |
7 | 1326 |
1327 #ifdef FEAT_EMACS_TAGS | |
1328 /* | |
1329 * Stack for included emacs-tags file. | |
1330 * It has a fixed size, to truncate cyclic includes. jw | |
1331 */ | |
1332 # define INCSTACK_SIZE 42 | |
1333 struct | |
1334 { | |
1335 FILE *fp; | |
1336 char_u *etag_fname; | |
1337 } incstack[INCSTACK_SIZE]; | |
1338 | |
1339 int incstack_idx = 0; /* index in incstack */ | |
1204 | 1340 char_u *ebuf; /* additional buffer for etag fname */ |
7 | 1341 int is_etag; /* current file is emaces style */ |
1342 #endif | |
1343 | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1344 char_u *mfp; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1345 hashtab_T ht_match[MT_COUNT]; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1346 hash_T hash = 0; |
7 | 1347 int match_count = 0; /* number of matches found */ |
1348 char_u **matches; | |
1349 int mtt; | |
1350 int help_save; | |
1351 #ifdef FEAT_MULTI_LANG | |
1352 int help_pri = 0; | |
1353 char_u *help_lang_find = NULL; /* lang to be found */ | |
1354 char_u help_lang[3]; /* lang of current tags file */ | |
1355 char_u *saved_pat = NULL; /* copy of pat[] */ | |
10444
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1356 int is_txt = FALSE; /* flag of file extension */ |
7 | 1357 #endif |
1358 | |
1359 pat_T orgpat; /* holds unconverted pattern info */ | |
1360 #ifdef FEAT_MBYTE | |
1361 vimconv_T vimconv; | |
1362 #endif | |
1363 | |
1364 #ifdef FEAT_TAG_BINS | |
1365 int findall = (mincount == MAXCOL || mincount == TAG_MANY); | |
1366 /* find all matching tags */ | |
1367 int sort_error = FALSE; /* tags file not sorted */ | |
1368 int linear; /* do a linear search */ | |
1369 int sortic = FALSE; /* tag file sorted in nocase */ | |
1370 #endif | |
1371 int line_error = FALSE; /* syntax error */ | |
1372 int has_re = (flags & TAG_REGEXP); /* regexp used */ | |
1373 int help_only = (flags & TAG_HELP); | |
1374 int name_only = (flags & TAG_NAMES); | |
1375 int noic = (flags & TAG_NOIC); | |
1376 int get_it_again = FALSE; | |
1377 #ifdef FEAT_CSCOPE | |
1378 int use_cscope = (flags & TAG_CSCOPE); | |
1379 #endif | |
1380 int verbose = (flags & TAG_VERBOSE); | |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1381 int save_p_ic = p_ic; |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1382 |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1383 /* |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1384 * Change the value of 'ignorecase' according to 'tagcase' for the |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1385 * duration of this function. |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1386 */ |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1387 switch (curbuf->b_tc_flags ? curbuf->b_tc_flags : tc_flags) |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1388 { |
10444
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1389 case TC_FOLLOWIC: break; |
9913
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9850
diff
changeset
|
1390 case TC_IGNORE: p_ic = TRUE; break; |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9850
diff
changeset
|
1391 case TC_MATCH: p_ic = FALSE; break; |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9850
diff
changeset
|
1392 case TC_FOLLOWSCS: p_ic = ignorecase(pat); break; |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9850
diff
changeset
|
1393 case TC_SMART: p_ic = ignorecase_opt(pat, TRUE, TRUE); break; |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1394 } |
7 | 1395 |
1396 help_save = curbuf->b_help; | |
1397 orgpat.pat = pat; | |
1398 #ifdef FEAT_MBYTE | |
1399 vimconv.vc_type = CONV_NONE; | |
1400 #endif | |
1401 | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1402 /* |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1403 * Allocate memory for the buffers that are used |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1404 */ |
3131 | 1405 lbuf = alloc(lbuf_size); |
7 | 1406 tag_fname = alloc(MAXPATHL + 1); |
1407 #ifdef FEAT_EMACS_TAGS | |
1408 ebuf = alloc(LSIZE); | |
1409 #endif | |
1410 for (mtt = 0; mtt < MT_COUNT; ++mtt) | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
1411 hash_init(&ht_match[mtt]); |
7 | 1412 |
1413 /* check for out of memory situation */ | |
1414 if (lbuf == NULL || tag_fname == NULL | |
1415 #ifdef FEAT_EMACS_TAGS | |
1416 || ebuf == NULL | |
1417 #endif | |
1418 ) | |
1419 goto findtag_end; | |
1420 | |
1421 #ifdef FEAT_CSCOPE | |
1422 STRCPY(tag_fname, "from cscope"); /* for error messages */ | |
1423 #endif | |
1424 | |
1425 /* | |
1426 * Initialize a few variables | |
1427 */ | |
1428 if (help_only) /* want tags from help file */ | |
1429 curbuf->b_help = TRUE; /* will be restored later */ | |
1430 | |
3131 | 1431 orgpat.len = (int)STRLEN(pat); |
7 | 1432 #ifdef FEAT_MULTI_LANG |
1433 if (curbuf->b_help) | |
1434 { | |
1435 /* When "@ab" is specified use only the "ab" language, otherwise | |
1436 * search all languages. */ | |
3131 | 1437 if (orgpat.len > 3 && pat[orgpat.len - 3] == '@' |
1438 && ASCII_ISALPHA(pat[orgpat.len - 2]) | |
1439 && ASCII_ISALPHA(pat[orgpat.len - 1])) | |
7 | 1440 { |
3131 | 1441 saved_pat = vim_strnsave(pat, orgpat.len - 3); |
7 | 1442 if (saved_pat != NULL) |
1443 { | |
3131 | 1444 help_lang_find = &pat[orgpat.len - 2]; |
1445 orgpat.pat = saved_pat; | |
1446 orgpat.len -= 3; | |
7 | 1447 } |
1448 } | |
1449 } | |
1450 #endif | |
3131 | 1451 if (p_tl != 0 && orgpat.len > p_tl) /* adjust for 'taglength' */ |
1452 orgpat.len = p_tl; | |
1453 | |
5513 | 1454 save_emsg_off = emsg_off; |
1455 emsg_off = TRUE; /* don't want error for invalid RE here */ | |
3131 | 1456 prepare_pats(&orgpat, has_re); |
5513 | 1457 emsg_off = save_emsg_off; |
3784 | 1458 if (has_re && orgpat.regmatch.regprog == NULL) |
1459 goto findtag_end; | |
7 | 1460 |
1461 #ifdef FEAT_TAG_BINS | |
1462 /* This is only to avoid a compiler warning for using search_info | |
1463 * uninitialised. */ | |
1464 vim_memset(&search_info, 0, (size_t)1); | |
1465 #endif | |
1466 | |
413 | 1467 /* |
1468 * When finding a specified number of matches, first try with matching | |
1469 * case, so binary search can be used, and try ignore-case matches in a | |
1470 * second loop. | |
1471 * When finding all matches, 'tagbsearch' is off, or there is no fixed | |
1472 * string to look for, ignore case right away to avoid going though the | |
1473 * tags files twice. | |
1474 * When the tag file is case-fold sorted, it is either one or the other. | |
1475 * Only ignore case when TAG_NOIC not used or 'ignorecase' set. | |
1476 */ | |
10444
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1477 #ifdef FEAT_MULTI_LANG |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1478 /* Set a flag if the file extension is .txt */ |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1479 if ((flags & TAG_KEEP_LANG) |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1480 && help_lang_find == NULL |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1481 && curbuf->b_fname != NULL |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1482 && (i = (int)STRLEN(curbuf->b_fname)) > 4 |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1483 && STRICMP(curbuf->b_fname + i - 4, ".txt") == 0) |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1484 is_txt = TRUE; |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1485 #endif |
7 | 1486 #ifdef FEAT_TAG_BINS |
3131 | 1487 orgpat.regmatch.rm_ic = ((p_ic || !noic) |
1488 && (findall || orgpat.headlen == 0 || !p_tbs)); | |
7 | 1489 for (round = 1; round <= 2; ++round) |
1490 { | |
3131 | 1491 linear = (orgpat.headlen == 0 || !p_tbs || round == 2); |
7 | 1492 #else |
3131 | 1493 orgpat.regmatch.rm_ic = (p_ic || !noic); |
7 | 1494 #endif |
1495 | |
1496 /* | |
1497 * Try tag file names from tags option one by one. | |
1498 */ | |
1499 for (first_file = TRUE; | |
1500 #ifdef FEAT_CSCOPE | |
1501 use_cscope || | |
1502 #endif | |
692 | 1503 get_tagfname(&tn, first_file, tag_fname) == OK; |
1504 first_file = FALSE) | |
7 | 1505 { |
1506 /* | |
1507 * A file that doesn't exist is silently ignored. Only when not a | |
1508 * single file is found, an error message is given (further on). | |
1509 */ | |
1510 #ifdef FEAT_CSCOPE | |
1511 if (use_cscope) | |
1512 fp = NULL; /* avoid GCC warning */ | |
1513 else | |
1514 #endif | |
1515 { | |
1516 #ifdef FEAT_MULTI_LANG | |
1517 if (curbuf->b_help) | |
1518 { | |
10444
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1519 /* Keep en if the file extension is .txt*/ |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1520 if (is_txt) |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1521 STRCPY(help_lang, "en"); |
7 | 1522 else |
10444
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1523 { |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1524 /* Prefer help tags according to 'helplang'. Put the |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1525 * two-letter language name in help_lang[]. */ |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1526 i = (int)STRLEN(tag_fname); |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1527 if (i > 3 && tag_fname[i - 3] == '-') |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1528 STRCPY(help_lang, tag_fname + i - 2); |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1529 else |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1530 STRCPY(help_lang, "en"); |
2edda415c28a
commit https://github.com/vim/vim/commit/6dbf66aa3e2197ce41f2b1cc7602bb9c15840548
Christian Brabandt <cb@256bit.org>
parents:
10430
diff
changeset
|
1531 } |
7 | 1532 /* When searching for a specific language skip tags files |
1533 * for other languages. */ | |
1534 if (help_lang_find != NULL | |
1535 && STRICMP(help_lang, help_lang_find) != 0) | |
1536 continue; | |
1537 | |
1538 /* For CTRL-] in a help file prefer a match with the same | |
1539 * language. */ | |
1540 if ((flags & TAG_KEEP_LANG) | |
1541 && help_lang_find == NULL | |
1542 && curbuf->b_fname != NULL | |
835 | 1543 && (i = (int)STRLEN(curbuf->b_fname)) > 4 |
7 | 1544 && curbuf->b_fname[i - 1] == 'x' |
1545 && curbuf->b_fname[i - 4] == '.' | |
1546 && STRNICMP(curbuf->b_fname + i - 3, help_lang, 2) == 0) | |
1547 help_pri = 0; | |
1548 else | |
1549 { | |
1550 help_pri = 1; | |
1551 for (s = p_hlg; *s != NUL; ++s) | |
1552 { | |
1553 if (STRNICMP(s, help_lang, 2) == 0) | |
1554 break; | |
1555 ++help_pri; | |
1556 if ((s = vim_strchr(s, ',')) == NULL) | |
1557 break; | |
1558 } | |
1559 if (s == NULL || *s == NUL) | |
1560 { | |
1561 /* Language not in 'helplang': use last, prefer English, | |
1562 * unless found already. */ | |
1563 ++help_pri; | |
1564 if (STRICMP(help_lang, "en") != 0) | |
1565 ++help_pri; | |
1566 } | |
1567 } | |
1568 } | |
1569 #endif | |
1570 | |
1571 if ((fp = mch_fopen((char *)tag_fname, "r")) == NULL) | |
1572 continue; | |
1573 | |
1574 if (p_verbose >= 5) | |
292 | 1575 { |
1576 verbose_enter(); | |
273 | 1577 smsg((char_u *)_("Searching tags file %s"), tag_fname); |
292 | 1578 verbose_leave(); |
1579 } | |
7 | 1580 } |
1581 did_open = TRUE; /* remember that we found at least one file */ | |
1582 | |
1583 state = TS_START; /* we're at the start of the file */ | |
1584 #ifdef FEAT_EMACS_TAGS | |
1585 is_etag = 0; /* default is: not emacs style */ | |
1586 #endif | |
1587 | |
1588 /* | |
1589 * Read and parse the lines in the file one by one | |
1590 */ | |
1591 for (;;) | |
1592 { | |
10134
95e9be4bc490
commit https://github.com/vim/vim/commit/7947312871e7d01cdba058199904c212ec32f1c0
Christian Brabandt <cb@256bit.org>
parents:
10132
diff
changeset
|
1593 #ifdef FEAT_TAG_BINS |
10128
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1594 /* check for CTRL-C typed, more often when jumping around */ |
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1595 if (state == TS_BINARY || state == TS_SKIP_BACK) |
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1596 line_breakcheck(); |
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1597 else |
10134
95e9be4bc490
commit https://github.com/vim/vim/commit/7947312871e7d01cdba058199904c212ec32f1c0
Christian Brabandt <cb@256bit.org>
parents:
10132
diff
changeset
|
1598 #endif |
10128
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1599 fast_breakcheck(); |
7 | 1600 #ifdef FEAT_INS_EXPAND |
1601 if ((flags & TAG_INS_COMP)) /* Double brackets for gcc */ | |
10277
154d5a2e7395
commit https://github.com/vim/vim/commit/472e85970ee3a80abd824bef510df12e9cfe9e96
Christian Brabandt <cb@256bit.org>
parents:
10134
diff
changeset
|
1602 ins_compl_check_keys(30, FALSE); |
449 | 1603 if (got_int || compl_interrupted) |
7 | 1604 #else |
1605 if (got_int) | |
1606 #endif | |
1607 { | |
1608 stop_searching = TRUE; | |
1609 break; | |
1610 } | |
1611 /* When mincount is TAG_MANY, stop when enough matches have been | |
1612 * found (for completion). */ | |
1613 if (mincount == TAG_MANY && match_count >= TAG_MANY) | |
1614 { | |
1615 stop_searching = TRUE; | |
1616 retval = OK; | |
1617 break; | |
1618 } | |
1619 if (get_it_again) | |
1620 goto line_read_in; | |
1621 #ifdef FEAT_TAG_BINS | |
1622 /* | |
1623 * For binary search: compute the next offset to use. | |
1624 */ | |
1625 if (state == TS_BINARY) | |
1626 { | |
1627 offset = search_info.low_offset + ((search_info.high_offset | |
1628 - search_info.low_offset) / 2); | |
1629 if (offset == search_info.curr_offset) | |
1630 break; /* End the binary search without a match. */ | |
1631 else | |
1632 search_info.curr_offset = offset; | |
1633 } | |
1634 | |
1635 /* | |
1636 * Skipping back (after a match during binary search). | |
1637 */ | |
1638 else if (state == TS_SKIP_BACK) | |
1639 { | |
1640 search_info.curr_offset -= LSIZE * 2; | |
1641 if (search_info.curr_offset < 0) | |
1642 { | |
1643 search_info.curr_offset = 0; | |
1644 rewind(fp); | |
1645 state = TS_STEP_FORWARD; | |
1646 } | |
1647 } | |
1648 | |
1649 /* | |
1650 * When jumping around in the file, first read a line to find the | |
1651 * start of the next line. | |
1652 */ | |
1653 if (state == TS_BINARY || state == TS_SKIP_BACK) | |
1654 { | |
1655 /* Adjust the search file offset to the correct position */ | |
1656 search_info.curr_offset_used = search_info.curr_offset; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1657 vim_fseek(fp, search_info.curr_offset, SEEK_SET); |
7 | 1658 eof = tag_fgets(lbuf, LSIZE, fp); |
1659 if (!eof && search_info.curr_offset != 0) | |
1660 { | |
1146 | 1661 /* The explicit cast is to work around a bug in gcc 3.4.2 |
1662 * (repeated below). */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1663 search_info.curr_offset = vim_ftell(fp); |
7 | 1664 if (search_info.curr_offset == search_info.high_offset) |
1665 { | |
1666 /* oops, gone a bit too far; try from low offset */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1667 vim_fseek(fp, search_info.low_offset, SEEK_SET); |
7 | 1668 search_info.curr_offset = search_info.low_offset; |
1669 } | |
1670 eof = tag_fgets(lbuf, LSIZE, fp); | |
1671 } | |
1672 /* skip empty and blank lines */ | |
1673 while (!eof && vim_isblankline(lbuf)) | |
1674 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1675 search_info.curr_offset = vim_ftell(fp); |
7 | 1676 eof = tag_fgets(lbuf, LSIZE, fp); |
1677 } | |
1678 if (eof) | |
1679 { | |
1680 /* Hit end of file. Skip backwards. */ | |
1681 state = TS_SKIP_BACK; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1682 search_info.match_offset = vim_ftell(fp); |
7 | 1683 search_info.curr_offset = search_info.curr_offset_used; |
1684 continue; | |
1685 } | |
1686 } | |
1687 | |
1688 /* | |
1689 * Not jumping around in the file: Read the next line. | |
1690 */ | |
1691 else | |
1692 #endif | |
1693 { | |
1694 /* skip empty and blank lines */ | |
1695 do | |
1696 { | |
1697 #ifdef FEAT_CSCOPE | |
1698 if (use_cscope) | |
1699 eof = cs_fgets(lbuf, LSIZE); | |
1700 else | |
1701 #endif | |
1702 eof = tag_fgets(lbuf, LSIZE, fp); | |
1703 } while (!eof && vim_isblankline(lbuf)); | |
1704 | |
1705 if (eof) | |
1706 { | |
1707 #ifdef FEAT_EMACS_TAGS | |
1708 if (incstack_idx) /* this was an included file */ | |
1709 { | |
1710 --incstack_idx; | |
1711 fclose(fp); /* end of this file ... */ | |
1712 fp = incstack[incstack_idx].fp; | |
1713 STRCPY(tag_fname, incstack[incstack_idx].etag_fname); | |
1714 vim_free(incstack[incstack_idx].etag_fname); | |
1715 is_etag = 1; /* (only etags can include) */ | |
1716 continue; /* ... continue with parent file */ | |
1717 } | |
1718 else | |
1719 #endif | |
1720 break; /* end of file */ | |
1721 } | |
1722 } | |
1723 line_read_in: | |
1724 | |
3131 | 1725 #ifdef FEAT_MBYTE |
1726 if (vimconv.vc_type != CONV_NONE) | |
1727 { | |
1728 char_u *conv_line; | |
1729 int len; | |
1730 | |
1731 /* Convert every line. Converting the pattern from 'enc' to | |
1732 * the tags file encoding doesn't work, because characters are | |
1733 * not recognized. */ | |
1734 conv_line = string_convert(&vimconv, lbuf, NULL); | |
1735 if (conv_line != NULL) | |
1736 { | |
1737 /* Copy or swap lbuf and conv_line. */ | |
1738 len = (int)STRLEN(conv_line) + 1; | |
1739 if (len > lbuf_size) | |
1740 { | |
1741 vim_free(lbuf); | |
1742 lbuf = conv_line; | |
1743 lbuf_size = len; | |
1744 } | |
1745 else | |
1746 { | |
1747 STRCPY(lbuf, conv_line); | |
1748 vim_free(conv_line); | |
1749 } | |
1750 } | |
1751 } | |
1752 #endif | |
1753 | |
1754 | |
7 | 1755 #ifdef FEAT_EMACS_TAGS |
1756 /* | |
1757 * Emacs tags line with CTRL-L: New file name on next line. | |
1758 * The file name is followed by a ','. | |
1759 */ | |
1760 if (*lbuf == Ctrl_L) /* remember etag file name in ebuf */ | |
1761 { | |
1762 is_etag = 1; /* in case at the start */ | |
1763 state = TS_LINEAR; | |
1764 if (!tag_fgets(ebuf, LSIZE, fp)) | |
1765 { | |
1766 for (p = ebuf; *p && *p != ','; p++) | |
1767 ; | |
1768 *p = NUL; | |
1769 | |
1770 /* | |
1771 * atoi(p+1) is the number of bytes before the next ^L | |
1772 * unless it is an include statement. | |
1773 */ | |
1774 if (STRNCMP(p + 1, "include", 7) == 0 | |
1775 && incstack_idx < INCSTACK_SIZE) | |
1776 { | |
1777 /* Save current "fp" and "tag_fname" in the stack. */ | |
1778 if ((incstack[incstack_idx].etag_fname = | |
1779 vim_strsave(tag_fname)) != NULL) | |
1780 { | |
1781 char_u *fullpath_ebuf; | |
1782 | |
1783 incstack[incstack_idx].fp = fp; | |
1784 fp = NULL; | |
1785 | |
1786 /* Figure out "tag_fname" and "fp" to use for | |
1787 * included file. */ | |
1788 fullpath_ebuf = expand_tag_fname(ebuf, | |
1789 tag_fname, FALSE); | |
1790 if (fullpath_ebuf != NULL) | |
1791 { | |
1792 fp = mch_fopen((char *)fullpath_ebuf, "r"); | |
1793 if (fp != NULL) | |
1794 { | |
1795 if (STRLEN(fullpath_ebuf) > LSIZE) | |
1796 EMSG2(_("E430: Tag file path truncated for %s\n"), ebuf); | |
418 | 1797 vim_strncpy(tag_fname, fullpath_ebuf, |
1798 MAXPATHL); | |
7 | 1799 ++incstack_idx; |
1800 is_etag = 0; /* we can include anything */ | |
1801 } | |
1802 vim_free(fullpath_ebuf); | |
1803 } | |
1804 if (fp == NULL) | |
1805 { | |
1806 /* Can't open the included file, skip it and | |
1807 * restore old value of "fp". */ | |
1808 fp = incstack[incstack_idx].fp; | |
1809 vim_free(incstack[incstack_idx].etag_fname); | |
1810 } | |
1811 } | |
1812 } | |
1813 } | |
1814 continue; | |
1815 } | |
1816 #endif | |
1817 | |
1818 /* | |
1819 * When still at the start of the file, check for Emacs tags file | |
1820 * format, and for "not sorted" flag. | |
1821 */ | |
1822 if (state == TS_START) | |
1823 { | |
5328 | 1824 /* The header ends when the line sorts below "!_TAG_". When |
1825 * case is folded lower case letters sort before "_". */ | |
4914
1707ddb6f5ae
updated for version 7.3.1202
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1826 if (STRNCMP(lbuf, "!_TAG_", 6) <= 0 |
1707ddb6f5ae
updated for version 7.3.1202
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1827 || (lbuf[0] == '!' && ASCII_ISLOWER(lbuf[1]))) |
3131 | 1828 { |
5328 | 1829 if (STRNCMP(lbuf, "!_TAG_", 6) != 0) |
1830 /* Non-header item before the header, e.g. "!" itself. | |
1831 */ | |
1832 goto parse_line; | |
1833 | |
3131 | 1834 /* |
1835 * Read header line. | |
1836 */ | |
1837 #ifdef FEAT_TAG_BINS | |
1838 if (STRNCMP(lbuf, "!_TAG_FILE_SORTED\t", 18) == 0) | |
1839 tag_file_sorted = lbuf[18]; | |
1840 #endif | |
1841 #ifdef FEAT_MBYTE | |
1842 if (STRNCMP(lbuf, "!_TAG_FILE_ENCODING\t", 20) == 0) | |
1843 { | |
1844 /* Prepare to convert every line from the specified | |
1845 * encoding to 'encoding'. */ | |
1846 for (p = lbuf + 20; *p > ' ' && *p < 127; ++p) | |
1847 ; | |
1848 *p = NUL; | |
1849 convert_setup(&vimconv, lbuf + 20, p_enc); | |
1850 } | |
1851 #endif | |
1852 | |
1853 /* Read the next line. Unrecognized flags are ignored. */ | |
1854 continue; | |
1855 } | |
1856 | |
1857 /* Headers ends. */ | |
1858 | |
7 | 1859 #ifdef FEAT_TAG_BINS |
1860 /* | |
1861 * When there is no tag head, or ignoring case, need to do a | |
1862 * linear search. | |
1863 * When no "!_TAG_" is found, default to binary search. If | |
1864 * the tag file isn't sorted, the second loop will find it. | |
1865 * When "!_TAG_FILE_SORTED" found: start binary search if | |
1866 * flag set. | |
1867 * For cscope, it's always linear. | |
1868 */ | |
1869 # ifdef FEAT_CSCOPE | |
1870 if (linear || use_cscope) | |
1871 # else | |
1872 if (linear) | |
1873 # endif | |
1874 state = TS_LINEAR; | |
3131 | 1875 else if (tag_file_sorted == NUL) |
7 | 1876 state = TS_BINARY; |
3131 | 1877 else if (tag_file_sorted == '1') |
7 | 1878 state = TS_BINARY; |
3131 | 1879 else if (tag_file_sorted == '2') |
1880 { | |
1881 state = TS_BINARY; | |
1882 sortic = TRUE; | |
1883 orgpat.regmatch.rm_ic = (p_ic || !noic); | |
7 | 1884 } |
3131 | 1885 else |
1886 state = TS_LINEAR; | |
1887 | |
1888 if (state == TS_BINARY && orgpat.regmatch.rm_ic && !sortic) | |
7 | 1889 { |
3206 | 1890 /* Binary search won't work for ignoring case, use linear |
7 | 1891 * search. */ |
1892 linear = TRUE; | |
1893 state = TS_LINEAR; | |
1894 } | |
1895 #else | |
1896 state = TS_LINEAR; | |
1897 #endif | |
1898 | |
1899 #ifdef FEAT_TAG_BINS | |
1900 /* | |
1901 * When starting a binary search, get the size of the file and | |
1902 * compute the first offset. | |
1903 */ | |
1904 if (state == TS_BINARY) | |
1905 { | |
1906 /* Get the tag file size (don't use mch_fstat(), it's not | |
1907 * portable). */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1908 if ((filesize = vim_lseek(fileno(fp), |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1909 (off_T)0L, SEEK_END)) <= 0) |
7 | 1910 state = TS_LINEAR; |
1911 else | |
1912 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1913 vim_lseek(fileno(fp), (off_T)0L, SEEK_SET); |
7 | 1914 |
1915 /* Calculate the first read offset in the file. Start | |
1916 * the search in the middle of the file. */ | |
1917 search_info.low_offset = 0; | |
1918 search_info.low_char = 0; | |
1919 search_info.high_offset = filesize; | |
1920 search_info.curr_offset = 0; | |
1921 search_info.high_char = 0xff; | |
1922 } | |
1923 continue; | |
1924 } | |
1925 #endif | |
1926 } | |
1927 | |
5328 | 1928 parse_line: |
7 | 1929 /* |
1930 * Figure out where the different strings are in this line. | |
1931 * For "normal" tags: Do a quick check if the tag matches. | |
1932 * This speeds up tag searching a lot! | |
1933 */ | |
3131 | 1934 if (orgpat.headlen |
7 | 1935 #ifdef FEAT_EMACS_TAGS |
1936 && !is_etag | |
1937 #endif | |
1938 ) | |
1939 { | |
1940 tagp.tagname = lbuf; | |
1941 #ifdef FEAT_TAG_ANYWHITE | |
1942 tagp.tagname_end = skiptowhite(lbuf); | |
3192 | 1943 if (*tagp.tagname_end == NUL) |
7 | 1944 #else |
1945 tagp.tagname_end = vim_strchr(lbuf, TAB); | |
3192 | 1946 if (tagp.tagname_end == NULL) |
7 | 1947 #endif |
1948 { | |
3192 | 1949 if (vim_strchr(lbuf, NL) == NULL) |
1950 { | |
1951 /* Truncated line, ignore it. Has been reported for | |
1952 * Mozilla JS with extremely long names. */ | |
1953 if (p_verbose >= 5) | |
1954 { | |
1955 verbose_enter(); | |
1956 MSG(_("Ignoring long line in tags file")); | |
1957 verbose_leave(); | |
1958 } | |
3206 | 1959 #ifdef FEAT_TAG_BINS |
1960 if (state != TS_LINEAR) | |
1961 { | |
1962 /* Avoid getting stuck. */ | |
1963 linear = TRUE; | |
1964 state = TS_LINEAR; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1965 vim_fseek(fp, search_info.low_offset, SEEK_SET); |
3206 | 1966 } |
1967 #endif | |
3192 | 1968 continue; |
1969 } | |
1970 | |
1971 /* Corrupted tag line. */ | |
7 | 1972 line_error = TRUE; |
1973 break; | |
1974 } | |
1975 | |
1976 #ifdef FEAT_TAG_OLDSTATIC | |
1977 /* | |
1978 * Check for old style static tag: "file:tag file .." | |
1979 */ | |
1980 tagp.fname = NULL; | |
1981 for (p = lbuf; p < tagp.tagname_end; ++p) | |
1982 { | |
1983 if (*p == ':') | |
1984 { | |
1985 if (tagp.fname == NULL) | |
1986 #ifdef FEAT_TAG_ANYWHITE | |
1987 tagp.fname = skipwhite(tagp.tagname_end); | |
1988 #else | |
1989 tagp.fname = tagp.tagname_end + 1; | |
1990 #endif | |
1991 if ( fnamencmp(lbuf, tagp.fname, p - lbuf) == 0 | |
1992 #ifdef FEAT_TAG_ANYWHITE | |
1993 && vim_iswhite(tagp.fname[p - lbuf]) | |
1994 #else | |
1995 && tagp.fname[p - lbuf] == TAB | |
1996 #endif | |
1997 ) | |
1998 { | |
1999 /* found one */ | |
2000 tagp.tagname = p + 1; | |
2001 break; | |
2002 } | |
2003 } | |
2004 } | |
2005 #endif | |
2006 | |
2007 /* | |
2008 * Skip this line if the length of the tag is different and | |
2009 * there is no regexp, or the tag is too short. | |
2010 */ | |
2011 cmplen = (int)(tagp.tagname_end - tagp.tagname); | |
2012 if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */ | |
2013 cmplen = p_tl; | |
3131 | 2014 if (has_re && orgpat.headlen < cmplen) |
2015 cmplen = orgpat.headlen; | |
2016 else if (state == TS_LINEAR && orgpat.headlen != cmplen) | |
7 | 2017 continue; |
2018 | |
2019 #ifdef FEAT_TAG_BINS | |
2020 if (state == TS_BINARY) | |
2021 { | |
2022 /* | |
2023 * Simplistic check for unsorted tags file. | |
2024 */ | |
2025 i = (int)tagp.tagname[0]; | |
2026 if (sortic) | |
2027 i = (int)TOUPPER_ASC(tagp.tagname[0]); | |
2028 if (i < search_info.low_char || i > search_info.high_char) | |
2029 sort_error = TRUE; | |
2030 | |
2031 /* | |
2032 * Compare the current tag with the searched tag. | |
2033 */ | |
2034 if (sortic) | |
3131 | 2035 tagcmp = tag_strnicmp(tagp.tagname, orgpat.head, |
7 | 2036 (size_t)cmplen); |
2037 else | |
3131 | 2038 tagcmp = STRNCMP(tagp.tagname, orgpat.head, cmplen); |
7 | 2039 |
2040 /* | |
2041 * A match with a shorter tag means to search forward. | |
2042 * A match with a longer tag means to search backward. | |
2043 */ | |
2044 if (tagcmp == 0) | |
2045 { | |
3131 | 2046 if (cmplen < orgpat.headlen) |
7 | 2047 tagcmp = -1; |
3131 | 2048 else if (cmplen > orgpat.headlen) |
7 | 2049 tagcmp = 1; |
2050 } | |
2051 | |
2052 if (tagcmp == 0) | |
2053 { | |
2054 /* We've located the tag, now skip back and search | |
2055 * forward until the first matching tag is found. | |
2056 */ | |
2057 state = TS_SKIP_BACK; | |
2058 search_info.match_offset = search_info.curr_offset; | |
2059 continue; | |
2060 } | |
2061 if (tagcmp < 0) | |
2062 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
2063 search_info.curr_offset = vim_ftell(fp); |
7 | 2064 if (search_info.curr_offset < search_info.high_offset) |
2065 { | |
2066 search_info.low_offset = search_info.curr_offset; | |
2067 if (sortic) | |
2068 search_info.low_char = | |
2069 TOUPPER_ASC(tagp.tagname[0]); | |
2070 else | |
2071 search_info.low_char = tagp.tagname[0]; | |
2072 continue; | |
2073 } | |
2074 } | |
2075 if (tagcmp > 0 | |
2076 && search_info.curr_offset != search_info.high_offset) | |
2077 { | |
2078 search_info.high_offset = search_info.curr_offset; | |
2079 if (sortic) | |
2080 search_info.high_char = | |
2081 TOUPPER_ASC(tagp.tagname[0]); | |
2082 else | |
2083 search_info.high_char = tagp.tagname[0]; | |
2084 continue; | |
2085 } | |
2086 | |
2087 /* No match yet and are at the end of the binary search. */ | |
2088 break; | |
2089 } | |
2090 else if (state == TS_SKIP_BACK) | |
2091 { | |
3131 | 2092 if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) |
7 | 2093 state = TS_STEP_FORWARD; |
2094 else | |
2095 /* Have to skip back more. Restore the curr_offset | |
2096 * used, otherwise we get stuck at a long line. */ | |
2097 search_info.curr_offset = search_info.curr_offset_used; | |
2098 continue; | |
2099 } | |
2100 else if (state == TS_STEP_FORWARD) | |
2101 { | |
3131 | 2102 if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) |
7 | 2103 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
2104 if ((off_T)vim_ftell(fp) > search_info.match_offset) |
7 | 2105 break; /* past last match */ |
2106 else | |
2107 continue; /* before first match */ | |
2108 } | |
2109 } | |
2110 else | |
2111 #endif | |
2112 /* skip this match if it can't match */ | |
3131 | 2113 if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) |
7 | 2114 continue; |
2115 | |
2116 /* | |
2117 * Can be a matching tag, isolate the file name and command. | |
2118 */ | |
2119 #ifdef FEAT_TAG_OLDSTATIC | |
2120 if (tagp.fname == NULL) | |
2121 #endif | |
2122 #ifdef FEAT_TAG_ANYWHITE | |
2123 tagp.fname = skipwhite(tagp.tagname_end); | |
2124 #else | |
2125 tagp.fname = tagp.tagname_end + 1; | |
2126 #endif | |
2127 #ifdef FEAT_TAG_ANYWHITE | |
2128 tagp.fname_end = skiptowhite(tagp.fname); | |
2129 tagp.command = skipwhite(tagp.fname_end); | |
2130 if (*tagp.command == NUL) | |
2131 #else | |
2132 tagp.fname_end = vim_strchr(tagp.fname, TAB); | |
2133 tagp.command = tagp.fname_end + 1; | |
2134 if (tagp.fname_end == NULL) | |
2135 #endif | |
2136 i = FAIL; | |
2137 else | |
2138 i = OK; | |
2139 } | |
2140 else | |
2141 i = parse_tag_line(lbuf, | |
2142 #ifdef FEAT_EMACS_TAGS | |
2143 is_etag, | |
2144 #endif | |
2145 &tagp); | |
2146 if (i == FAIL) | |
2147 { | |
2148 line_error = TRUE; | |
2149 break; | |
2150 } | |
2151 | |
2152 #ifdef FEAT_EMACS_TAGS | |
2153 if (is_etag) | |
2154 tagp.fname = ebuf; | |
2155 #endif | |
2156 /* | |
2157 * First try matching with the pattern literally (also when it is | |
2158 * a regexp). | |
2159 */ | |
2160 cmplen = (int)(tagp.tagname_end - tagp.tagname); | |
2161 if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */ | |
2162 cmplen = p_tl; | |
2163 /* if tag length does not match, don't try comparing */ | |
3131 | 2164 if (orgpat.len != cmplen) |
7 | 2165 match = FALSE; |
2166 else | |
2167 { | |
3131 | 2168 if (orgpat.regmatch.rm_ic) |
7 | 2169 { |
3131 | 2170 match = (MB_STRNICMP(tagp.tagname, orgpat.pat, cmplen) == 0); |
7 | 2171 if (match) |
3131 | 2172 match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat, |
7 | 2173 cmplen) == 0); |
2174 } | |
2175 else | |
3131 | 2176 match = (STRNCMP(tagp.tagname, orgpat.pat, cmplen) == 0); |
7 | 2177 } |
2178 | |
2179 /* | |
2180 * Has a regexp: Also find tags matching regexp. | |
2181 */ | |
2182 match_re = FALSE; | |
3131 | 2183 if (!match && orgpat.regmatch.regprog != NULL) |
7 | 2184 { |
2185 int cc; | |
2186 | |
2187 cc = *tagp.tagname_end; | |
2188 *tagp.tagname_end = NUL; | |
3131 | 2189 match = vim_regexec(&orgpat.regmatch, tagp.tagname, (colnr_T)0); |
7 | 2190 if (match) |
2191 { | |
3131 | 2192 matchoff = (int)(orgpat.regmatch.startp[0] - tagp.tagname); |
2193 if (orgpat.regmatch.rm_ic) | |
7 | 2194 { |
3131 | 2195 orgpat.regmatch.rm_ic = FALSE; |
2196 match_no_ic = vim_regexec(&orgpat.regmatch, tagp.tagname, | |
7 | 2197 (colnr_T)0); |
3131 | 2198 orgpat.regmatch.rm_ic = TRUE; |
7 | 2199 } |
2200 } | |
2201 *tagp.tagname_end = cc; | |
2202 match_re = TRUE; | |
2203 } | |
2204 | |
2205 /* | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2206 * If a match is found, add it to ht_match[]. |
7 | 2207 */ |
2208 if (match) | |
2209 { | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2210 int len = 0; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2211 |
7 | 2212 #ifdef FEAT_CSCOPE |
2213 if (use_cscope) | |
2214 { | |
2215 /* Don't change the ordering, always use the same table. */ | |
2216 mtt = MT_GL_OTH; | |
2217 } | |
2218 else | |
2219 #endif | |
2220 { | |
2221 /* Decide in which array to store this match. */ | |
2222 is_current = test_for_current( | |
2223 #ifdef FEAT_EMACS_TAGS | |
2224 is_etag, | |
2225 #endif | |
2226 tagp.fname, tagp.fname_end, tag_fname, | |
2227 buf_ffname); | |
2228 #ifdef FEAT_EMACS_TAGS | |
2229 is_static = FALSE; | |
2230 if (!is_etag) /* emacs tags are never static */ | |
2231 #endif | |
2232 { | |
2233 #ifdef FEAT_TAG_OLDSTATIC | |
2234 if (tagp.tagname != lbuf) | |
2235 is_static = TRUE; /* detected static tag before */ | |
2236 else | |
2237 #endif | |
2238 is_static = test_for_static(&tagp); | |
2239 } | |
2240 | |
2241 /* decide in which of the sixteen tables to store this | |
2242 * match */ | |
2243 if (is_static) | |
2244 { | |
2245 if (is_current) | |
2246 mtt = MT_ST_CUR; | |
2247 else | |
2248 mtt = MT_ST_OTH; | |
2249 } | |
2250 else | |
2251 { | |
2252 if (is_current) | |
2253 mtt = MT_GL_CUR; | |
2254 else | |
2255 mtt = MT_GL_OTH; | |
2256 } | |
3131 | 2257 if (orgpat.regmatch.rm_ic && !match_no_ic) |
7 | 2258 mtt += MT_IC_OFF; |
2259 if (match_re) | |
2260 mtt += MT_RE_OFF; | |
2261 } | |
2262 | |
2263 /* | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2264 * Add the found match in ht_match[mtt]. |
7 | 2265 * Store the info we need later, which depends on the kind of |
2266 * tags we are dealing with. | |
2267 */ | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2268 if (help_only) |
7 | 2269 { |
2270 #ifdef FEAT_MULTI_LANG | |
2271 # define ML_EXTRA 3 | |
2272 #else | |
2273 # define ML_EXTRA 0 | |
2274 #endif | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2275 /* |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2276 * Append the help-heuristic number after the tagname, for |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2277 * sorting it later. The heuristic is ignored for |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2278 * detecting duplicates. |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2279 * The format is {tagname}@{lang}NUL{heuristic}NUL |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2280 */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2281 *tagp.tagname_end = NUL; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2282 len = (int)(tagp.tagname_end - tagp.tagname); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2283 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 10 + ML_EXTRA + 1); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2284 if (mfp != NULL) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2285 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2286 int heuristic; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2287 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2288 p = mfp; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2289 STRCPY(p, tagp.tagname); |
7 | 2290 #ifdef FEAT_MULTI_LANG |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2291 p[len] = '@'; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2292 STRCPY(p + len + 1, help_lang); |
7 | 2293 #endif |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2294 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2295 heuristic = help_heuristic(tagp.tagname, |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2296 match_re ? matchoff : 0, !match_no_ic); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2297 #ifdef FEAT_MULTI_LANG |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2298 heuristic += help_pri; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2299 #endif |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2300 sprintf((char *)p + len + 1 + ML_EXTRA, "%06d", |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2301 heuristic); |
7 | 2302 } |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2303 *tagp.tagname_end = TAB; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2304 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2305 else if (name_only) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2306 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2307 if (get_it_again) |
7 | 2308 { |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2309 char_u *temp_end = tagp.command; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2310 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2311 if (*temp_end == '/') |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2312 while (*temp_end && *temp_end != '\r' |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2313 && *temp_end != '\n' |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2314 && *temp_end != '$') |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2315 temp_end++; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2316 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2317 if (tagp.command + 2 < temp_end) |
7 | 2318 { |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2319 len = (int)(temp_end - tagp.command - 2); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2320 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2321 if (mfp != NULL) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2322 vim_strncpy(mfp, tagp.command + 2, len); |
7 | 2323 } |
2324 else | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2325 mfp = NULL; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2326 get_it_again = FALSE; |
7 | 2327 } |
2328 else | |
2329 { | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2330 len = (int)(tagp.tagname_end - tagp.tagname); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2331 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2332 if (mfp != NULL) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2333 vim_strncpy(mfp, tagp.tagname, len); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2334 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2335 /* if wanted, re-read line to get long form too */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2336 if (State & INSERT) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2337 get_it_again = p_sft; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2338 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2339 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2340 else |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2341 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2342 #define TAG_SEP 0x01 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2343 size_t tag_fname_len = STRLEN(tag_fname); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2344 #ifdef FEAT_EMACS_TAGS |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2345 size_t ebuf_len = 0; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2346 #endif |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2347 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2348 /* Save the tag in a buffer. |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2349 * Use 0x01 to separate fields (Can't use NUL, because the |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2350 * hash key is terminated by NUL). |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2351 * Emacs tag: <mtt><tag_fname><0x01><ebuf><0x01><lbuf><NUL> |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2352 * other tag: <mtt><tag_fname><0x01><0x01><lbuf><NUL> |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2353 * without Emacs tags: <mtt><tag_fname><0x01><lbuf><NUL> |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2354 */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2355 len = (int)tag_fname_len + (int)STRLEN(lbuf) + 3; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2356 #ifdef FEAT_EMACS_TAGS |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2357 if (is_etag) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2358 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2359 ebuf_len = STRLEN(ebuf); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2360 len += (int)ebuf_len + 1; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2361 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2362 else |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2363 ++len; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2364 #endif |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2365 mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2366 if (mfp != NULL) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2367 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2368 p = mfp; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2369 p[0] = mtt; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2370 STRCPY(p + 1, tag_fname); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2371 #ifdef BACKSLASH_IN_FILENAME |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2372 /* Ignore differences in slashes, avoid adding |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2373 * both path/file and path\file. */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2374 slash_adjust(p + 1); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2375 #endif |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2376 p[tag_fname_len + 1] = TAG_SEP; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2377 s = p + 1 + tag_fname_len + 1; |
7 | 2378 #ifdef FEAT_EMACS_TAGS |
2379 if (is_etag) | |
2380 { | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2381 STRCPY(s, ebuf); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2382 s[ebuf_len] = TAG_SEP; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2383 s += ebuf_len + 1; |
7 | 2384 } |
2385 else | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2386 *s++ = TAG_SEP; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2387 #endif |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2388 STRCPY(s, lbuf); |
7 | 2389 } |
2390 } | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2391 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2392 if (mfp != NULL) |
7 | 2393 { |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2394 hashitem_T *hi; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2395 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2396 /* |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2397 * Don't add identical matches. |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2398 * Add all cscope tags, because they are all listed. |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2399 * "mfp" is used as a hash key, there is a NUL byte to end |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2400 * the part matters for comparing, more bytes may follow |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2401 * after it. E.g. help tags store the priority after the |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2402 * NUL. |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2403 */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2404 #ifdef FEAT_CSCOPE |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2405 if (use_cscope) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2406 hash++; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2407 else |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2408 #endif |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2409 hash = hash_hash(mfp); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2410 hi = hash_lookup(&ht_match[mtt], mfp, hash); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2411 if (HASHITEM_EMPTY(hi)) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2412 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2413 if (hash_add_item(&ht_match[mtt], hi, mfp, hash) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2414 == FAIL) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2415 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2416 /* Out of memory! Just forget about the rest. */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2417 retval = OK; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2418 stop_searching = TRUE; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2419 break; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2420 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2421 else |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2422 ++match_count; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2423 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2424 else |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2425 /* duplicate tag, drop it */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2426 vim_free(mfp); |
7 | 2427 } |
2428 } | |
2429 #ifdef FEAT_CSCOPE | |
2430 if (use_cscope && eof) | |
2431 break; | |
2432 #endif | |
2433 } /* forever */ | |
2434 | |
2435 if (line_error) | |
2436 { | |
2437 EMSG2(_("E431: Format error in tags file \"%s\""), tag_fname); | |
2438 #ifdef FEAT_CSCOPE | |
2439 if (!use_cscope) | |
2440 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
2441 EMSGN(_("Before byte %ld"), (long)vim_ftell(fp)); |
7 | 2442 stop_searching = TRUE; |
2443 line_error = FALSE; | |
2444 } | |
2445 | |
2446 #ifdef FEAT_CSCOPE | |
2447 if (!use_cscope) | |
2448 #endif | |
2449 fclose(fp); | |
2450 #ifdef FEAT_EMACS_TAGS | |
2451 while (incstack_idx) | |
2452 { | |
2453 --incstack_idx; | |
2454 fclose(incstack[incstack_idx].fp); | |
2455 vim_free(incstack[incstack_idx].etag_fname); | |
2456 } | |
2457 #endif | |
2458 #ifdef FEAT_MBYTE | |
2459 if (vimconv.vc_type != CONV_NONE) | |
2460 convert_setup(&vimconv, NULL, NULL); | |
2461 #endif | |
2462 | |
2463 #ifdef FEAT_TAG_BINS | |
3131 | 2464 tag_file_sorted = NUL; |
7 | 2465 if (sort_error) |
2466 { | |
2467 EMSG2(_("E432: Tags file not sorted: %s"), tag_fname); | |
2468 sort_error = FALSE; | |
2469 } | |
2470 #endif | |
2471 | |
2472 /* | |
2473 * Stop searching if sufficient tags have been found. | |
2474 */ | |
2475 if (match_count >= mincount) | |
2476 { | |
2477 retval = OK; | |
2478 stop_searching = TRUE; | |
2479 } | |
2480 | |
2481 #ifdef FEAT_CSCOPE | |
2482 if (stop_searching || use_cscope) | |
2483 #else | |
2484 if (stop_searching) | |
2485 #endif | |
2486 break; | |
2487 | |
2488 } /* end of for-each-file loop */ | |
2489 | |
692 | 2490 #ifdef FEAT_CSCOPE |
2491 if (!use_cscope) | |
2492 #endif | |
2493 tagname_free(&tn); | |
2494 | |
7 | 2495 #ifdef FEAT_TAG_BINS |
413 | 2496 /* stop searching when already did a linear search, or when TAG_NOIC |
2497 * used, and 'ignorecase' not set or already did case-ignore search */ | |
3131 | 2498 if (stop_searching || linear || (!p_ic && noic) || orgpat.regmatch.rm_ic) |
7 | 2499 break; |
2500 # ifdef FEAT_CSCOPE | |
2501 if (use_cscope) | |
2502 break; | |
2503 # endif | |
3131 | 2504 orgpat.regmatch.rm_ic = TRUE; /* try another time while ignoring case */ |
7 | 2505 } |
2506 #endif | |
2507 | |
2508 if (!stop_searching) | |
2509 { | |
2510 if (!did_open && verbose) /* never opened any tags file */ | |
2511 EMSG(_("E433: No tags file")); | |
2512 retval = OK; /* It's OK even when no tag found */ | |
2513 } | |
2514 | |
2515 findtag_end: | |
2516 vim_free(lbuf); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
3804
diff
changeset
|
2517 vim_regfree(orgpat.regmatch.regprog); |
7 | 2518 vim_free(tag_fname); |
2519 #ifdef FEAT_EMACS_TAGS | |
2520 vim_free(ebuf); | |
2521 #endif | |
2522 | |
2523 /* | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2524 * Move the matches from the ht_match[] arrays into one list of |
7 | 2525 * matches. When retval == FAIL, free the matches. |
2526 */ | |
2527 if (retval == FAIL) | |
2528 match_count = 0; | |
2529 | |
2530 if (match_count > 0) | |
2531 matches = (char_u **)lalloc((long_u)(match_count * sizeof(char_u *)), | |
2532 TRUE); | |
2533 else | |
2534 matches = NULL; | |
2535 match_count = 0; | |
2536 for (mtt = 0; mtt < MT_COUNT; ++mtt) | |
2537 { | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2538 hashitem_T *hi; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2539 long_u todo; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2540 |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2541 todo = (long)ht_match[mtt].ht_used; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2542 for (hi = ht_match[mtt].ht_array; todo > 0; ++hi) |
7 | 2543 { |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2544 if (!HASHITEM_EMPTY(hi)) |
7 | 2545 { |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2546 mfp = hi->hi_key; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2547 if (matches == NULL) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2548 vim_free(mfp); |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2549 else |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2550 { |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2551 /* now change the TAG_SEP back to NUL */ |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2552 for (p = mfp; *p != NUL; ++p) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2553 if (*p == TAG_SEP) |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2554 *p = NUL; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2555 matches[match_count++] = (char_u *)mfp; |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2556 } |
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2557 todo--; |
7 | 2558 } |
2559 } | |
10601
1b09db809d3f
patch 8.0.0190: finding duplicate tags uses a slow linear search
Christian Brabandt <cb@256bit.org>
parents:
10444
diff
changeset
|
2560 hash_clear(&ht_match[mtt]); |
7 | 2561 } |
2562 | |
2563 *matchesp = matches; | |
2564 *num_matches = match_count; | |
2565 | |
2566 curbuf->b_help = help_save; | |
2567 #ifdef FEAT_MULTI_LANG | |
2568 vim_free(saved_pat); | |
2569 #endif | |
2570 | |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
2571 p_ic = save_p_ic; |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
2572 |
7 | 2573 return retval; |
2574 } | |
2575 | |
2576 static garray_T tag_fnames = GA_EMPTY; | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
2577 static void found_tagfile_cb(char_u *fname, void *cookie); |
7 | 2578 |
2579 /* | |
2580 * Callback function for finding all "tags" and "tags-??" files in | |
2581 * 'runtimepath' doc directories. | |
2582 */ | |
2583 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2584 found_tagfile_cb(char_u *fname, void *cookie UNUSED) |
7 | 2585 { |
2586 if (ga_grow(&tag_fnames, 1) == OK) | |
2587 ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = | |
2588 vim_strsave(fname); | |
2589 } | |
2590 | |
359 | 2591 #if defined(EXITFREE) || defined(PROTO) |
2592 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2593 free_tag_stuff(void) |
359 | 2594 { |
692 | 2595 ga_clear_strings(&tag_fnames); |
359 | 2596 do_tag(NULL, DT_FREE, 0, 0, 0); |
1818 | 2597 tag_freematch(); |
2598 | |
2599 # if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2600 if (ptag_entry.tagname) | |
2601 { | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2185
diff
changeset
|
2602 vim_free(ptag_entry.tagname); |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2185
diff
changeset
|
2603 ptag_entry.tagname = NULL; |
1818 | 2604 } |
2605 # endif | |
359 | 2606 } |
2607 #endif | |
2608 | |
7 | 2609 /* |
2610 * Get the next name of a tag file from the tag file list. | |
2611 * For help files, use "tags" file only. | |
2612 * | |
2613 * Return FAIL if no more tag file names, OK otherwise. | |
2614 */ | |
514 | 2615 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2616 get_tagfname( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2617 tagname_T *tnp, /* holds status info */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2618 int first, /* TRUE when first file name is wanted */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2619 char_u *buf) /* pointer to buffer of MAXPATHL chars */ |
7 | 2620 { |
2621 char_u *fname = NULL; | |
2622 char_u *r_ptr; | |
2623 | |
692 | 2624 if (first) |
2625 vim_memset(tnp, 0, sizeof(tagname_T)); | |
2626 | |
514 | 2627 if (curbuf->b_help) |
7 | 2628 { |
514 | 2629 /* |
2630 * For help files it's done in a completely different way: | |
2631 * Find "doc/tags" and "doc/tags-??" in all directories in | |
2632 * 'runtimepath'. | |
2633 */ | |
2634 if (first) | |
7 | 2635 { |
2636 ga_clear_strings(&tag_fnames); | |
2637 ga_init2(&tag_fnames, (int)sizeof(char_u *), 10); | |
2638 do_in_runtimepath((char_u *) | |
2639 #ifdef FEAT_MULTI_LANG | |
36 | 2640 # ifdef VMS |
2641 /* Functions decc$to_vms() and decc$translate_vms() crash | |
2642 * on some VMS systems with wildcards "??". Seems ECO | |
2643 * patches do fix the problem in C RTL, but we can't use | |
2644 * an #ifdef for that. */ | |
2645 "doc/tags doc/tags-*" | |
2646 # else | |
7 | 2647 "doc/tags doc/tags-??" |
36 | 2648 # endif |
7 | 2649 #else |
2650 "doc/tags" | |
2651 #endif | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
2652 , DIP_ALL, found_tagfile_cb, NULL); |
7 | 2653 } |
602 | 2654 |
692 | 2655 if (tnp->tn_hf_idx >= tag_fnames.ga_len) |
7 | 2656 { |
2657 /* Not found in 'runtimepath', use 'helpfile', if it exists and | |
2658 * wasn't used yet, replacing "help.txt" with "tags". */ | |
692 | 2659 if (tnp->tn_hf_idx > tag_fnames.ga_len || *p_hf == NUL) |
7 | 2660 return FAIL; |
692 | 2661 ++tnp->tn_hf_idx; |
7 | 2662 STRCPY(buf, p_hf); |
2663 STRCPY(gettail(buf), "tags"); | |
2664 } | |
2665 else | |
692 | 2666 vim_strncpy(buf, ((char_u **)(tag_fnames.ga_data))[ |
2667 tnp->tn_hf_idx++], MAXPATHL - 1); | |
514 | 2668 return OK; |
2669 } | |
2670 | |
2671 if (first) | |
2672 { | |
692 | 2673 /* Init. We make a copy of 'tags', because autocommands may change |
2674 * the value without notifying us. */ | |
2675 tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL) | |
2676 ? curbuf->b_p_tags : p_tags); | |
2677 if (tnp->tn_tags == NULL) | |
2678 return FAIL; | |
2679 tnp->tn_np = tnp->tn_tags; | |
7 | 2680 } |
692 | 2681 |
2682 /* | |
2683 * Loop until we have found a file name that can be used. | |
2684 * There are two states: | |
2685 * tnp->tn_did_filefind_init == FALSE: setup for next part in 'tags'. | |
2686 * tnp->tn_did_filefind_init == TRUE: find next file in this part. | |
2687 */ | |
2688 for (;;) | |
7 | 2689 { |
692 | 2690 if (tnp->tn_did_filefind_init) |
7 | 2691 { |
692 | 2692 fname = vim_findfile(tnp->tn_search_ctx); |
2693 if (fname != NULL) | |
2694 break; | |
2695 | |
2696 tnp->tn_did_filefind_init = FALSE; | |
2697 } | |
2698 else | |
2699 { | |
2700 char_u *filename = NULL; | |
2701 | |
2702 /* Stop when used all parts of 'tags'. */ | |
2703 if (*tnp->tn_np == NUL) | |
7 | 2704 { |
692 | 2705 vim_findfile_cleanup(tnp->tn_search_ctx); |
2706 tnp->tn_search_ctx = NULL; | |
2707 return FAIL; | |
7 | 2708 } |
692 | 2709 |
2710 /* | |
2711 * Copy next file name into buf. | |
2712 */ | |
2713 buf[0] = NUL; | |
2714 (void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,"); | |
7 | 2715 |
2716 #ifdef FEAT_PATH_EXTRA | |
692 | 2717 r_ptr = vim_findfile_stopdir(buf); |
7 | 2718 #else |
692 | 2719 r_ptr = NULL; |
7 | 2720 #endif |
692 | 2721 /* move the filename one char forward and truncate the |
2722 * filepath with a NUL */ | |
2723 filename = gettail(buf); | |
1620 | 2724 STRMOVE(filename + 1, filename); |
692 | 2725 *filename++ = NUL; |
2726 | |
2727 tnp->tn_search_ctx = vim_findfile_init(buf, filename, | |
2728 r_ptr, 100, | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2185
diff
changeset
|
2729 FALSE, /* don't free visited list */ |
1541 | 2730 FINDFILE_FILE, /* we search for a file */ |
692 | 2731 tnp->tn_search_ctx, TRUE, curbuf->b_ffname); |
2732 if (tnp->tn_search_ctx != NULL) | |
2733 tnp->tn_did_filefind_init = TRUE; | |
7 | 2734 } |
2735 } | |
2736 | |
692 | 2737 STRCPY(buf, fname); |
2738 vim_free(fname); | |
7 | 2739 return OK; |
2740 } | |
2741 | |
2742 /* | |
692 | 2743 * Free the contents of a tagname_T that was filled by get_tagfname(). |
2744 */ | |
2745 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2746 tagname_free(tagname_T *tnp) |
692 | 2747 { |
2748 vim_free(tnp->tn_tags); | |
2749 vim_findfile_cleanup(tnp->tn_search_ctx); | |
1541 | 2750 tnp->tn_search_ctx = NULL; |
692 | 2751 ga_clear_strings(&tag_fnames); |
2752 } | |
2753 | |
2754 /* | |
7 | 2755 * Parse one line from the tags file. Find start/end of tag name, start/end of |
2756 * file name and start of search pattern. | |
2757 * | |
2758 * If is_etag is TRUE, tagp->fname and tagp->fname_end are not set. | |
2759 * | |
2760 * Return FAIL if there is a format error in this line, OK otherwise. | |
2761 */ | |
2762 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2763 parse_tag_line( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2764 char_u *lbuf, /* line to be parsed */ |
7 | 2765 #ifdef FEAT_EMACS_TAGS |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2766 int is_etag, |
7 | 2767 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2768 tagptrs_T *tagp) |
7 | 2769 { |
2770 char_u *p; | |
2771 | |
2772 #ifdef FEAT_EMACS_TAGS | |
2773 char_u *p_7f; | |
2774 | |
2775 if (is_etag) | |
2776 { | |
2777 /* | |
2778 * There are two formats for an emacs tag line: | |
2779 * 1: struct EnvBase ^?EnvBase^A139,4627 | |
2780 * 2: #define ARPB_WILD_WORLD ^?153,5194 | |
2781 */ | |
2782 p_7f = vim_strchr(lbuf, 0x7f); | |
2783 if (p_7f == NULL) | |
1770 | 2784 { |
2785 etag_fail: | |
2786 if (vim_strchr(lbuf, '\n') == NULL) | |
2787 { | |
2788 /* Truncated line. Ignore it. */ | |
2789 if (p_verbose >= 5) | |
2790 { | |
2791 verbose_enter(); | |
2792 MSG(_("Ignoring long line in tags file")); | |
2793 verbose_leave(); | |
2794 } | |
2795 tagp->command = lbuf; | |
2796 tagp->tagname = lbuf; | |
2797 tagp->tagname_end = lbuf; | |
2798 return OK; | |
2799 } | |
7 | 2800 return FAIL; |
1770 | 2801 } |
7 | 2802 |
2803 /* Find ^A. If not found the line number is after the 0x7f */ | |
2804 p = vim_strchr(p_7f, Ctrl_A); | |
2805 if (p == NULL) | |
2806 p = p_7f + 1; | |
2807 else | |
2808 ++p; | |
2809 | |
2810 if (!VIM_ISDIGIT(*p)) /* check for start of line number */ | |
1770 | 2811 goto etag_fail; |
7 | 2812 tagp->command = p; |
2813 | |
2814 | |
2815 if (p[-1] == Ctrl_A) /* first format: explicit tagname given */ | |
2816 { | |
2817 tagp->tagname = p_7f + 1; | |
2818 tagp->tagname_end = p - 1; | |
2819 } | |
2820 else /* second format: isolate tagname */ | |
2821 { | |
2822 /* find end of tagname */ | |
2823 for (p = p_7f - 1; !vim_iswordc(*p); --p) | |
2824 if (p == lbuf) | |
1770 | 2825 goto etag_fail; |
7 | 2826 tagp->tagname_end = p + 1; |
2827 while (p >= lbuf && vim_iswordc(*p)) | |
2828 --p; | |
2829 tagp->tagname = p + 1; | |
2830 } | |
2831 } | |
2832 else /* not an Emacs tag */ | |
2833 { | |
2834 #endif | |
2835 /* Isolate the tagname, from lbuf up to the first white */ | |
2836 tagp->tagname = lbuf; | |
2837 #ifdef FEAT_TAG_ANYWHITE | |
2838 p = skiptowhite(lbuf); | |
2839 #else | |
2840 p = vim_strchr(lbuf, TAB); | |
2841 if (p == NULL) | |
2842 return FAIL; | |
2843 #endif | |
2844 tagp->tagname_end = p; | |
2845 | |
2846 /* Isolate file name, from first to second white space */ | |
2847 #ifdef FEAT_TAG_ANYWHITE | |
2848 p = skipwhite(p); | |
2849 #else | |
2850 if (*p != NUL) | |
2851 ++p; | |
2852 #endif | |
2853 tagp->fname = p; | |
2854 #ifdef FEAT_TAG_ANYWHITE | |
2855 p = skiptowhite(p); | |
2856 #else | |
2857 p = vim_strchr(p, TAB); | |
2858 if (p == NULL) | |
2859 return FAIL; | |
2860 #endif | |
2861 tagp->fname_end = p; | |
2862 | |
2863 /* find start of search command, after second white space */ | |
2864 #ifdef FEAT_TAG_ANYWHITE | |
2865 p = skipwhite(p); | |
2866 #else | |
2867 if (*p != NUL) | |
2868 ++p; | |
2869 #endif | |
2870 if (*p == NUL) | |
2871 return FAIL; | |
2872 tagp->command = p; | |
2873 #ifdef FEAT_EMACS_TAGS | |
2874 } | |
2875 #endif | |
2876 | |
2877 return OK; | |
2878 } | |
2879 | |
2880 /* | |
2881 * Check if tagname is a static tag | |
2882 * | |
2883 * Static tags produced by the older ctags program have the format: | |
2884 * 'file:tag file /pattern'. | |
1204 | 2885 * This is only recognized when both occurrence of 'file' are the same, to |
7 | 2886 * avoid recognizing "string::string" or ":exit". |
2887 * | |
2888 * Static tags produced by the new ctags program have the format: | |
2889 * 'tag file /pattern/;"<Tab>file:' " | |
2890 * | |
2891 * Return TRUE if it is a static tag and adjust *tagname to the real tag. | |
2892 * Return FALSE if it is not a static tag. | |
2893 */ | |
2894 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2895 test_for_static(tagptrs_T *tagp) |
7 | 2896 { |
2897 char_u *p; | |
2898 | |
2899 #ifdef FEAT_TAG_OLDSTATIC | |
2900 int len; | |
2901 | |
2902 /* | |
2903 * Check for old style static tag: "file:tag file .." | |
2904 */ | |
2905 len = (int)(tagp->fname_end - tagp->fname); | |
2906 p = tagp->tagname + len; | |
2907 if ( p < tagp->tagname_end | |
2908 && *p == ':' | |
2909 && fnamencmp(tagp->tagname, tagp->fname, len) == 0) | |
2910 { | |
2911 tagp->tagname = p + 1; | |
2912 return TRUE; | |
2913 } | |
2914 #endif | |
2915 | |
2916 /* | |
2917 * Check for new style static tag ":...<Tab>file:[<Tab>...]" | |
2918 */ | |
2919 p = tagp->command; | |
2920 while ((p = vim_strchr(p, '\t')) != NULL) | |
2921 { | |
2922 ++p; | |
2923 if (STRNCMP(p, "file:", 5) == 0) | |
2924 return TRUE; | |
2925 } | |
2926 | |
2927 return FALSE; | |
2928 } | |
2929 | |
2930 /* | |
2931 * Parse a line from a matching tag. Does not change the line itself. | |
2932 * | |
2933 * The line that we get looks like this: | |
2934 * Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf> | |
2935 * other tag: <mtt><tag_fname><NUL><NUL><lbuf> | |
2936 * without Emacs tags: <mtt><tag_fname><NUL><lbuf> | |
2937 * | |
2938 * Return OK or FAIL. | |
2939 */ | |
2940 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2941 parse_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2942 char_u *lbuf, /* input: matching line */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2943 tagptrs_T *tagp) /* output: pointers into the line */ |
7 | 2944 { |
2945 int retval; | |
2946 char_u *p; | |
2947 char_u *pc, *pt; | |
2948 | |
2949 tagp->tag_fname = lbuf + 1; | |
2950 lbuf += STRLEN(tagp->tag_fname) + 2; | |
2951 #ifdef FEAT_EMACS_TAGS | |
2952 if (*lbuf) | |
2953 { | |
2954 tagp->is_etag = TRUE; | |
2955 tagp->fname = lbuf; | |
2956 lbuf += STRLEN(lbuf); | |
2957 tagp->fname_end = lbuf++; | |
2958 } | |
2959 else | |
2960 { | |
2961 tagp->is_etag = FALSE; | |
2962 ++lbuf; | |
2963 } | |
2964 #endif | |
2965 | |
2966 /* Find search pattern and the file name for non-etags. */ | |
2967 retval = parse_tag_line(lbuf, | |
2968 #ifdef FEAT_EMACS_TAGS | |
2969 tagp->is_etag, | |
2970 #endif | |
2971 tagp); | |
2972 | |
2973 tagp->tagkind = NULL; | |
2974 tagp->command_end = NULL; | |
2975 | |
2976 if (retval == OK) | |
2977 { | |
2978 /* Try to find a kind field: "kind:<kind>" or just "<kind>"*/ | |
2979 p = tagp->command; | |
2980 if (find_extra(&p) == OK) | |
2981 { | |
2982 tagp->command_end = p; | |
2983 p += 2; /* skip ";\"" */ | |
2984 if (*p++ == TAB) | |
2985 while (ASCII_ISALPHA(*p)) | |
2986 { | |
2987 if (STRNCMP(p, "kind:", 5) == 0) | |
2988 { | |
2989 tagp->tagkind = p + 5; | |
2990 break; | |
2991 } | |
2992 pc = vim_strchr(p, ':'); | |
2993 pt = vim_strchr(p, '\t'); | |
2994 if (pc == NULL || (pt != NULL && pc > pt)) | |
2995 { | |
2996 tagp->tagkind = p; | |
2997 break; | |
2998 } | |
2999 if (pt == NULL) | |
3000 break; | |
3001 p = pt + 1; | |
3002 } | |
3003 } | |
3004 if (tagp->tagkind != NULL) | |
3005 { | |
3006 for (p = tagp->tagkind; | |
3007 *p && *p != '\t' && *p != '\r' && *p != '\n'; ++p) | |
3008 ; | |
3009 tagp->tagkind_end = p; | |
3010 } | |
3011 } | |
3012 return retval; | |
3013 } | |
3014 | |
3015 /* | |
3016 * Find out the actual file name of a tag. Concatenate the tags file name | |
3017 * with the matching tag file name. | |
3018 * Returns an allocated string or NULL (out of memory). | |
3019 */ | |
3020 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3021 tag_full_fname(tagptrs_T *tagp) |
7 | 3022 { |
3023 char_u *fullname; | |
3024 int c; | |
3025 | |
3026 #ifdef FEAT_EMACS_TAGS | |
3027 if (tagp->is_etag) | |
3028 c = 0; /* to shut up GCC */ | |
3029 else | |
3030 #endif | |
3031 { | |
3032 c = *tagp->fname_end; | |
3033 *tagp->fname_end = NUL; | |
3034 } | |
3035 fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE); | |
3036 | |
3037 #ifdef FEAT_EMACS_TAGS | |
3038 if (!tagp->is_etag) | |
3039 #endif | |
3040 *tagp->fname_end = c; | |
3041 | |
3042 return fullname; | |
3043 } | |
3044 | |
3045 /* | |
3046 * Jump to a tag that has been found in one of the tag files | |
3047 * | |
3048 * returns OK for success, NOTAGFILE when file not found, FAIL otherwise. | |
3049 */ | |
3050 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3051 jumpto_tag( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3052 char_u *lbuf, /* line from the tags file for this tag */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3053 int forceit, /* :ta with ! */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3054 int keep_help) /* keep help flag (FALSE for cscope) */ |
7 | 3055 { |
3056 int save_secure; | |
3057 int save_magic; | |
3058 int save_p_ws, save_p_scs, save_p_ic; | |
3059 linenr_T save_lnum; | |
3060 int csave = 0; | |
3061 char_u *str; | |
3062 char_u *pbuf; /* search pattern buffer */ | |
3063 char_u *pbuf_end; | |
3064 char_u *tofree_fname = NULL; | |
3065 char_u *fname; | |
3066 tagptrs_T tagp; | |
3067 int retval = FAIL; | |
3068 int getfile_result; | |
3069 int search_options; | |
3070 #ifdef FEAT_SEARCH_EXTRA | |
3071 int save_no_hlsearch; | |
3072 #endif | |
3073 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
3074 win_T *curwin_save = NULL; | |
3075 #endif | |
3076 char_u *full_fname = NULL; | |
3077 #ifdef FEAT_FOLDING | |
3078 int old_KeyTyped = KeyTyped; /* getting the file may reset it */ | |
3079 #endif | |
3080 | |
3081 pbuf = alloc(LSIZE); | |
3082 | |
3083 /* parse the match line into the tagp structure */ | |
3084 if (pbuf == NULL || parse_match(lbuf, &tagp) == FAIL) | |
3085 { | |
3086 tagp.fname_end = NULL; | |
3087 goto erret; | |
3088 } | |
3089 | |
3090 /* truncate the file name, so it can be used as a string */ | |
3091 csave = *tagp.fname_end; | |
3092 *tagp.fname_end = NUL; | |
3093 fname = tagp.fname; | |
3094 | |
3095 /* copy the command to pbuf[], remove trailing CR/NL */ | |
3096 str = tagp.command; | |
3097 for (pbuf_end = pbuf; *str && *str != '\n' && *str != '\r'; ) | |
3098 { | |
3099 #ifdef FEAT_EMACS_TAGS | |
3100 if (tagp.is_etag && *str == ',')/* stop at ',' after line number */ | |
3101 break; | |
3102 #endif | |
3103 *pbuf_end++ = *str++; | |
3104 } | |
3105 *pbuf_end = NUL; | |
3106 | |
3107 #ifdef FEAT_EMACS_TAGS | |
3108 if (!tagp.is_etag) | |
3109 #endif | |
3110 { | |
3111 /* | |
3112 * Remove the "<Tab>fieldname:value" stuff; we don't need it here. | |
3113 */ | |
3114 str = pbuf; | |
3115 if (find_extra(&str) == OK) | |
3116 { | |
3117 pbuf_end = str; | |
3118 *pbuf_end = NUL; | |
3119 } | |
3120 } | |
3121 | |
3122 /* | |
3123 * Expand file name, when needed (for environment variables). | |
3124 * If 'tagrelative' option set, may change file name. | |
3125 */ | |
3126 fname = expand_tag_fname(fname, tagp.tag_fname, TRUE); | |
3127 if (fname == NULL) | |
3128 goto erret; | |
3129 tofree_fname = fname; /* free() it later */ | |
3130 | |
3131 /* | |
3132 * Check if the file with the tag exists before abandoning the current | |
3133 * file. Also accept a file name for which there is a matching BufReadCmd | |
3134 * autocommand event (e.g., http://sys/file). | |
3135 */ | |
3136 if (mch_getperm(fname) < 0 | |
3137 #ifdef FEAT_AUTOCMD | |
40 | 3138 && !has_autocmd(EVENT_BUFREADCMD, fname, NULL) |
7 | 3139 #endif |
3140 ) | |
3141 { | |
3142 retval = NOTAGFILE; | |
3143 vim_free(nofile_fname); | |
3144 nofile_fname = vim_strsave(fname); | |
3145 if (nofile_fname == NULL) | |
3146 nofile_fname = empty_option; | |
3147 goto erret; | |
3148 } | |
3149 | |
3150 ++RedrawingDisabled; | |
3151 | |
3152 #ifdef FEAT_GUI | |
3153 need_mouse_correct = TRUE; | |
3154 #endif | |
3155 | |
3156 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 3157 if (g_do_tagpreview != 0) |
7 | 3158 { |
728 | 3159 postponed_split = 0; /* don't split again below */ |
3160 curwin_save = curwin; /* Save current window */ | |
3161 | |
7 | 3162 /* |
3163 * If we are reusing a window, we may change dir when | |
3164 * entering it (autocommands) so turn the tag filename | |
3165 * into a fullpath | |
3166 */ | |
3167 if (!curwin->w_p_pvw) | |
3168 { | |
3169 full_fname = FullName_save(fname, FALSE); | |
3170 fname = full_fname; | |
3171 | |
3172 /* | |
3173 * Make the preview window the current window. | |
3174 * Open a preview window when needed. | |
3175 */ | |
816 | 3176 prepare_tagpreview(TRUE); |
7 | 3177 } |
3178 } | |
3179 | |
682 | 3180 /* If it was a CTRL-W CTRL-] command split window now. For ":tab tag" |
3181 * open a new tab page. */ | |
3182 if (postponed_split || cmdmod.tab != 0) | |
7 | 3183 { |
3184 win_split(postponed_split > 0 ? postponed_split : 0, | |
3185 postponed_split_flags); | |
2583 | 3186 RESET_BINDING(curwin); |
7 | 3187 } |
3188 #endif | |
3189 | |
3190 if (keep_help) | |
3191 { | |
3192 /* A :ta from a help file will keep the b_help flag set. For ":ptag" | |
3193 * we need to use the flag from the window where we came from. */ | |
3194 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 3195 if (g_do_tagpreview != 0) |
7 | 3196 keep_help_flag = curwin_save->w_buffer->b_help; |
3197 else | |
3198 #endif | |
3199 keep_help_flag = curbuf->b_help; | |
3200 } | |
3201 getfile_result = getfile(0, fname, NULL, TRUE, (linenr_T)0, forceit); | |
3202 keep_help_flag = FALSE; | |
3203 | |
3204 if (getfile_result <= 0) /* got to the right file */ | |
3205 { | |
3206 curwin->w_set_curswant = TRUE; | |
3207 #ifdef FEAT_WINDOWS | |
3208 postponed_split = 0; | |
3209 #endif | |
3210 | |
3211 save_secure = secure; | |
3212 secure = 1; | |
3213 #ifdef HAVE_SANDBOX | |
3214 ++sandbox; | |
3215 #endif | |
3216 save_magic = p_magic; | |
3217 p_magic = FALSE; /* always execute with 'nomagic' */ | |
3218 #ifdef FEAT_SEARCH_EXTRA | |
3219 /* Save value of no_hlsearch, jumping to a tag is not a real search */ | |
3220 save_no_hlsearch = no_hlsearch; | |
3221 #endif | |
3222 | |
3223 /* | |
3224 * If 'cpoptions' contains 't', store the search pattern for the "n" | |
3225 * command. If 'cpoptions' does not contain 't', the search pattern | |
3226 * is not stored. | |
3227 */ | |
3228 if (vim_strchr(p_cpo, CPO_TAGPAT) != NULL) | |
3229 search_options = 0; | |
3230 else | |
3231 search_options = SEARCH_KEEP; | |
3232 | |
3233 /* | |
3234 * If the command is a search, try here. | |
3235 * | |
3236 * Reset 'smartcase' for the search, since the search pattern was not | |
3237 * typed by the user. | |
3238 * Only use do_search() when there is a full search command, without | |
3239 * anything following. | |
3240 */ | |
3241 str = pbuf; | |
3242 if (pbuf[0] == '/' || pbuf[0] == '?') | |
3243 str = skip_regexp(pbuf + 1, pbuf[0], FALSE, NULL) + 1; | |
3244 if (str > pbuf_end - 1) /* search command with nothing following */ | |
3245 { | |
3246 save_p_ws = p_ws; | |
3247 save_p_ic = p_ic; | |
3248 save_p_scs = p_scs; | |
3249 p_ws = TRUE; /* need 'wrapscan' for backward searches */ | |
3250 p_ic = FALSE; /* don't ignore case now */ | |
3251 p_scs = FALSE; | |
3252 #if 0 /* disabled for now */ | |
3253 #ifdef FEAT_CMDHIST | |
3254 /* put pattern in search history */ | |
3255 add_to_history(HIST_SEARCH, pbuf + 1, TRUE, pbuf[0]); | |
3256 #endif | |
3257 #endif | |
3258 save_lnum = curwin->w_cursor.lnum; | |
3259 curwin->w_cursor.lnum = 0; /* start search before first line */ | |
1521 | 3260 if (do_search(NULL, pbuf[0], pbuf + 1, (long)1, |
3261 search_options, NULL)) | |
7 | 3262 retval = OK; |
3263 else | |
3264 { | |
3265 int found = 1; | |
3266 int cc; | |
3267 | |
3268 /* | |
3269 * try again, ignore case now | |
3270 */ | |
3271 p_ic = TRUE; | |
3272 if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1, | |
1521 | 3273 search_options, NULL)) |
7 | 3274 { |
3275 /* | |
3276 * Failed to find pattern, take a guess: "^func (" | |
3277 */ | |
3278 found = 2; | |
3279 (void)test_for_static(&tagp); | |
3280 cc = *tagp.tagname_end; | |
3281 *tagp.tagname_end = NUL; | |
3282 sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname); | |
1521 | 3283 if (!do_search(NULL, '/', pbuf, (long)1, |
3284 search_options, NULL)) | |
7 | 3285 { |
3286 /* Guess again: "^char * \<func (" */ | |
3287 sprintf((char *)pbuf, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(", | |
3288 tagp.tagname); | |
3289 if (!do_search(NULL, '/', pbuf, (long)1, | |
1521 | 3290 search_options, NULL)) |
7 | 3291 found = 0; |
3292 } | |
3293 *tagp.tagname_end = cc; | |
3294 } | |
3295 if (found == 0) | |
3296 { | |
3297 EMSG(_("E434: Can't find tag pattern")); | |
3298 curwin->w_cursor.lnum = save_lnum; | |
3299 } | |
3300 else | |
3301 { | |
3302 /* | |
3303 * Only give a message when really guessed, not when 'ic' | |
3304 * is set and match found while ignoring case. | |
3305 */ | |
3306 if (found == 2 || !save_p_ic) | |
3307 { | |
3308 MSG(_("E435: Couldn't find tag, just guessing!")); | |
3309 if (!msg_scrolled && msg_silent == 0) | |
3310 { | |
3311 out_flush(); | |
3312 ui_delay(1000L, TRUE); | |
3313 } | |
3314 } | |
3315 retval = OK; | |
3316 } | |
3317 } | |
3318 p_ws = save_p_ws; | |
3319 p_ic = save_p_ic; | |
3320 p_scs = save_p_scs; | |
3321 | |
3322 /* A search command may have positioned the cursor beyond the end | |
3323 * of the line. May need to correct that here. */ | |
3324 check_cursor(); | |
3325 } | |
3326 else | |
3327 { | |
3328 curwin->w_cursor.lnum = 1; /* start command in line 1 */ | |
3329 do_cmdline_cmd(pbuf); | |
3330 retval = OK; | |
3331 } | |
3332 | |
3333 /* | |
3334 * When the command has done something that is not allowed make sure | |
3335 * the error message can be seen. | |
3336 */ | |
3337 if (secure == 2) | |
3338 wait_return(TRUE); | |
3339 secure = save_secure; | |
3340 p_magic = save_magic; | |
3341 #ifdef HAVE_SANDBOX | |
3342 --sandbox; | |
3343 #endif | |
3344 #ifdef FEAT_SEARCH_EXTRA | |
3345 /* restore no_hlsearch when keeping the old search pattern */ | |
3346 if (search_options) | |
5458 | 3347 { |
3348 SET_NO_HLSEARCH(save_no_hlsearch); | |
3349 } | |
7 | 3350 #endif |
3351 | |
3352 /* Return OK if jumped to another file (at least we found the file!). */ | |
3353 if (getfile_result == -1) | |
3354 retval = OK; | |
3355 | |
3356 if (retval == OK) | |
3357 { | |
3358 /* | |
3359 * For a help buffer: Put the cursor line at the top of the window, | |
3360 * the help subject will be below it. | |
3361 */ | |
3362 if (curbuf->b_help) | |
3363 set_topline(curwin, curwin->w_cursor.lnum); | |
3364 #ifdef FEAT_FOLDING | |
3365 if ((fdo_flags & FDO_TAG) && old_KeyTyped) | |
3366 foldOpenCursor(); | |
3367 #endif | |
3368 } | |
3369 | |
3370 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 3371 if (g_do_tagpreview != 0 |
3372 && curwin != curwin_save && win_valid(curwin_save)) | |
7 | 3373 { |
3374 /* Return cursor to where we were */ | |
3375 validate_cursor(); | |
3376 redraw_later(VALID); | |
3377 win_enter(curwin_save, TRUE); | |
3378 } | |
3379 #endif | |
3380 | |
3381 --RedrawingDisabled; | |
3382 } | |
3383 else | |
3384 { | |
3385 --RedrawingDisabled; | |
3386 #ifdef FEAT_WINDOWS | |
3387 if (postponed_split) /* close the window */ | |
3388 { | |
3389 win_close(curwin, FALSE); | |
3390 postponed_split = 0; | |
3391 } | |
3392 #endif | |
3393 } | |
3394 | |
3395 erret: | |
3396 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
3397 g_do_tagpreview = 0; /* For next time */ | |
3398 #endif | |
3399 if (tagp.fname_end != NULL) | |
3400 *tagp.fname_end = csave; | |
3401 vim_free(pbuf); | |
3402 vim_free(tofree_fname); | |
3403 vim_free(full_fname); | |
3404 | |
3405 return retval; | |
3406 } | |
3407 | |
3408 /* | |
3409 * If "expand" is TRUE, expand wildcards in fname. | |
3410 * If 'tagrelative' option set, change fname (name of file containing tag) | |
3411 * according to tag_fname (name of tag file containing fname). | |
3412 * Returns a pointer to allocated memory (or NULL when out of memory). | |
3413 */ | |
3414 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3415 expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) |
7 | 3416 { |
3417 char_u *p; | |
3418 char_u *retval; | |
3419 char_u *expanded_fname = NULL; | |
3420 expand_T xpc; | |
3421 | |
3422 /* | |
3423 * Expand file name (for environment variables) when needed. | |
3424 */ | |
3425 if (expand && mch_has_wildcard(fname)) | |
3426 { | |
3427 ExpandInit(&xpc); | |
3428 xpc.xp_context = EXPAND_FILES; | |
3429 expanded_fname = ExpandOne(&xpc, (char_u *)fname, NULL, | |
3430 WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); | |
3431 if (expanded_fname != NULL) | |
3432 fname = expanded_fname; | |
3433 } | |
3434 | |
3435 if ((p_tr || curbuf->b_help) | |
3436 && !vim_isAbsName(fname) | |
3437 && (p = gettail(tag_fname)) != tag_fname) | |
3438 { | |
3439 retval = alloc(MAXPATHL); | |
3440 if (retval != NULL) | |
3441 { | |
3442 STRCPY(retval, tag_fname); | |
418 | 3443 vim_strncpy(retval + (p - tag_fname), fname, |
3444 MAXPATHL - (p - tag_fname) - 1); | |
7 | 3445 /* |
3446 * Translate names like "src/a/../b/file.c" into "src/b/file.c". | |
3447 */ | |
3448 simplify_filename(retval); | |
3449 } | |
3450 } | |
3451 else | |
3452 retval = vim_strsave(fname); | |
3453 | |
3454 vim_free(expanded_fname); | |
3455 | |
3456 return retval; | |
3457 } | |
3458 | |
3459 /* | |
3460 * Converts a file name into a canonical form. It simplifies a file name into | |
3461 * its simplest form by stripping out unneeded components, if any. The | |
3462 * resulting file name is simplified in place and will either be the same | |
3463 * length as that supplied, or shorter. | |
3464 */ | |
3465 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3466 simplify_filename(char_u *filename) |
7 | 3467 { |
3468 #ifndef AMIGA /* Amiga doesn't have "..", it uses "/" */ | |
3469 int components = 0; | |
3470 char_u *p, *tail, *start; | |
3471 int stripping_disabled = FALSE; | |
3472 int relative = TRUE; | |
3473 | |
3474 p = filename; | |
3475 #ifdef BACKSLASH_IN_FILENAME | |
3476 if (p[1] == ':') /* skip "x:" */ | |
3477 p += 2; | |
3478 #endif | |
3479 | |
3480 if (vim_ispathsep(*p)) | |
3481 { | |
3482 relative = FALSE; | |
3483 do | |
3484 ++p; | |
3485 while (vim_ispathsep(*p)); | |
3486 } | |
3487 start = p; /* remember start after "c:/" or "/" or "///" */ | |
3488 | |
3489 do | |
3490 { | |
3491 /* At this point "p" is pointing to the char following a single "/" | |
3492 * or "p" is at the "start" of the (absolute or relative) path name. */ | |
3493 #ifdef VMS | |
3494 /* VMS allows device:[path] - don't strip the [ in directory */ | |
3495 if ((*p == '[' || *p == '<') && p > filename && p[-1] == ':') | |
3496 { | |
3497 /* :[ or :< composition: vms directory component */ | |
3498 ++components; | |
3499 p = getnextcomp(p + 1); | |
3500 } | |
3501 /* allow remote calls as host"user passwd"::device:[path] */ | |
3502 else if (p[0] == ':' && p[1] == ':' && p > filename && p[-1] == '"' ) | |
3503 { | |
3504 /* ":: composition: vms host/passwd component */ | |
3505 ++components; | |
3506 p = getnextcomp(p + 2); | |
3507 } | |
3508 else | |
3509 #endif | |
3510 if (vim_ispathsep(*p)) | |
1620 | 3511 STRMOVE(p, p + 1); /* remove duplicate "/" */ |
7 | 3512 else if (p[0] == '.' && (vim_ispathsep(p[1]) || p[1] == NUL)) |
3513 { | |
3514 if (p == start && relative) | |
3515 p += 1 + (p[1] != NUL); /* keep single "." or leading "./" */ | |
3516 else | |
3517 { | |
3518 /* Strip "./" or ".///". If we are at the end of the file name | |
3519 * and there is no trailing path separator, either strip "/." if | |
3520 * we are after "start", or strip "." if we are at the beginning | |
3521 * of an absolute path name . */ | |
3522 tail = p + 1; | |
3523 if (p[1] != NUL) | |
3524 while (vim_ispathsep(*tail)) | |
39 | 3525 mb_ptr_adv(tail); |
7 | 3526 else if (p > start) |
3527 --p; /* strip preceding path separator */ | |
1620 | 3528 STRMOVE(p, tail); |
7 | 3529 } |
3530 } | |
3531 else if (p[0] == '.' && p[1] == '.' && | |
3532 (vim_ispathsep(p[2]) || p[2] == NUL)) | |
3533 { | |
3534 /* Skip to after ".." or "../" or "..///". */ | |
3535 tail = p + 2; | |
3536 while (vim_ispathsep(*tail)) | |
39 | 3537 mb_ptr_adv(tail); |
7 | 3538 |
3539 if (components > 0) /* strip one preceding component */ | |
3540 { | |
3541 int do_strip = FALSE; | |
3542 char_u saved_char; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
3543 stat_T st; |
7 | 3544 |
3545 /* Don't strip for an erroneous file name. */ | |
3546 if (!stripping_disabled) | |
3547 { | |
3548 /* If the preceding component does not exist in the file | |
3549 * system, we strip it. On Unix, we don't accept a symbolic | |
3550 * link that refers to a non-existent file. */ | |
3551 saved_char = p[-1]; | |
3552 p[-1] = NUL; | |
3553 #ifdef UNIX | |
3554 if (mch_lstat((char *)filename, &st) < 0) | |
3555 #else | |
3556 if (mch_stat((char *)filename, &st) < 0) | |
3557 #endif | |
3558 do_strip = TRUE; | |
3559 p[-1] = saved_char; | |
3560 | |
3561 --p; | |
3562 /* Skip back to after previous '/'. */ | |
39 | 3563 while (p > start && !after_pathsep(start, p)) |
3564 mb_ptr_back(start, p); | |
7 | 3565 |
3566 if (!do_strip) | |
3567 { | |
3568 /* If the component exists in the file system, check | |
3569 * that stripping it won't change the meaning of the | |
3570 * file name. First get information about the | |
3571 * unstripped file name. This may fail if the component | |
3572 * to strip is not a searchable directory (but a regular | |
3573 * file, for instance), since the trailing "/.." cannot | |
3574 * be applied then. We don't strip it then since we | |
3575 * don't want to replace an erroneous file name by | |
3576 * a valid one, and we disable stripping of later | |
3577 * components. */ | |
3578 saved_char = *tail; | |
3579 *tail = NUL; | |
3580 if (mch_stat((char *)filename, &st) >= 0) | |
3581 do_strip = TRUE; | |
3582 else | |
3583 stripping_disabled = TRUE; | |
3584 *tail = saved_char; | |
3585 #ifdef UNIX | |
3586 if (do_strip) | |
3587 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
3588 stat_T new_st; |
7 | 3589 |
3590 /* On Unix, the check for the unstripped file name | |
3591 * above works also for a symbolic link pointing to | |
3592 * a searchable directory. But then the parent of | |
3593 * the directory pointed to by the link must be the | |
3594 * same as the stripped file name. (The latter | |
3595 * exists in the file system since it is the | |
3596 * component's parent directory.) */ | |
3597 if (p == start && relative) | |
3598 (void)mch_stat(".", &new_st); | |
3599 else | |
3600 { | |
3601 saved_char = *p; | |
3602 *p = NUL; | |
3603 (void)mch_stat((char *)filename, &new_st); | |
3604 *p = saved_char; | |
3605 } | |
3606 | |
3607 if (new_st.st_ino != st.st_ino || | |
3608 new_st.st_dev != st.st_dev) | |
3609 { | |
3610 do_strip = FALSE; | |
3611 /* We don't disable stripping of later | |
3612 * components since the unstripped path name is | |
3613 * still valid. */ | |
3614 } | |
3615 } | |
3616 #endif | |
3617 } | |
3618 } | |
3619 | |
3620 if (!do_strip) | |
3621 { | |
3622 /* Skip the ".." or "../" and reset the counter for the | |
3623 * components that might be stripped later on. */ | |
3624 p = tail; | |
3625 components = 0; | |
3626 } | |
3627 else | |
3628 { | |
3629 /* Strip previous component. If the result would get empty | |
3630 * and there is no trailing path separator, leave a single | |
3631 * "." instead. If we are at the end of the file name and | |
3632 * there is no trailing path separator and a preceding | |
3633 * component is left after stripping, strip its trailing | |
3634 * path separator as well. */ | |
3635 if (p == start && relative && tail[-1] == '.') | |
3636 { | |
3637 *p++ = '.'; | |
3638 *p = NUL; | |
3639 } | |
3640 else | |
3641 { | |
3642 if (p > start && tail[-1] == '.') | |
3643 --p; | |
1620 | 3644 STRMOVE(p, tail); /* strip previous component */ |
7 | 3645 } |
3646 | |
3647 --components; | |
3648 } | |
3649 } | |
3650 else if (p == start && !relative) /* leading "/.." or "/../" */ | |
1620 | 3651 STRMOVE(p, tail); /* strip ".." or "../" */ |
7 | 3652 else |
3653 { | |
3654 if (p == start + 2 && p[-2] == '.') /* leading "./../" */ | |
3655 { | |
1620 | 3656 STRMOVE(p - 2, p); /* strip leading "./" */ |
7 | 3657 tail -= 2; |
3658 } | |
3659 p = tail; /* skip to char after ".." or "../" */ | |
3660 } | |
3661 } | |
3662 else | |
3663 { | |
3664 ++components; /* simple path component */ | |
3665 p = getnextcomp(p); | |
3666 } | |
3667 } while (*p != NUL); | |
3668 #endif /* !AMIGA */ | |
3669 } | |
3670 | |
3671 /* | |
3672 * Check if we have a tag for the buffer with name "buf_ffname". | |
3673 * This is a bit slow, because of the full path compare in fullpathcmp(). | |
3674 * Return TRUE if tag for file "fname" if tag file "tag_fname" is for current | |
3675 * file. | |
3676 */ | |
3677 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3678 test_for_current( |
7 | 3679 #ifdef FEAT_EMACS_TAGS |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3680 int is_etag, |
7 | 3681 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3682 char_u *fname, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3683 char_u *fname_end, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3684 char_u *tag_fname, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3685 char_u *buf_ffname) |
7 | 3686 { |
3687 int c; | |
3688 int retval = FALSE; | |
3689 char_u *fullname; | |
3690 | |
3691 if (buf_ffname != NULL) /* if the buffer has a name */ | |
3692 { | |
3693 #ifdef FEAT_EMACS_TAGS | |
3694 if (is_etag) | |
3695 c = 0; /* to shut up GCC */ | |
3696 else | |
3697 #endif | |
3698 { | |
3699 c = *fname_end; | |
3700 *fname_end = NUL; | |
3701 } | |
3702 fullname = expand_tag_fname(fname, tag_fname, TRUE); | |
3703 if (fullname != NULL) | |
3704 { | |
3705 retval = (fullpathcmp(fullname, buf_ffname, TRUE) & FPC_SAME); | |
3706 vim_free(fullname); | |
3707 } | |
3708 #ifdef FEAT_EMACS_TAGS | |
3709 if (!is_etag) | |
3710 #endif | |
3711 *fname_end = c; | |
3712 } | |
3713 | |
3714 return retval; | |
3715 } | |
3716 | |
3717 /* | |
3718 * Find the end of the tagaddress. | |
3719 * Return OK if ";\"" is following, FAIL otherwise. | |
3720 */ | |
3721 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3722 find_extra(char_u **pp) |
7 | 3723 { |
3724 char_u *str = *pp; | |
3725 | |
3726 /* Repeat for addresses separated with ';' */ | |
3727 for (;;) | |
3728 { | |
3729 if (VIM_ISDIGIT(*str)) | |
3730 str = skipdigits(str); | |
3731 else if (*str == '/' || *str == '?') | |
3732 { | |
3733 str = skip_regexp(str + 1, *str, FALSE, NULL); | |
3734 if (*str != **pp) | |
3735 str = NULL; | |
3736 else | |
3737 ++str; | |
3738 } | |
3739 else | |
3740 str = NULL; | |
3741 if (str == NULL || *str != ';' | |
3742 || !(VIM_ISDIGIT(str[1]) || str[1] == '/' || str[1] == '?')) | |
3743 break; | |
3744 ++str; /* skip ';' */ | |
3745 } | |
3746 | |
3747 if (str != NULL && STRNCMP(str, ";\"", 2) == 0) | |
3748 { | |
3749 *pp = str; | |
3750 return OK; | |
3751 } | |
3752 return FAIL; | |
3753 } | |
3754 | |
3755 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
3756 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3757 expand_tags( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3758 int tagnames, /* expand tag names */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3759 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3760 int *num_file, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3761 char_u ***file) |
7 | 3762 { |
3763 int i; | |
3764 int c; | |
3765 int tagnmflag; | |
3766 char_u tagnm[100]; | |
3767 tagptrs_T t_p; | |
3768 int ret; | |
3769 | |
3770 if (tagnames) | |
3771 tagnmflag = TAG_NAMES; | |
3772 else | |
3773 tagnmflag = 0; | |
3774 if (pat[0] == '/') | |
3775 ret = find_tags(pat + 1, num_file, file, | |
3776 TAG_REGEXP | tagnmflag | TAG_VERBOSE, | |
3777 TAG_MANY, curbuf->b_ffname); | |
3778 else | |
3779 ret = find_tags(pat, num_file, file, | |
3780 TAG_REGEXP | tagnmflag | TAG_VERBOSE | TAG_NOIC, | |
3781 TAG_MANY, curbuf->b_ffname); | |
3782 if (ret == OK && !tagnames) | |
3783 { | |
3784 /* Reorganize the tags for display and matching as strings of: | |
3785 * "<tagname>\0<kind>\0<filename>\0" | |
3786 */ | |
3787 for (i = 0; i < *num_file; i++) | |
3788 { | |
3789 parse_match((*file)[i], &t_p); | |
3790 c = (int)(t_p.tagname_end - t_p.tagname); | |
3791 mch_memmove(tagnm, t_p.tagname, (size_t)c); | |
3792 tagnm[c++] = 0; | |
3793 tagnm[c++] = (t_p.tagkind != NULL && *t_p.tagkind) | |
3794 ? *t_p.tagkind : 'f'; | |
3795 tagnm[c++] = 0; | |
3796 mch_memmove((*file)[i] + c, t_p.fname, t_p.fname_end - t_p.fname); | |
3797 (*file)[i][c + (t_p.fname_end - t_p.fname)] = 0; | |
3798 mch_memmove((*file)[i], tagnm, (size_t)c); | |
3799 } | |
3800 } | |
3801 return ret; | |
3802 } | |
3803 #endif | |
179 | 3804 |
3805 #if defined(FEAT_EVAL) || defined(PROTO) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
3806 static int add_tag_field(dict_T *dict, char *field_name, char_u *start, char_u *end); |
179 | 3807 |
3808 /* | |
2185 | 3809 * Add a tag field to the dictionary "dict". |
3810 * Return OK or FAIL. | |
179 | 3811 */ |
3812 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3813 add_tag_field( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3814 dict_T *dict, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3815 char *field_name, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3816 char_u *start, /* start of the value */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3817 char_u *end) /* after the value; can be NULL */ |
179 | 3818 { |
2770 | 3819 char_u *buf; |
188 | 3820 int len = 0; |
2770 | 3821 int retval; |
179 | 3822 |
2185 | 3823 /* check that the field name doesn't exist yet */ |
3824 if (dict_find(dict, (char_u *)field_name, -1) != NULL) | |
3825 { | |
3826 if (p_verbose > 0) | |
3827 { | |
3828 verbose_enter(); | |
3829 smsg((char_u *)_("Duplicate field name: %s"), field_name); | |
3830 verbose_leave(); | |
3831 } | |
3832 return FAIL; | |
3833 } | |
2770 | 3834 buf = alloc(MAXPATHL); |
3835 if (buf == NULL) | |
3836 return FAIL; | |
188 | 3837 if (start != NULL) |
3838 { | |
211 | 3839 if (end == NULL) |
3840 { | |
3841 end = start + STRLEN(start); | |
3842 while (end > start && (end[-1] == '\r' || end[-1] == '\n')) | |
3843 --end; | |
3844 } | |
835 | 3845 len = (int)(end - start); |
2770 | 3846 if (len > MAXPATHL - 1) |
3847 len = MAXPATHL - 1; | |
418 | 3848 vim_strncpy(buf, start, len); |
188 | 3849 } |
179 | 3850 buf[len] = NUL; |
2770 | 3851 retval = dict_add_nr_str(dict, field_name, 0L, buf); |
3852 vim_free(buf); | |
3853 return retval; | |
179 | 3854 } |
3855 | |
3856 /* | |
3857 * Add the tags matching the specified pattern to the list "list" | |
3858 * as a dictionary | |
3859 */ | |
3860 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3861 get_tags(list_T *list, char_u *pat) |
179 | 3862 { |
3863 int num_matches, i, ret; | |
3864 char_u **matches, *p; | |
970 | 3865 char_u *full_fname; |
179 | 3866 dict_T *dict; |
3867 tagptrs_T tp; | |
3868 long is_static; | |
3869 | |
3870 ret = find_tags(pat, &num_matches, &matches, | |
3871 TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL); | |
3872 if (ret == OK && num_matches > 0) | |
3873 { | |
3874 for (i = 0; i < num_matches; ++i) | |
3875 { | |
188 | 3876 parse_match(matches[i], &tp); |
3877 is_static = test_for_static(&tp); | |
3878 | |
3879 /* Skip pseudo-tag lines. */ | |
3880 if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0) | |
3881 continue; | |
3882 | |
179 | 3883 if ((dict = dict_alloc()) == NULL) |
3884 ret = FAIL; | |
3885 if (list_append_dict(list, dict) == FAIL) | |
3886 ret = FAIL; | |
3887 | |
970 | 3888 full_fname = tag_full_fname(&tp); |
179 | 3889 if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL |
970 | 3890 || add_tag_field(dict, "filename", full_fname, |
3891 NULL) == FAIL | |
179 | 3892 || add_tag_field(dict, "cmd", tp.command, |
3893 tp.command_end) == FAIL | |
3894 || add_tag_field(dict, "kind", tp.tagkind, | |
3895 tp.tagkind_end) == FAIL | |
3896 || dict_add_nr_str(dict, "static", is_static, NULL) == FAIL) | |
3897 ret = FAIL; | |
3898 | |
970 | 3899 vim_free(full_fname); |
3900 | |
179 | 3901 if (tp.command_end != NULL) |
3902 { | |
3903 for (p = tp.command_end + 3; | |
3904 *p != NUL && *p != '\n' && *p != '\r'; ++p) | |
3905 { | |
3906 if (p == tp.tagkind || (p + 5 == tp.tagkind | |
3907 && STRNCMP(p, "kind:", 5) == 0)) | |
3908 /* skip "kind:<kind>" and "<kind>" */ | |
3909 p = tp.tagkind_end - 1; | |
3910 else if (STRNCMP(p, "file:", 5) == 0) | |
3911 /* skip "file:" (static tag) */ | |
3912 p += 4; | |
188 | 3913 else if (!vim_iswhite(*p)) |
179 | 3914 { |
3915 char_u *s, *n; | |
188 | 3916 int len; |
179 | 3917 |
799 | 3918 /* Add extra field as a dict entry. Fields are |
3919 * separated by Tabs. */ | |
179 | 3920 n = p; |
799 | 3921 while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') |
179 | 3922 ++p; |
835 | 3923 len = (int)(p - n); |
188 | 3924 if (*p == ':' && len > 0) |
3925 { | |
3926 s = ++p; | |
836 | 3927 while (*p != NUL && *p >= ' ') |
188 | 3928 ++p; |
3929 n[len] = NUL; | |
3930 if (add_tag_field(dict, (char *)n, s, p) == FAIL) | |
3931 ret = FAIL; | |
3932 n[len] = ':'; | |
3933 } | |
836 | 3934 else |
3935 /* Skip field without colon. */ | |
3936 while (*p != NUL && *p >= ' ') | |
3937 ++p; | |
1674 | 3938 if (*p == NUL) |
3939 break; | |
179 | 3940 } |
3941 } | |
3942 } | |
3943 | |
3944 vim_free(matches[i]); | |
3945 } | |
3946 vim_free(matches); | |
3947 } | |
3948 return ret; | |
3949 } | |
3950 #endif |