Mercurial > vim
annotate src/tag.c @ 10128:98ddc760e8d5 v7.4.2335
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Sep 6 20:24:50 2016 +0200
patch 7.4.2335
Problem: taglist() is slow. (Luc Hermitte)
Solution: Check for CTRL-C less often when doing a linear search. (closes
https://github.com/vim/vim/issues/1044)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 06 Sep 2016 20:30:07 +0200 |
parents | 4aead6a9b7a9 |
children | 9a13895ee8d7 |
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 /* | |
38 * The matching tags are first stored in ga_match[]. In which one depends on | |
39 * the priority of the match. | |
40 * At the end, the matches from ga_match[] are concatenated, to make a list | |
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 | |
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 | |
1344 struct match_found | |
1345 { | |
1346 int len; /* nr of chars of match[] to be compared */ | |
1347 char_u match[1]; /* actually longer */ | |
1348 } *mfp, *mfp2; | |
1349 garray_T ga_match[MT_COUNT]; | |
1350 int match_count = 0; /* number of matches found */ | |
1351 char_u **matches; | |
1352 int mtt; | |
1353 int help_save; | |
1354 #ifdef FEAT_MULTI_LANG | |
1355 int help_pri = 0; | |
1356 char_u *help_lang_find = NULL; /* lang to be found */ | |
1357 char_u help_lang[3]; /* lang of current tags file */ | |
1358 char_u *saved_pat = NULL; /* copy of pat[] */ | |
1359 #endif | |
1360 | |
1361 pat_T orgpat; /* holds unconverted pattern info */ | |
1362 #ifdef FEAT_MBYTE | |
1363 vimconv_T vimconv; | |
1364 #endif | |
1365 | |
1366 #ifdef FEAT_TAG_BINS | |
1367 int findall = (mincount == MAXCOL || mincount == TAG_MANY); | |
1368 /* find all matching tags */ | |
1369 int sort_error = FALSE; /* tags file not sorted */ | |
1370 int linear; /* do a linear search */ | |
1371 int sortic = FALSE; /* tag file sorted in nocase */ | |
1372 #endif | |
1373 int line_error = FALSE; /* syntax error */ | |
1374 int has_re = (flags & TAG_REGEXP); /* regexp used */ | |
1375 int help_only = (flags & TAG_HELP); | |
1376 int name_only = (flags & TAG_NAMES); | |
1377 int noic = (flags & TAG_NOIC); | |
1378 int get_it_again = FALSE; | |
1379 #ifdef FEAT_CSCOPE | |
1380 int use_cscope = (flags & TAG_CSCOPE); | |
1381 #endif | |
1382 int verbose = (flags & TAG_VERBOSE); | |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1383 int save_p_ic = p_ic; |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1384 |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1385 /* |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1386 * 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
|
1387 * duration of this function. |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1388 */ |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
1389 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
|
1390 { |
9913
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9850
diff
changeset
|
1391 case TC_FOLLOWIC: break; |
bb00c661b3a4
commit https://github.com/vim/vim/commit/66e29d7112e437b2b50efe1f82c7e892736d23e4
Christian Brabandt <cb@256bit.org>
parents:
9850
diff
changeset
|
1392 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
|
1393 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
|
1394 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
|
1395 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
|
1396 } |
7 | 1397 |
1398 help_save = curbuf->b_help; | |
1399 orgpat.pat = pat; | |
1400 #ifdef FEAT_MBYTE | |
1401 vimconv.vc_type = CONV_NONE; | |
1402 #endif | |
1403 | |
1404 /* | |
1405 * Allocate memory for the buffers that are used | |
1406 */ | |
3131 | 1407 lbuf = alloc(lbuf_size); |
7 | 1408 tag_fname = alloc(MAXPATHL + 1); |
1409 #ifdef FEAT_EMACS_TAGS | |
1410 ebuf = alloc(LSIZE); | |
1411 #endif | |
1412 for (mtt = 0; mtt < MT_COUNT; ++mtt) | |
1413 ga_init2(&ga_match[mtt], (int)sizeof(struct match_found *), 100); | |
1414 | |
1415 /* check for out of memory situation */ | |
1416 if (lbuf == NULL || tag_fname == NULL | |
1417 #ifdef FEAT_EMACS_TAGS | |
1418 || ebuf == NULL | |
1419 #endif | |
1420 ) | |
1421 goto findtag_end; | |
1422 | |
1423 #ifdef FEAT_CSCOPE | |
1424 STRCPY(tag_fname, "from cscope"); /* for error messages */ | |
1425 #endif | |
1426 | |
1427 /* | |
1428 * Initialize a few variables | |
1429 */ | |
1430 if (help_only) /* want tags from help file */ | |
1431 curbuf->b_help = TRUE; /* will be restored later */ | |
1432 | |
3131 | 1433 orgpat.len = (int)STRLEN(pat); |
7 | 1434 #ifdef FEAT_MULTI_LANG |
1435 if (curbuf->b_help) | |
1436 { | |
1437 /* When "@ab" is specified use only the "ab" language, otherwise | |
1438 * search all languages. */ | |
3131 | 1439 if (orgpat.len > 3 && pat[orgpat.len - 3] == '@' |
1440 && ASCII_ISALPHA(pat[orgpat.len - 2]) | |
1441 && ASCII_ISALPHA(pat[orgpat.len - 1])) | |
7 | 1442 { |
3131 | 1443 saved_pat = vim_strnsave(pat, orgpat.len - 3); |
7 | 1444 if (saved_pat != NULL) |
1445 { | |
3131 | 1446 help_lang_find = &pat[orgpat.len - 2]; |
1447 orgpat.pat = saved_pat; | |
1448 orgpat.len -= 3; | |
7 | 1449 } |
1450 } | |
1451 } | |
1452 #endif | |
3131 | 1453 if (p_tl != 0 && orgpat.len > p_tl) /* adjust for 'taglength' */ |
1454 orgpat.len = p_tl; | |
1455 | |
5513 | 1456 save_emsg_off = emsg_off; |
1457 emsg_off = TRUE; /* don't want error for invalid RE here */ | |
3131 | 1458 prepare_pats(&orgpat, has_re); |
5513 | 1459 emsg_off = save_emsg_off; |
3784 | 1460 if (has_re && orgpat.regmatch.regprog == NULL) |
1461 goto findtag_end; | |
7 | 1462 |
1463 #ifdef FEAT_TAG_BINS | |
1464 /* This is only to avoid a compiler warning for using search_info | |
1465 * uninitialised. */ | |
1466 vim_memset(&search_info, 0, (size_t)1); | |
1467 #endif | |
1468 | |
413 | 1469 /* |
1470 * When finding a specified number of matches, first try with matching | |
1471 * case, so binary search can be used, and try ignore-case matches in a | |
1472 * second loop. | |
1473 * When finding all matches, 'tagbsearch' is off, or there is no fixed | |
1474 * string to look for, ignore case right away to avoid going though the | |
1475 * tags files twice. | |
1476 * When the tag file is case-fold sorted, it is either one or the other. | |
1477 * Only ignore case when TAG_NOIC not used or 'ignorecase' set. | |
1478 */ | |
7 | 1479 #ifdef FEAT_TAG_BINS |
3131 | 1480 orgpat.regmatch.rm_ic = ((p_ic || !noic) |
1481 && (findall || orgpat.headlen == 0 || !p_tbs)); | |
7 | 1482 for (round = 1; round <= 2; ++round) |
1483 { | |
3131 | 1484 linear = (orgpat.headlen == 0 || !p_tbs || round == 2); |
7 | 1485 #else |
3131 | 1486 orgpat.regmatch.rm_ic = (p_ic || !noic); |
7 | 1487 #endif |
1488 | |
1489 /* | |
1490 * Try tag file names from tags option one by one. | |
1491 */ | |
1492 for (first_file = TRUE; | |
1493 #ifdef FEAT_CSCOPE | |
1494 use_cscope || | |
1495 #endif | |
692 | 1496 get_tagfname(&tn, first_file, tag_fname) == OK; |
1497 first_file = FALSE) | |
7 | 1498 { |
1499 /* | |
1500 * A file that doesn't exist is silently ignored. Only when not a | |
1501 * single file is found, an error message is given (further on). | |
1502 */ | |
1503 #ifdef FEAT_CSCOPE | |
1504 if (use_cscope) | |
1505 fp = NULL; /* avoid GCC warning */ | |
1506 else | |
1507 #endif | |
1508 { | |
1509 #ifdef FEAT_MULTI_LANG | |
1510 if (curbuf->b_help) | |
1511 { | |
1512 /* Prefer help tags according to 'helplang'. Put the | |
1513 * two-letter language name in help_lang[]. */ | |
835 | 1514 i = (int)STRLEN(tag_fname); |
7 | 1515 if (i > 3 && tag_fname[i - 3] == '-') |
1516 STRCPY(help_lang, tag_fname + i - 2); | |
1517 else | |
1518 STRCPY(help_lang, "en"); | |
1519 | |
1520 /* When searching for a specific language skip tags files | |
1521 * for other languages. */ | |
1522 if (help_lang_find != NULL | |
1523 && STRICMP(help_lang, help_lang_find) != 0) | |
1524 continue; | |
1525 | |
1526 /* For CTRL-] in a help file prefer a match with the same | |
1527 * language. */ | |
1528 if ((flags & TAG_KEEP_LANG) | |
1529 && help_lang_find == NULL | |
1530 && curbuf->b_fname != NULL | |
835 | 1531 && (i = (int)STRLEN(curbuf->b_fname)) > 4 |
7 | 1532 && curbuf->b_fname[i - 1] == 'x' |
1533 && curbuf->b_fname[i - 4] == '.' | |
1534 && STRNICMP(curbuf->b_fname + i - 3, help_lang, 2) == 0) | |
1535 help_pri = 0; | |
1536 else | |
1537 { | |
1538 help_pri = 1; | |
1539 for (s = p_hlg; *s != NUL; ++s) | |
1540 { | |
1541 if (STRNICMP(s, help_lang, 2) == 0) | |
1542 break; | |
1543 ++help_pri; | |
1544 if ((s = vim_strchr(s, ',')) == NULL) | |
1545 break; | |
1546 } | |
1547 if (s == NULL || *s == NUL) | |
1548 { | |
1549 /* Language not in 'helplang': use last, prefer English, | |
1550 * unless found already. */ | |
1551 ++help_pri; | |
1552 if (STRICMP(help_lang, "en") != 0) | |
1553 ++help_pri; | |
1554 } | |
1555 } | |
1556 } | |
1557 #endif | |
1558 | |
1559 if ((fp = mch_fopen((char *)tag_fname, "r")) == NULL) | |
1560 continue; | |
1561 | |
1562 if (p_verbose >= 5) | |
292 | 1563 { |
1564 verbose_enter(); | |
273 | 1565 smsg((char_u *)_("Searching tags file %s"), tag_fname); |
292 | 1566 verbose_leave(); |
1567 } | |
7 | 1568 } |
1569 did_open = TRUE; /* remember that we found at least one file */ | |
1570 | |
1571 state = TS_START; /* we're at the start of the file */ | |
1572 #ifdef FEAT_EMACS_TAGS | |
1573 is_etag = 0; /* default is: not emacs style */ | |
1574 #endif | |
1575 | |
1576 /* | |
1577 * Read and parse the lines in the file one by one | |
1578 */ | |
1579 for (;;) | |
1580 { | |
10128
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1581 /* 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
|
1582 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
|
1583 line_breakcheck(); |
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1584 else |
98ddc760e8d5
commit https://github.com/vim/vim/commit/72b4b870fcc445c14faf282e0595b5f9406b101d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1585 fast_breakcheck(); |
7 | 1586 #ifdef FEAT_INS_EXPAND |
1587 if ((flags & TAG_INS_COMP)) /* Double brackets for gcc */ | |
464 | 1588 ins_compl_check_keys(30); |
449 | 1589 if (got_int || compl_interrupted) |
7 | 1590 #else |
1591 if (got_int) | |
1592 #endif | |
1593 { | |
1594 stop_searching = TRUE; | |
1595 break; | |
1596 } | |
1597 /* When mincount is TAG_MANY, stop when enough matches have been | |
1598 * found (for completion). */ | |
1599 if (mincount == TAG_MANY && match_count >= TAG_MANY) | |
1600 { | |
1601 stop_searching = TRUE; | |
1602 retval = OK; | |
1603 break; | |
1604 } | |
1605 if (get_it_again) | |
1606 goto line_read_in; | |
1607 #ifdef FEAT_TAG_BINS | |
1608 /* | |
1609 * For binary search: compute the next offset to use. | |
1610 */ | |
1611 if (state == TS_BINARY) | |
1612 { | |
1613 offset = search_info.low_offset + ((search_info.high_offset | |
1614 - search_info.low_offset) / 2); | |
1615 if (offset == search_info.curr_offset) | |
1616 break; /* End the binary search without a match. */ | |
1617 else | |
1618 search_info.curr_offset = offset; | |
1619 } | |
1620 | |
1621 /* | |
1622 * Skipping back (after a match during binary search). | |
1623 */ | |
1624 else if (state == TS_SKIP_BACK) | |
1625 { | |
1626 search_info.curr_offset -= LSIZE * 2; | |
1627 if (search_info.curr_offset < 0) | |
1628 { | |
1629 search_info.curr_offset = 0; | |
1630 rewind(fp); | |
1631 state = TS_STEP_FORWARD; | |
1632 } | |
1633 } | |
1634 | |
1635 /* | |
1636 * When jumping around in the file, first read a line to find the | |
1637 * start of the next line. | |
1638 */ | |
1639 if (state == TS_BINARY || state == TS_SKIP_BACK) | |
1640 { | |
1641 /* Adjust the search file offset to the correct position */ | |
1642 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
|
1643 vim_fseek(fp, search_info.curr_offset, SEEK_SET); |
7 | 1644 eof = tag_fgets(lbuf, LSIZE, fp); |
1645 if (!eof && search_info.curr_offset != 0) | |
1646 { | |
1146 | 1647 /* The explicit cast is to work around a bug in gcc 3.4.2 |
1648 * (repeated below). */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1649 search_info.curr_offset = vim_ftell(fp); |
7 | 1650 if (search_info.curr_offset == search_info.high_offset) |
1651 { | |
1652 /* 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
|
1653 vim_fseek(fp, search_info.low_offset, SEEK_SET); |
7 | 1654 search_info.curr_offset = search_info.low_offset; |
1655 } | |
1656 eof = tag_fgets(lbuf, LSIZE, fp); | |
1657 } | |
1658 /* skip empty and blank lines */ | |
1659 while (!eof && vim_isblankline(lbuf)) | |
1660 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1661 search_info.curr_offset = vim_ftell(fp); |
7 | 1662 eof = tag_fgets(lbuf, LSIZE, fp); |
1663 } | |
1664 if (eof) | |
1665 { | |
1666 /* Hit end of file. Skip backwards. */ | |
1667 state = TS_SKIP_BACK; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1668 search_info.match_offset = vim_ftell(fp); |
7 | 1669 search_info.curr_offset = search_info.curr_offset_used; |
1670 continue; | |
1671 } | |
1672 } | |
1673 | |
1674 /* | |
1675 * Not jumping around in the file: Read the next line. | |
1676 */ | |
1677 else | |
1678 #endif | |
1679 { | |
1680 /* skip empty and blank lines */ | |
1681 do | |
1682 { | |
1683 #ifdef FEAT_CSCOPE | |
1684 if (use_cscope) | |
1685 eof = cs_fgets(lbuf, LSIZE); | |
1686 else | |
1687 #endif | |
1688 eof = tag_fgets(lbuf, LSIZE, fp); | |
1689 } while (!eof && vim_isblankline(lbuf)); | |
1690 | |
1691 if (eof) | |
1692 { | |
1693 #ifdef FEAT_EMACS_TAGS | |
1694 if (incstack_idx) /* this was an included file */ | |
1695 { | |
1696 --incstack_idx; | |
1697 fclose(fp); /* end of this file ... */ | |
1698 fp = incstack[incstack_idx].fp; | |
1699 STRCPY(tag_fname, incstack[incstack_idx].etag_fname); | |
1700 vim_free(incstack[incstack_idx].etag_fname); | |
1701 is_etag = 1; /* (only etags can include) */ | |
1702 continue; /* ... continue with parent file */ | |
1703 } | |
1704 else | |
1705 #endif | |
1706 break; /* end of file */ | |
1707 } | |
1708 } | |
1709 line_read_in: | |
1710 | |
3131 | 1711 #ifdef FEAT_MBYTE |
1712 if (vimconv.vc_type != CONV_NONE) | |
1713 { | |
1714 char_u *conv_line; | |
1715 int len; | |
1716 | |
1717 /* Convert every line. Converting the pattern from 'enc' to | |
1718 * the tags file encoding doesn't work, because characters are | |
1719 * not recognized. */ | |
1720 conv_line = string_convert(&vimconv, lbuf, NULL); | |
1721 if (conv_line != NULL) | |
1722 { | |
1723 /* Copy or swap lbuf and conv_line. */ | |
1724 len = (int)STRLEN(conv_line) + 1; | |
1725 if (len > lbuf_size) | |
1726 { | |
1727 vim_free(lbuf); | |
1728 lbuf = conv_line; | |
1729 lbuf_size = len; | |
1730 } | |
1731 else | |
1732 { | |
1733 STRCPY(lbuf, conv_line); | |
1734 vim_free(conv_line); | |
1735 } | |
1736 } | |
1737 } | |
1738 #endif | |
1739 | |
1740 | |
7 | 1741 #ifdef FEAT_EMACS_TAGS |
1742 /* | |
1743 * Emacs tags line with CTRL-L: New file name on next line. | |
1744 * The file name is followed by a ','. | |
1745 */ | |
1746 if (*lbuf == Ctrl_L) /* remember etag file name in ebuf */ | |
1747 { | |
1748 is_etag = 1; /* in case at the start */ | |
1749 state = TS_LINEAR; | |
1750 if (!tag_fgets(ebuf, LSIZE, fp)) | |
1751 { | |
1752 for (p = ebuf; *p && *p != ','; p++) | |
1753 ; | |
1754 *p = NUL; | |
1755 | |
1756 /* | |
1757 * atoi(p+1) is the number of bytes before the next ^L | |
1758 * unless it is an include statement. | |
1759 */ | |
1760 if (STRNCMP(p + 1, "include", 7) == 0 | |
1761 && incstack_idx < INCSTACK_SIZE) | |
1762 { | |
1763 /* Save current "fp" and "tag_fname" in the stack. */ | |
1764 if ((incstack[incstack_idx].etag_fname = | |
1765 vim_strsave(tag_fname)) != NULL) | |
1766 { | |
1767 char_u *fullpath_ebuf; | |
1768 | |
1769 incstack[incstack_idx].fp = fp; | |
1770 fp = NULL; | |
1771 | |
1772 /* Figure out "tag_fname" and "fp" to use for | |
1773 * included file. */ | |
1774 fullpath_ebuf = expand_tag_fname(ebuf, | |
1775 tag_fname, FALSE); | |
1776 if (fullpath_ebuf != NULL) | |
1777 { | |
1778 fp = mch_fopen((char *)fullpath_ebuf, "r"); | |
1779 if (fp != NULL) | |
1780 { | |
1781 if (STRLEN(fullpath_ebuf) > LSIZE) | |
1782 EMSG2(_("E430: Tag file path truncated for %s\n"), ebuf); | |
418 | 1783 vim_strncpy(tag_fname, fullpath_ebuf, |
1784 MAXPATHL); | |
7 | 1785 ++incstack_idx; |
1786 is_etag = 0; /* we can include anything */ | |
1787 } | |
1788 vim_free(fullpath_ebuf); | |
1789 } | |
1790 if (fp == NULL) | |
1791 { | |
1792 /* Can't open the included file, skip it and | |
1793 * restore old value of "fp". */ | |
1794 fp = incstack[incstack_idx].fp; | |
1795 vim_free(incstack[incstack_idx].etag_fname); | |
1796 } | |
1797 } | |
1798 } | |
1799 } | |
1800 continue; | |
1801 } | |
1802 #endif | |
1803 | |
1804 /* | |
1805 * When still at the start of the file, check for Emacs tags file | |
1806 * format, and for "not sorted" flag. | |
1807 */ | |
1808 if (state == TS_START) | |
1809 { | |
5328 | 1810 /* The header ends when the line sorts below "!_TAG_". When |
1811 * 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
|
1812 if (STRNCMP(lbuf, "!_TAG_", 6) <= 0 |
1707ddb6f5ae
updated for version 7.3.1202
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1813 || (lbuf[0] == '!' && ASCII_ISLOWER(lbuf[1]))) |
3131 | 1814 { |
5328 | 1815 if (STRNCMP(lbuf, "!_TAG_", 6) != 0) |
1816 /* Non-header item before the header, e.g. "!" itself. | |
1817 */ | |
1818 goto parse_line; | |
1819 | |
3131 | 1820 /* |
1821 * Read header line. | |
1822 */ | |
1823 #ifdef FEAT_TAG_BINS | |
1824 if (STRNCMP(lbuf, "!_TAG_FILE_SORTED\t", 18) == 0) | |
1825 tag_file_sorted = lbuf[18]; | |
1826 #endif | |
1827 #ifdef FEAT_MBYTE | |
1828 if (STRNCMP(lbuf, "!_TAG_FILE_ENCODING\t", 20) == 0) | |
1829 { | |
1830 /* Prepare to convert every line from the specified | |
1831 * encoding to 'encoding'. */ | |
1832 for (p = lbuf + 20; *p > ' ' && *p < 127; ++p) | |
1833 ; | |
1834 *p = NUL; | |
1835 convert_setup(&vimconv, lbuf + 20, p_enc); | |
1836 } | |
1837 #endif | |
1838 | |
1839 /* Read the next line. Unrecognized flags are ignored. */ | |
1840 continue; | |
1841 } | |
1842 | |
1843 /* Headers ends. */ | |
1844 | |
7 | 1845 #ifdef FEAT_TAG_BINS |
1846 /* | |
1847 * When there is no tag head, or ignoring case, need to do a | |
1848 * linear search. | |
1849 * When no "!_TAG_" is found, default to binary search. If | |
1850 * the tag file isn't sorted, the second loop will find it. | |
1851 * When "!_TAG_FILE_SORTED" found: start binary search if | |
1852 * flag set. | |
1853 * For cscope, it's always linear. | |
1854 */ | |
1855 # ifdef FEAT_CSCOPE | |
1856 if (linear || use_cscope) | |
1857 # else | |
1858 if (linear) | |
1859 # endif | |
1860 state = TS_LINEAR; | |
3131 | 1861 else if (tag_file_sorted == NUL) |
7 | 1862 state = TS_BINARY; |
3131 | 1863 else if (tag_file_sorted == '1') |
7 | 1864 state = TS_BINARY; |
3131 | 1865 else if (tag_file_sorted == '2') |
1866 { | |
1867 state = TS_BINARY; | |
1868 sortic = TRUE; | |
1869 orgpat.regmatch.rm_ic = (p_ic || !noic); | |
7 | 1870 } |
3131 | 1871 else |
1872 state = TS_LINEAR; | |
1873 | |
1874 if (state == TS_BINARY && orgpat.regmatch.rm_ic && !sortic) | |
7 | 1875 { |
3206 | 1876 /* Binary search won't work for ignoring case, use linear |
7 | 1877 * search. */ |
1878 linear = TRUE; | |
1879 state = TS_LINEAR; | |
1880 } | |
1881 #else | |
1882 state = TS_LINEAR; | |
1883 #endif | |
1884 | |
1885 #ifdef FEAT_TAG_BINS | |
1886 /* | |
1887 * When starting a binary search, get the size of the file and | |
1888 * compute the first offset. | |
1889 */ | |
1890 if (state == TS_BINARY) | |
1891 { | |
1892 /* Get the tag file size (don't use mch_fstat(), it's not | |
1893 * portable). */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1894 if ((filesize = vim_lseek(fileno(fp), |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1895 (off_T)0L, SEEK_END)) <= 0) |
7 | 1896 state = TS_LINEAR; |
1897 else | |
1898 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1899 vim_lseek(fileno(fp), (off_T)0L, SEEK_SET); |
7 | 1900 |
1901 /* Calculate the first read offset in the file. Start | |
1902 * the search in the middle of the file. */ | |
1903 search_info.low_offset = 0; | |
1904 search_info.low_char = 0; | |
1905 search_info.high_offset = filesize; | |
1906 search_info.curr_offset = 0; | |
1907 search_info.high_char = 0xff; | |
1908 } | |
1909 continue; | |
1910 } | |
1911 #endif | |
1912 } | |
1913 | |
5328 | 1914 parse_line: |
7 | 1915 /* |
1916 * Figure out where the different strings are in this line. | |
1917 * For "normal" tags: Do a quick check if the tag matches. | |
1918 * This speeds up tag searching a lot! | |
1919 */ | |
3131 | 1920 if (orgpat.headlen |
7 | 1921 #ifdef FEAT_EMACS_TAGS |
1922 && !is_etag | |
1923 #endif | |
1924 ) | |
1925 { | |
1926 tagp.tagname = lbuf; | |
1927 #ifdef FEAT_TAG_ANYWHITE | |
1928 tagp.tagname_end = skiptowhite(lbuf); | |
3192 | 1929 if (*tagp.tagname_end == NUL) |
7 | 1930 #else |
1931 tagp.tagname_end = vim_strchr(lbuf, TAB); | |
3192 | 1932 if (tagp.tagname_end == NULL) |
7 | 1933 #endif |
1934 { | |
3192 | 1935 if (vim_strchr(lbuf, NL) == NULL) |
1936 { | |
1937 /* Truncated line, ignore it. Has been reported for | |
1938 * Mozilla JS with extremely long names. */ | |
1939 if (p_verbose >= 5) | |
1940 { | |
1941 verbose_enter(); | |
1942 MSG(_("Ignoring long line in tags file")); | |
1943 verbose_leave(); | |
1944 } | |
3206 | 1945 #ifdef FEAT_TAG_BINS |
1946 if (state != TS_LINEAR) | |
1947 { | |
1948 /* Avoid getting stuck. */ | |
1949 linear = TRUE; | |
1950 state = TS_LINEAR; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
1951 vim_fseek(fp, search_info.low_offset, SEEK_SET); |
3206 | 1952 } |
1953 #endif | |
3192 | 1954 continue; |
1955 } | |
1956 | |
1957 /* Corrupted tag line. */ | |
7 | 1958 line_error = TRUE; |
1959 break; | |
1960 } | |
1961 | |
1962 #ifdef FEAT_TAG_OLDSTATIC | |
1963 /* | |
1964 * Check for old style static tag: "file:tag file .." | |
1965 */ | |
1966 tagp.fname = NULL; | |
1967 for (p = lbuf; p < tagp.tagname_end; ++p) | |
1968 { | |
1969 if (*p == ':') | |
1970 { | |
1971 if (tagp.fname == NULL) | |
1972 #ifdef FEAT_TAG_ANYWHITE | |
1973 tagp.fname = skipwhite(tagp.tagname_end); | |
1974 #else | |
1975 tagp.fname = tagp.tagname_end + 1; | |
1976 #endif | |
1977 if ( fnamencmp(lbuf, tagp.fname, p - lbuf) == 0 | |
1978 #ifdef FEAT_TAG_ANYWHITE | |
1979 && vim_iswhite(tagp.fname[p - lbuf]) | |
1980 #else | |
1981 && tagp.fname[p - lbuf] == TAB | |
1982 #endif | |
1983 ) | |
1984 { | |
1985 /* found one */ | |
1986 tagp.tagname = p + 1; | |
1987 break; | |
1988 } | |
1989 } | |
1990 } | |
1991 #endif | |
1992 | |
1993 /* | |
1994 * Skip this line if the length of the tag is different and | |
1995 * there is no regexp, or the tag is too short. | |
1996 */ | |
1997 cmplen = (int)(tagp.tagname_end - tagp.tagname); | |
1998 if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */ | |
1999 cmplen = p_tl; | |
3131 | 2000 if (has_re && orgpat.headlen < cmplen) |
2001 cmplen = orgpat.headlen; | |
2002 else if (state == TS_LINEAR && orgpat.headlen != cmplen) | |
7 | 2003 continue; |
2004 | |
2005 #ifdef FEAT_TAG_BINS | |
2006 if (state == TS_BINARY) | |
2007 { | |
2008 /* | |
2009 * Simplistic check for unsorted tags file. | |
2010 */ | |
2011 i = (int)tagp.tagname[0]; | |
2012 if (sortic) | |
2013 i = (int)TOUPPER_ASC(tagp.tagname[0]); | |
2014 if (i < search_info.low_char || i > search_info.high_char) | |
2015 sort_error = TRUE; | |
2016 | |
2017 /* | |
2018 * Compare the current tag with the searched tag. | |
2019 */ | |
2020 if (sortic) | |
3131 | 2021 tagcmp = tag_strnicmp(tagp.tagname, orgpat.head, |
7 | 2022 (size_t)cmplen); |
2023 else | |
3131 | 2024 tagcmp = STRNCMP(tagp.tagname, orgpat.head, cmplen); |
7 | 2025 |
2026 /* | |
2027 * A match with a shorter tag means to search forward. | |
2028 * A match with a longer tag means to search backward. | |
2029 */ | |
2030 if (tagcmp == 0) | |
2031 { | |
3131 | 2032 if (cmplen < orgpat.headlen) |
7 | 2033 tagcmp = -1; |
3131 | 2034 else if (cmplen > orgpat.headlen) |
7 | 2035 tagcmp = 1; |
2036 } | |
2037 | |
2038 if (tagcmp == 0) | |
2039 { | |
2040 /* We've located the tag, now skip back and search | |
2041 * forward until the first matching tag is found. | |
2042 */ | |
2043 state = TS_SKIP_BACK; | |
2044 search_info.match_offset = search_info.curr_offset; | |
2045 continue; | |
2046 } | |
2047 if (tagcmp < 0) | |
2048 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
2049 search_info.curr_offset = vim_ftell(fp); |
7 | 2050 if (search_info.curr_offset < search_info.high_offset) |
2051 { | |
2052 search_info.low_offset = search_info.curr_offset; | |
2053 if (sortic) | |
2054 search_info.low_char = | |
2055 TOUPPER_ASC(tagp.tagname[0]); | |
2056 else | |
2057 search_info.low_char = tagp.tagname[0]; | |
2058 continue; | |
2059 } | |
2060 } | |
2061 if (tagcmp > 0 | |
2062 && search_info.curr_offset != search_info.high_offset) | |
2063 { | |
2064 search_info.high_offset = search_info.curr_offset; | |
2065 if (sortic) | |
2066 search_info.high_char = | |
2067 TOUPPER_ASC(tagp.tagname[0]); | |
2068 else | |
2069 search_info.high_char = tagp.tagname[0]; | |
2070 continue; | |
2071 } | |
2072 | |
2073 /* No match yet and are at the end of the binary search. */ | |
2074 break; | |
2075 } | |
2076 else if (state == TS_SKIP_BACK) | |
2077 { | |
3131 | 2078 if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) |
7 | 2079 state = TS_STEP_FORWARD; |
2080 else | |
2081 /* Have to skip back more. Restore the curr_offset | |
2082 * used, otherwise we get stuck at a long line. */ | |
2083 search_info.curr_offset = search_info.curr_offset_used; | |
2084 continue; | |
2085 } | |
2086 else if (state == TS_STEP_FORWARD) | |
2087 { | |
3131 | 2088 if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) |
7 | 2089 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
2090 if ((off_T)vim_ftell(fp) > search_info.match_offset) |
7 | 2091 break; /* past last match */ |
2092 else | |
2093 continue; /* before first match */ | |
2094 } | |
2095 } | |
2096 else | |
2097 #endif | |
2098 /* skip this match if it can't match */ | |
3131 | 2099 if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0) |
7 | 2100 continue; |
2101 | |
2102 /* | |
2103 * Can be a matching tag, isolate the file name and command. | |
2104 */ | |
2105 #ifdef FEAT_TAG_OLDSTATIC | |
2106 if (tagp.fname == NULL) | |
2107 #endif | |
2108 #ifdef FEAT_TAG_ANYWHITE | |
2109 tagp.fname = skipwhite(tagp.tagname_end); | |
2110 #else | |
2111 tagp.fname = tagp.tagname_end + 1; | |
2112 #endif | |
2113 #ifdef FEAT_TAG_ANYWHITE | |
2114 tagp.fname_end = skiptowhite(tagp.fname); | |
2115 tagp.command = skipwhite(tagp.fname_end); | |
2116 if (*tagp.command == NUL) | |
2117 #else | |
2118 tagp.fname_end = vim_strchr(tagp.fname, TAB); | |
2119 tagp.command = tagp.fname_end + 1; | |
2120 if (tagp.fname_end == NULL) | |
2121 #endif | |
2122 i = FAIL; | |
2123 else | |
2124 i = OK; | |
2125 } | |
2126 else | |
2127 i = parse_tag_line(lbuf, | |
2128 #ifdef FEAT_EMACS_TAGS | |
2129 is_etag, | |
2130 #endif | |
2131 &tagp); | |
2132 if (i == FAIL) | |
2133 { | |
2134 line_error = TRUE; | |
2135 break; | |
2136 } | |
2137 | |
2138 #ifdef FEAT_EMACS_TAGS | |
2139 if (is_etag) | |
2140 tagp.fname = ebuf; | |
2141 #endif | |
2142 /* | |
2143 * First try matching with the pattern literally (also when it is | |
2144 * a regexp). | |
2145 */ | |
2146 cmplen = (int)(tagp.tagname_end - tagp.tagname); | |
2147 if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */ | |
2148 cmplen = p_tl; | |
2149 /* if tag length does not match, don't try comparing */ | |
3131 | 2150 if (orgpat.len != cmplen) |
7 | 2151 match = FALSE; |
2152 else | |
2153 { | |
3131 | 2154 if (orgpat.regmatch.rm_ic) |
7 | 2155 { |
3131 | 2156 match = (MB_STRNICMP(tagp.tagname, orgpat.pat, cmplen) == 0); |
7 | 2157 if (match) |
3131 | 2158 match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat, |
7 | 2159 cmplen) == 0); |
2160 } | |
2161 else | |
3131 | 2162 match = (STRNCMP(tagp.tagname, orgpat.pat, cmplen) == 0); |
7 | 2163 } |
2164 | |
2165 /* | |
2166 * Has a regexp: Also find tags matching regexp. | |
2167 */ | |
2168 match_re = FALSE; | |
3131 | 2169 if (!match && orgpat.regmatch.regprog != NULL) |
7 | 2170 { |
2171 int cc; | |
2172 | |
2173 cc = *tagp.tagname_end; | |
2174 *tagp.tagname_end = NUL; | |
3131 | 2175 match = vim_regexec(&orgpat.regmatch, tagp.tagname, (colnr_T)0); |
7 | 2176 if (match) |
2177 { | |
3131 | 2178 matchoff = (int)(orgpat.regmatch.startp[0] - tagp.tagname); |
2179 if (orgpat.regmatch.rm_ic) | |
7 | 2180 { |
3131 | 2181 orgpat.regmatch.rm_ic = FALSE; |
2182 match_no_ic = vim_regexec(&orgpat.regmatch, tagp.tagname, | |
7 | 2183 (colnr_T)0); |
3131 | 2184 orgpat.regmatch.rm_ic = TRUE; |
7 | 2185 } |
2186 } | |
2187 *tagp.tagname_end = cc; | |
2188 match_re = TRUE; | |
2189 } | |
2190 | |
2191 /* | |
2192 * If a match is found, add it to ga_match[]. | |
2193 */ | |
2194 if (match) | |
2195 { | |
2196 #ifdef FEAT_CSCOPE | |
2197 if (use_cscope) | |
2198 { | |
2199 /* Don't change the ordering, always use the same table. */ | |
2200 mtt = MT_GL_OTH; | |
2201 } | |
2202 else | |
2203 #endif | |
2204 { | |
2205 /* Decide in which array to store this match. */ | |
2206 is_current = test_for_current( | |
2207 #ifdef FEAT_EMACS_TAGS | |
2208 is_etag, | |
2209 #endif | |
2210 tagp.fname, tagp.fname_end, tag_fname, | |
2211 buf_ffname); | |
2212 #ifdef FEAT_EMACS_TAGS | |
2213 is_static = FALSE; | |
2214 if (!is_etag) /* emacs tags are never static */ | |
2215 #endif | |
2216 { | |
2217 #ifdef FEAT_TAG_OLDSTATIC | |
2218 if (tagp.tagname != lbuf) | |
2219 is_static = TRUE; /* detected static tag before */ | |
2220 else | |
2221 #endif | |
2222 is_static = test_for_static(&tagp); | |
2223 } | |
2224 | |
2225 /* decide in which of the sixteen tables to store this | |
2226 * match */ | |
2227 if (is_static) | |
2228 { | |
2229 if (is_current) | |
2230 mtt = MT_ST_CUR; | |
2231 else | |
2232 mtt = MT_ST_OTH; | |
2233 } | |
2234 else | |
2235 { | |
2236 if (is_current) | |
2237 mtt = MT_GL_CUR; | |
2238 else | |
2239 mtt = MT_GL_OTH; | |
2240 } | |
3131 | 2241 if (orgpat.regmatch.rm_ic && !match_no_ic) |
7 | 2242 mtt += MT_IC_OFF; |
2243 if (match_re) | |
2244 mtt += MT_RE_OFF; | |
2245 } | |
2246 | |
2247 /* | |
2248 * Add the found match in ga_match[mtt], avoiding duplicates. | |
2249 * Store the info we need later, which depends on the kind of | |
2250 * tags we are dealing with. | |
2251 */ | |
2252 if (ga_grow(&ga_match[mtt], 1) == OK) | |
2253 { | |
3263 | 2254 int len; |
9068
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2255 int heuristic; |
3263 | 2256 |
7 | 2257 if (help_only) |
2258 { | |
2259 #ifdef FEAT_MULTI_LANG | |
2260 # define ML_EXTRA 3 | |
2261 #else | |
2262 # define ML_EXTRA 0 | |
2263 #endif | |
2264 /* | |
2265 * Append the help-heuristic number after the | |
2266 * tagname, for sorting it later. | |
2267 */ | |
2268 *tagp.tagname_end = NUL; | |
2269 len = (int)(tagp.tagname_end - tagp.tagname); | |
2270 mfp = (struct match_found *) | |
2271 alloc((int)sizeof(struct match_found) + len | |
2272 + 10 + ML_EXTRA); | |
2273 if (mfp != NULL) | |
2274 { | |
2275 /* "len" includes the language and the NUL, but | |
2276 * not the priority. */ | |
2277 mfp->len = len + ML_EXTRA + 1; | |
2278 #define ML_HELP_LEN 6 | |
2279 p = mfp->match; | |
2280 STRCPY(p, tagp.tagname); | |
2281 #ifdef FEAT_MULTI_LANG | |
2282 p[len] = '@'; | |
2283 STRCPY(p + len + 1, help_lang); | |
2284 #endif | |
9068
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2285 |
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2286 heuristic = help_heuristic(tagp.tagname, |
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2287 match_re ? matchoff : 0, !match_no_ic); |
7 | 2288 #ifdef FEAT_MULTI_LANG |
9068
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2289 heuristic += help_pri; |
7 | 2290 #endif |
9068
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2291 sprintf((char *)p + len + 1 + ML_EXTRA, "%06d", |
0a3bc9fdea20
commit https://github.com/vim/vim/commit/827b165b2aebad2cfe98cc6d5804c6c0fe8afd89
Christian Brabandt <cb@256bit.org>
parents:
8930
diff
changeset
|
2292 heuristic); |
7 | 2293 } |
2294 *tagp.tagname_end = TAB; | |
2295 } | |
2296 else if (name_only) | |
2297 { | |
2298 if (get_it_again) | |
2299 { | |
2300 char_u *temp_end = tagp.command; | |
2301 | |
2302 if (*temp_end == '/') | |
2303 while (*temp_end && *temp_end != '\r' | |
2304 && *temp_end != '\n' | |
2305 && *temp_end != '$') | |
2306 temp_end++; | |
2307 | |
2308 if (tagp.command + 2 < temp_end) | |
2309 { | |
2310 len = (int)(temp_end - tagp.command - 2); | |
2311 mfp = (struct match_found *)alloc( | |
2312 (int)sizeof(struct match_found) + len); | |
2313 if (mfp != NULL) | |
2314 { | |
2315 mfp->len = len + 1; /* include the NUL */ | |
2316 p = mfp->match; | |
418 | 2317 vim_strncpy(p, tagp.command + 2, len); |
7 | 2318 } |
2319 } | |
2320 else | |
2321 mfp = NULL; | |
2322 get_it_again = FALSE; | |
2323 } | |
2324 else | |
2325 { | |
2326 len = (int)(tagp.tagname_end - tagp.tagname); | |
2327 mfp = (struct match_found *)alloc( | |
2328 (int)sizeof(struct match_found) + len); | |
2329 if (mfp != NULL) | |
2330 { | |
2331 mfp->len = len + 1; /* include the NUL */ | |
2332 p = mfp->match; | |
418 | 2333 vim_strncpy(p, tagp.tagname, len); |
7 | 2334 } |
2335 | |
2336 /* if wanted, re-read line to get long form too */ | |
2337 if (State & INSERT) | |
2338 get_it_again = p_sft; | |
2339 } | |
2340 } | |
2341 else | |
2342 { | |
2343 /* Save the tag in a buffer. | |
2344 * Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf> | |
2345 * other tag: <mtt><tag_fname><NUL><NUL><lbuf> | |
2346 * without Emacs tags: <mtt><tag_fname><NUL><lbuf> | |
2347 */ | |
359 | 2348 len = (int)STRLEN(tag_fname) |
3131 | 2349 + (int)STRLEN(lbuf) + 3; |
7 | 2350 #ifdef FEAT_EMACS_TAGS |
2351 if (is_etag) | |
2352 len += (int)STRLEN(ebuf) + 1; | |
2353 else | |
2354 ++len; | |
2355 #endif | |
2356 mfp = (struct match_found *)alloc( | |
2357 (int)sizeof(struct match_found) + len); | |
2358 if (mfp != NULL) | |
2359 { | |
2360 mfp->len = len; | |
2361 p = mfp->match; | |
2362 p[0] = mtt; | |
2363 STRCPY(p + 1, tag_fname); | |
2364 #ifdef BACKSLASH_IN_FILENAME | |
2365 /* Ignore differences in slashes, avoid adding | |
2366 * both path/file and path\file. */ | |
2367 slash_adjust(p + 1); | |
2368 #endif | |
2369 s = p + 1 + STRLEN(tag_fname) + 1; | |
2370 #ifdef FEAT_EMACS_TAGS | |
2371 if (is_etag) | |
2372 { | |
2373 STRCPY(s, ebuf); | |
2374 s += STRLEN(ebuf) + 1; | |
2375 } | |
2376 else | |
2377 *s++ = NUL; | |
2378 #endif | |
3131 | 2379 STRCPY(s, lbuf); |
7 | 2380 } |
2381 } | |
2382 | |
2383 if (mfp != NULL) | |
2384 { | |
2385 /* | |
2386 * Don't add identical matches. | |
2387 * This can take a lot of time when finding many | |
2388 * matches, check for CTRL-C now and then. | |
2389 * Add all cscope tags, because they are all listed. | |
2390 */ | |
2391 #ifdef FEAT_CSCOPE | |
2392 if (use_cscope) | |
2393 i = -1; | |
2394 else | |
2395 #endif | |
2396 for (i = ga_match[mtt].ga_len; --i >= 0 && !got_int; ) | |
2397 { | |
2398 mfp2 = ((struct match_found **) | |
2399 (ga_match[mtt].ga_data))[i]; | |
2400 if (mfp2->len == mfp->len | |
2401 && vim_memcmp(mfp2->match, mfp->match, | |
2402 (size_t)mfp->len) == 0) | |
2403 break; | |
2404 line_breakcheck(); | |
2405 } | |
2406 if (i < 0) | |
2407 { | |
2408 ((struct match_found **)(ga_match[mtt].ga_data)) | |
2409 [ga_match[mtt].ga_len++] = mfp; | |
2410 ++match_count; | |
2411 } | |
2412 else | |
2413 vim_free(mfp); | |
2414 } | |
2415 } | |
2416 else /* Out of memory! Just forget about the rest. */ | |
2417 { | |
2418 retval = OK; | |
2419 stop_searching = TRUE; | |
2420 break; | |
2421 } | |
2422 } | |
2423 #ifdef FEAT_CSCOPE | |
2424 if (use_cscope && eof) | |
2425 break; | |
2426 #endif | |
2427 } /* forever */ | |
2428 | |
2429 if (line_error) | |
2430 { | |
2431 EMSG2(_("E431: Format error in tags file \"%s\""), tag_fname); | |
2432 #ifdef FEAT_CSCOPE | |
2433 if (!use_cscope) | |
2434 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
2435 EMSGN(_("Before byte %ld"), (long)vim_ftell(fp)); |
7 | 2436 stop_searching = TRUE; |
2437 line_error = FALSE; | |
2438 } | |
2439 | |
2440 #ifdef FEAT_CSCOPE | |
2441 if (!use_cscope) | |
2442 #endif | |
2443 fclose(fp); | |
2444 #ifdef FEAT_EMACS_TAGS | |
2445 while (incstack_idx) | |
2446 { | |
2447 --incstack_idx; | |
2448 fclose(incstack[incstack_idx].fp); | |
2449 vim_free(incstack[incstack_idx].etag_fname); | |
2450 } | |
2451 #endif | |
2452 #ifdef FEAT_MBYTE | |
2453 if (vimconv.vc_type != CONV_NONE) | |
2454 convert_setup(&vimconv, NULL, NULL); | |
2455 #endif | |
2456 | |
2457 #ifdef FEAT_TAG_BINS | |
3131 | 2458 tag_file_sorted = NUL; |
7 | 2459 if (sort_error) |
2460 { | |
2461 EMSG2(_("E432: Tags file not sorted: %s"), tag_fname); | |
2462 sort_error = FALSE; | |
2463 } | |
2464 #endif | |
2465 | |
2466 /* | |
2467 * Stop searching if sufficient tags have been found. | |
2468 */ | |
2469 if (match_count >= mincount) | |
2470 { | |
2471 retval = OK; | |
2472 stop_searching = TRUE; | |
2473 } | |
2474 | |
2475 #ifdef FEAT_CSCOPE | |
2476 if (stop_searching || use_cscope) | |
2477 #else | |
2478 if (stop_searching) | |
2479 #endif | |
2480 break; | |
2481 | |
2482 } /* end of for-each-file loop */ | |
2483 | |
692 | 2484 #ifdef FEAT_CSCOPE |
2485 if (!use_cscope) | |
2486 #endif | |
2487 tagname_free(&tn); | |
2488 | |
7 | 2489 #ifdef FEAT_TAG_BINS |
413 | 2490 /* stop searching when already did a linear search, or when TAG_NOIC |
2491 * used, and 'ignorecase' not set or already did case-ignore search */ | |
3131 | 2492 if (stop_searching || linear || (!p_ic && noic) || orgpat.regmatch.rm_ic) |
7 | 2493 break; |
2494 # ifdef FEAT_CSCOPE | |
2495 if (use_cscope) | |
2496 break; | |
2497 # endif | |
3131 | 2498 orgpat.regmatch.rm_ic = TRUE; /* try another time while ignoring case */ |
7 | 2499 } |
2500 #endif | |
2501 | |
2502 if (!stop_searching) | |
2503 { | |
2504 if (!did_open && verbose) /* never opened any tags file */ | |
2505 EMSG(_("E433: No tags file")); | |
2506 retval = OK; /* It's OK even when no tag found */ | |
2507 } | |
2508 | |
2509 findtag_end: | |
2510 vim_free(lbuf); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
3804
diff
changeset
|
2511 vim_regfree(orgpat.regmatch.regprog); |
7 | 2512 vim_free(tag_fname); |
2513 #ifdef FEAT_EMACS_TAGS | |
2514 vim_free(ebuf); | |
2515 #endif | |
2516 | |
2517 /* | |
2518 * Move the matches from the ga_match[] arrays into one list of | |
2519 * matches. When retval == FAIL, free the matches. | |
2520 */ | |
2521 if (retval == FAIL) | |
2522 match_count = 0; | |
2523 | |
2524 if (match_count > 0) | |
2525 matches = (char_u **)lalloc((long_u)(match_count * sizeof(char_u *)), | |
2526 TRUE); | |
2527 else | |
2528 matches = NULL; | |
2529 match_count = 0; | |
2530 for (mtt = 0; mtt < MT_COUNT; ++mtt) | |
2531 { | |
2532 for (i = 0; i < ga_match[mtt].ga_len; ++i) | |
2533 { | |
2534 mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i]; | |
2535 if (matches == NULL) | |
2536 vim_free(mfp); | |
2537 else | |
2538 { | |
2539 /* To avoid allocating memory again we turn the struct | |
2540 * match_found into a string. For help the priority was not | |
2541 * included in the length. */ | |
2542 mch_memmove(mfp, mfp->match, | |
2543 (size_t)(mfp->len + (help_only ? ML_HELP_LEN : 0))); | |
2544 matches[match_count++] = (char_u *)mfp; | |
2545 } | |
2546 } | |
2547 ga_clear(&ga_match[mtt]); | |
2548 } | |
2549 | |
2550 *matchesp = matches; | |
2551 *num_matches = match_count; | |
2552 | |
2553 curbuf->b_help = help_save; | |
2554 #ifdef FEAT_MULTI_LANG | |
2555 vim_free(saved_pat); | |
2556 #endif | |
2557 | |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
2558 p_ic = save_p_ic; |
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
6851
diff
changeset
|
2559 |
7 | 2560 return retval; |
2561 } | |
2562 | |
2563 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
|
2564 static void found_tagfile_cb(char_u *fname, void *cookie); |
7 | 2565 |
2566 /* | |
2567 * Callback function for finding all "tags" and "tags-??" files in | |
2568 * 'runtimepath' doc directories. | |
2569 */ | |
2570 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2571 found_tagfile_cb(char_u *fname, void *cookie UNUSED) |
7 | 2572 { |
2573 if (ga_grow(&tag_fnames, 1) == OK) | |
2574 ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = | |
2575 vim_strsave(fname); | |
2576 } | |
2577 | |
359 | 2578 #if defined(EXITFREE) || defined(PROTO) |
2579 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2580 free_tag_stuff(void) |
359 | 2581 { |
692 | 2582 ga_clear_strings(&tag_fnames); |
359 | 2583 do_tag(NULL, DT_FREE, 0, 0, 0); |
1818 | 2584 tag_freematch(); |
2585 | |
2586 # if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2587 if (ptag_entry.tagname) | |
2588 { | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2185
diff
changeset
|
2589 vim_free(ptag_entry.tagname); |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2185
diff
changeset
|
2590 ptag_entry.tagname = NULL; |
1818 | 2591 } |
2592 # endif | |
359 | 2593 } |
2594 #endif | |
2595 | |
7 | 2596 /* |
2597 * Get the next name of a tag file from the tag file list. | |
2598 * For help files, use "tags" file only. | |
2599 * | |
2600 * Return FAIL if no more tag file names, OK otherwise. | |
2601 */ | |
514 | 2602 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2603 get_tagfname( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2604 tagname_T *tnp, /* holds status info */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2605 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
|
2606 char_u *buf) /* pointer to buffer of MAXPATHL chars */ |
7 | 2607 { |
2608 char_u *fname = NULL; | |
2609 char_u *r_ptr; | |
2610 | |
692 | 2611 if (first) |
2612 vim_memset(tnp, 0, sizeof(tagname_T)); | |
2613 | |
514 | 2614 if (curbuf->b_help) |
7 | 2615 { |
514 | 2616 /* |
2617 * For help files it's done in a completely different way: | |
2618 * Find "doc/tags" and "doc/tags-??" in all directories in | |
2619 * 'runtimepath'. | |
2620 */ | |
2621 if (first) | |
7 | 2622 { |
2623 ga_clear_strings(&tag_fnames); | |
2624 ga_init2(&tag_fnames, (int)sizeof(char_u *), 10); | |
2625 do_in_runtimepath((char_u *) | |
2626 #ifdef FEAT_MULTI_LANG | |
36 | 2627 # ifdef VMS |
2628 /* Functions decc$to_vms() and decc$translate_vms() crash | |
2629 * on some VMS systems with wildcards "??". Seems ECO | |
2630 * patches do fix the problem in C RTL, but we can't use | |
2631 * an #ifdef for that. */ | |
2632 "doc/tags doc/tags-*" | |
2633 # else | |
7 | 2634 "doc/tags doc/tags-??" |
36 | 2635 # endif |
7 | 2636 #else |
2637 "doc/tags" | |
2638 #endif | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
2639 , DIP_ALL, found_tagfile_cb, NULL); |
7 | 2640 } |
602 | 2641 |
692 | 2642 if (tnp->tn_hf_idx >= tag_fnames.ga_len) |
7 | 2643 { |
2644 /* Not found in 'runtimepath', use 'helpfile', if it exists and | |
2645 * wasn't used yet, replacing "help.txt" with "tags". */ | |
692 | 2646 if (tnp->tn_hf_idx > tag_fnames.ga_len || *p_hf == NUL) |
7 | 2647 return FAIL; |
692 | 2648 ++tnp->tn_hf_idx; |
7 | 2649 STRCPY(buf, p_hf); |
2650 STRCPY(gettail(buf), "tags"); | |
2651 } | |
2652 else | |
692 | 2653 vim_strncpy(buf, ((char_u **)(tag_fnames.ga_data))[ |
2654 tnp->tn_hf_idx++], MAXPATHL - 1); | |
514 | 2655 return OK; |
2656 } | |
2657 | |
2658 if (first) | |
2659 { | |
692 | 2660 /* Init. We make a copy of 'tags', because autocommands may change |
2661 * the value without notifying us. */ | |
2662 tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL) | |
2663 ? curbuf->b_p_tags : p_tags); | |
2664 if (tnp->tn_tags == NULL) | |
2665 return FAIL; | |
2666 tnp->tn_np = tnp->tn_tags; | |
7 | 2667 } |
692 | 2668 |
2669 /* | |
2670 * Loop until we have found a file name that can be used. | |
2671 * There are two states: | |
2672 * tnp->tn_did_filefind_init == FALSE: setup for next part in 'tags'. | |
2673 * tnp->tn_did_filefind_init == TRUE: find next file in this part. | |
2674 */ | |
2675 for (;;) | |
7 | 2676 { |
692 | 2677 if (tnp->tn_did_filefind_init) |
7 | 2678 { |
692 | 2679 fname = vim_findfile(tnp->tn_search_ctx); |
2680 if (fname != NULL) | |
2681 break; | |
2682 | |
2683 tnp->tn_did_filefind_init = FALSE; | |
2684 } | |
2685 else | |
2686 { | |
2687 char_u *filename = NULL; | |
2688 | |
2689 /* Stop when used all parts of 'tags'. */ | |
2690 if (*tnp->tn_np == NUL) | |
7 | 2691 { |
692 | 2692 vim_findfile_cleanup(tnp->tn_search_ctx); |
2693 tnp->tn_search_ctx = NULL; | |
2694 return FAIL; | |
7 | 2695 } |
692 | 2696 |
2697 /* | |
2698 * Copy next file name into buf. | |
2699 */ | |
2700 buf[0] = NUL; | |
2701 (void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,"); | |
7 | 2702 |
2703 #ifdef FEAT_PATH_EXTRA | |
692 | 2704 r_ptr = vim_findfile_stopdir(buf); |
7 | 2705 #else |
692 | 2706 r_ptr = NULL; |
7 | 2707 #endif |
692 | 2708 /* move the filename one char forward and truncate the |
2709 * filepath with a NUL */ | |
2710 filename = gettail(buf); | |
1620 | 2711 STRMOVE(filename + 1, filename); |
692 | 2712 *filename++ = NUL; |
2713 | |
2714 tnp->tn_search_ctx = vim_findfile_init(buf, filename, | |
2715 r_ptr, 100, | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2185
diff
changeset
|
2716 FALSE, /* don't free visited list */ |
1541 | 2717 FINDFILE_FILE, /* we search for a file */ |
692 | 2718 tnp->tn_search_ctx, TRUE, curbuf->b_ffname); |
2719 if (tnp->tn_search_ctx != NULL) | |
2720 tnp->tn_did_filefind_init = TRUE; | |
7 | 2721 } |
2722 } | |
2723 | |
692 | 2724 STRCPY(buf, fname); |
2725 vim_free(fname); | |
7 | 2726 return OK; |
2727 } | |
2728 | |
2729 /* | |
692 | 2730 * Free the contents of a tagname_T that was filled by get_tagfname(). |
2731 */ | |
2732 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2733 tagname_free(tagname_T *tnp) |
692 | 2734 { |
2735 vim_free(tnp->tn_tags); | |
2736 vim_findfile_cleanup(tnp->tn_search_ctx); | |
1541 | 2737 tnp->tn_search_ctx = NULL; |
692 | 2738 ga_clear_strings(&tag_fnames); |
2739 } | |
2740 | |
2741 /* | |
7 | 2742 * Parse one line from the tags file. Find start/end of tag name, start/end of |
2743 * file name and start of search pattern. | |
2744 * | |
2745 * If is_etag is TRUE, tagp->fname and tagp->fname_end are not set. | |
2746 * | |
2747 * Return FAIL if there is a format error in this line, OK otherwise. | |
2748 */ | |
2749 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2750 parse_tag_line( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2751 char_u *lbuf, /* line to be parsed */ |
7 | 2752 #ifdef FEAT_EMACS_TAGS |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2753 int is_etag, |
7 | 2754 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2755 tagptrs_T *tagp) |
7 | 2756 { |
2757 char_u *p; | |
2758 | |
2759 #ifdef FEAT_EMACS_TAGS | |
2760 char_u *p_7f; | |
2761 | |
2762 if (is_etag) | |
2763 { | |
2764 /* | |
2765 * There are two formats for an emacs tag line: | |
2766 * 1: struct EnvBase ^?EnvBase^A139,4627 | |
2767 * 2: #define ARPB_WILD_WORLD ^?153,5194 | |
2768 */ | |
2769 p_7f = vim_strchr(lbuf, 0x7f); | |
2770 if (p_7f == NULL) | |
1770 | 2771 { |
2772 etag_fail: | |
2773 if (vim_strchr(lbuf, '\n') == NULL) | |
2774 { | |
2775 /* Truncated line. Ignore it. */ | |
2776 if (p_verbose >= 5) | |
2777 { | |
2778 verbose_enter(); | |
2779 MSG(_("Ignoring long line in tags file")); | |
2780 verbose_leave(); | |
2781 } | |
2782 tagp->command = lbuf; | |
2783 tagp->tagname = lbuf; | |
2784 tagp->tagname_end = lbuf; | |
2785 return OK; | |
2786 } | |
7 | 2787 return FAIL; |
1770 | 2788 } |
7 | 2789 |
2790 /* Find ^A. If not found the line number is after the 0x7f */ | |
2791 p = vim_strchr(p_7f, Ctrl_A); | |
2792 if (p == NULL) | |
2793 p = p_7f + 1; | |
2794 else | |
2795 ++p; | |
2796 | |
2797 if (!VIM_ISDIGIT(*p)) /* check for start of line number */ | |
1770 | 2798 goto etag_fail; |
7 | 2799 tagp->command = p; |
2800 | |
2801 | |
2802 if (p[-1] == Ctrl_A) /* first format: explicit tagname given */ | |
2803 { | |
2804 tagp->tagname = p_7f + 1; | |
2805 tagp->tagname_end = p - 1; | |
2806 } | |
2807 else /* second format: isolate tagname */ | |
2808 { | |
2809 /* find end of tagname */ | |
2810 for (p = p_7f - 1; !vim_iswordc(*p); --p) | |
2811 if (p == lbuf) | |
1770 | 2812 goto etag_fail; |
7 | 2813 tagp->tagname_end = p + 1; |
2814 while (p >= lbuf && vim_iswordc(*p)) | |
2815 --p; | |
2816 tagp->tagname = p + 1; | |
2817 } | |
2818 } | |
2819 else /* not an Emacs tag */ | |
2820 { | |
2821 #endif | |
2822 /* Isolate the tagname, from lbuf up to the first white */ | |
2823 tagp->tagname = lbuf; | |
2824 #ifdef FEAT_TAG_ANYWHITE | |
2825 p = skiptowhite(lbuf); | |
2826 #else | |
2827 p = vim_strchr(lbuf, TAB); | |
2828 if (p == NULL) | |
2829 return FAIL; | |
2830 #endif | |
2831 tagp->tagname_end = p; | |
2832 | |
2833 /* Isolate file name, from first to second white space */ | |
2834 #ifdef FEAT_TAG_ANYWHITE | |
2835 p = skipwhite(p); | |
2836 #else | |
2837 if (*p != NUL) | |
2838 ++p; | |
2839 #endif | |
2840 tagp->fname = p; | |
2841 #ifdef FEAT_TAG_ANYWHITE | |
2842 p = skiptowhite(p); | |
2843 #else | |
2844 p = vim_strchr(p, TAB); | |
2845 if (p == NULL) | |
2846 return FAIL; | |
2847 #endif | |
2848 tagp->fname_end = p; | |
2849 | |
2850 /* find start of search command, after second white space */ | |
2851 #ifdef FEAT_TAG_ANYWHITE | |
2852 p = skipwhite(p); | |
2853 #else | |
2854 if (*p != NUL) | |
2855 ++p; | |
2856 #endif | |
2857 if (*p == NUL) | |
2858 return FAIL; | |
2859 tagp->command = p; | |
2860 #ifdef FEAT_EMACS_TAGS | |
2861 } | |
2862 #endif | |
2863 | |
2864 return OK; | |
2865 } | |
2866 | |
2867 /* | |
2868 * Check if tagname is a static tag | |
2869 * | |
2870 * Static tags produced by the older ctags program have the format: | |
2871 * 'file:tag file /pattern'. | |
1204 | 2872 * This is only recognized when both occurrence of 'file' are the same, to |
7 | 2873 * avoid recognizing "string::string" or ":exit". |
2874 * | |
2875 * Static tags produced by the new ctags program have the format: | |
2876 * 'tag file /pattern/;"<Tab>file:' " | |
2877 * | |
2878 * Return TRUE if it is a static tag and adjust *tagname to the real tag. | |
2879 * Return FALSE if it is not a static tag. | |
2880 */ | |
2881 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2882 test_for_static(tagptrs_T *tagp) |
7 | 2883 { |
2884 char_u *p; | |
2885 | |
2886 #ifdef FEAT_TAG_OLDSTATIC | |
2887 int len; | |
2888 | |
2889 /* | |
2890 * Check for old style static tag: "file:tag file .." | |
2891 */ | |
2892 len = (int)(tagp->fname_end - tagp->fname); | |
2893 p = tagp->tagname + len; | |
2894 if ( p < tagp->tagname_end | |
2895 && *p == ':' | |
2896 && fnamencmp(tagp->tagname, tagp->fname, len) == 0) | |
2897 { | |
2898 tagp->tagname = p + 1; | |
2899 return TRUE; | |
2900 } | |
2901 #endif | |
2902 | |
2903 /* | |
2904 * Check for new style static tag ":...<Tab>file:[<Tab>...]" | |
2905 */ | |
2906 p = tagp->command; | |
2907 while ((p = vim_strchr(p, '\t')) != NULL) | |
2908 { | |
2909 ++p; | |
2910 if (STRNCMP(p, "file:", 5) == 0) | |
2911 return TRUE; | |
2912 } | |
2913 | |
2914 return FALSE; | |
2915 } | |
2916 | |
2917 /* | |
2918 * Parse a line from a matching tag. Does not change the line itself. | |
2919 * | |
2920 * The line that we get looks like this: | |
2921 * Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf> | |
2922 * other tag: <mtt><tag_fname><NUL><NUL><lbuf> | |
2923 * without Emacs tags: <mtt><tag_fname><NUL><lbuf> | |
2924 * | |
2925 * Return OK or FAIL. | |
2926 */ | |
2927 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2928 parse_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2929 char_u *lbuf, /* input: matching line */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2930 tagptrs_T *tagp) /* output: pointers into the line */ |
7 | 2931 { |
2932 int retval; | |
2933 char_u *p; | |
2934 char_u *pc, *pt; | |
2935 | |
2936 tagp->tag_fname = lbuf + 1; | |
2937 lbuf += STRLEN(tagp->tag_fname) + 2; | |
2938 #ifdef FEAT_EMACS_TAGS | |
2939 if (*lbuf) | |
2940 { | |
2941 tagp->is_etag = TRUE; | |
2942 tagp->fname = lbuf; | |
2943 lbuf += STRLEN(lbuf); | |
2944 tagp->fname_end = lbuf++; | |
2945 } | |
2946 else | |
2947 { | |
2948 tagp->is_etag = FALSE; | |
2949 ++lbuf; | |
2950 } | |
2951 #endif | |
2952 | |
2953 /* Find search pattern and the file name for non-etags. */ | |
2954 retval = parse_tag_line(lbuf, | |
2955 #ifdef FEAT_EMACS_TAGS | |
2956 tagp->is_etag, | |
2957 #endif | |
2958 tagp); | |
2959 | |
2960 tagp->tagkind = NULL; | |
2961 tagp->command_end = NULL; | |
2962 | |
2963 if (retval == OK) | |
2964 { | |
2965 /* Try to find a kind field: "kind:<kind>" or just "<kind>"*/ | |
2966 p = tagp->command; | |
2967 if (find_extra(&p) == OK) | |
2968 { | |
2969 tagp->command_end = p; | |
2970 p += 2; /* skip ";\"" */ | |
2971 if (*p++ == TAB) | |
2972 while (ASCII_ISALPHA(*p)) | |
2973 { | |
2974 if (STRNCMP(p, "kind:", 5) == 0) | |
2975 { | |
2976 tagp->tagkind = p + 5; | |
2977 break; | |
2978 } | |
2979 pc = vim_strchr(p, ':'); | |
2980 pt = vim_strchr(p, '\t'); | |
2981 if (pc == NULL || (pt != NULL && pc > pt)) | |
2982 { | |
2983 tagp->tagkind = p; | |
2984 break; | |
2985 } | |
2986 if (pt == NULL) | |
2987 break; | |
2988 p = pt + 1; | |
2989 } | |
2990 } | |
2991 if (tagp->tagkind != NULL) | |
2992 { | |
2993 for (p = tagp->tagkind; | |
2994 *p && *p != '\t' && *p != '\r' && *p != '\n'; ++p) | |
2995 ; | |
2996 tagp->tagkind_end = p; | |
2997 } | |
2998 } | |
2999 return retval; | |
3000 } | |
3001 | |
3002 /* | |
3003 * Find out the actual file name of a tag. Concatenate the tags file name | |
3004 * with the matching tag file name. | |
3005 * Returns an allocated string or NULL (out of memory). | |
3006 */ | |
3007 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3008 tag_full_fname(tagptrs_T *tagp) |
7 | 3009 { |
3010 char_u *fullname; | |
3011 int c; | |
3012 | |
3013 #ifdef FEAT_EMACS_TAGS | |
3014 if (tagp->is_etag) | |
3015 c = 0; /* to shut up GCC */ | |
3016 else | |
3017 #endif | |
3018 { | |
3019 c = *tagp->fname_end; | |
3020 *tagp->fname_end = NUL; | |
3021 } | |
3022 fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE); | |
3023 | |
3024 #ifdef FEAT_EMACS_TAGS | |
3025 if (!tagp->is_etag) | |
3026 #endif | |
3027 *tagp->fname_end = c; | |
3028 | |
3029 return fullname; | |
3030 } | |
3031 | |
3032 /* | |
3033 * Jump to a tag that has been found in one of the tag files | |
3034 * | |
3035 * returns OK for success, NOTAGFILE when file not found, FAIL otherwise. | |
3036 */ | |
3037 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3038 jumpto_tag( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3039 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
|
3040 int forceit, /* :ta with ! */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3041 int keep_help) /* keep help flag (FALSE for cscope) */ |
7 | 3042 { |
3043 int save_secure; | |
3044 int save_magic; | |
3045 int save_p_ws, save_p_scs, save_p_ic; | |
3046 linenr_T save_lnum; | |
3047 int csave = 0; | |
3048 char_u *str; | |
3049 char_u *pbuf; /* search pattern buffer */ | |
3050 char_u *pbuf_end; | |
3051 char_u *tofree_fname = NULL; | |
3052 char_u *fname; | |
3053 tagptrs_T tagp; | |
3054 int retval = FAIL; | |
3055 int getfile_result; | |
3056 int search_options; | |
3057 #ifdef FEAT_SEARCH_EXTRA | |
3058 int save_no_hlsearch; | |
3059 #endif | |
3060 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
3061 win_T *curwin_save = NULL; | |
3062 #endif | |
3063 char_u *full_fname = NULL; | |
3064 #ifdef FEAT_FOLDING | |
3065 int old_KeyTyped = KeyTyped; /* getting the file may reset it */ | |
3066 #endif | |
3067 | |
3068 pbuf = alloc(LSIZE); | |
3069 | |
3070 /* parse the match line into the tagp structure */ | |
3071 if (pbuf == NULL || parse_match(lbuf, &tagp) == FAIL) | |
3072 { | |
3073 tagp.fname_end = NULL; | |
3074 goto erret; | |
3075 } | |
3076 | |
3077 /* truncate the file name, so it can be used as a string */ | |
3078 csave = *tagp.fname_end; | |
3079 *tagp.fname_end = NUL; | |
3080 fname = tagp.fname; | |
3081 | |
3082 /* copy the command to pbuf[], remove trailing CR/NL */ | |
3083 str = tagp.command; | |
3084 for (pbuf_end = pbuf; *str && *str != '\n' && *str != '\r'; ) | |
3085 { | |
3086 #ifdef FEAT_EMACS_TAGS | |
3087 if (tagp.is_etag && *str == ',')/* stop at ',' after line number */ | |
3088 break; | |
3089 #endif | |
3090 *pbuf_end++ = *str++; | |
3091 } | |
3092 *pbuf_end = NUL; | |
3093 | |
3094 #ifdef FEAT_EMACS_TAGS | |
3095 if (!tagp.is_etag) | |
3096 #endif | |
3097 { | |
3098 /* | |
3099 * Remove the "<Tab>fieldname:value" stuff; we don't need it here. | |
3100 */ | |
3101 str = pbuf; | |
3102 if (find_extra(&str) == OK) | |
3103 { | |
3104 pbuf_end = str; | |
3105 *pbuf_end = NUL; | |
3106 } | |
3107 } | |
3108 | |
3109 /* | |
3110 * Expand file name, when needed (for environment variables). | |
3111 * If 'tagrelative' option set, may change file name. | |
3112 */ | |
3113 fname = expand_tag_fname(fname, tagp.tag_fname, TRUE); | |
3114 if (fname == NULL) | |
3115 goto erret; | |
3116 tofree_fname = fname; /* free() it later */ | |
3117 | |
3118 /* | |
3119 * Check if the file with the tag exists before abandoning the current | |
3120 * file. Also accept a file name for which there is a matching BufReadCmd | |
3121 * autocommand event (e.g., http://sys/file). | |
3122 */ | |
3123 if (mch_getperm(fname) < 0 | |
3124 #ifdef FEAT_AUTOCMD | |
40 | 3125 && !has_autocmd(EVENT_BUFREADCMD, fname, NULL) |
7 | 3126 #endif |
3127 ) | |
3128 { | |
3129 retval = NOTAGFILE; | |
3130 vim_free(nofile_fname); | |
3131 nofile_fname = vim_strsave(fname); | |
3132 if (nofile_fname == NULL) | |
3133 nofile_fname = empty_option; | |
3134 goto erret; | |
3135 } | |
3136 | |
3137 ++RedrawingDisabled; | |
3138 | |
3139 #ifdef FEAT_GUI | |
3140 need_mouse_correct = TRUE; | |
3141 #endif | |
3142 | |
3143 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 3144 if (g_do_tagpreview != 0) |
7 | 3145 { |
728 | 3146 postponed_split = 0; /* don't split again below */ |
3147 curwin_save = curwin; /* Save current window */ | |
3148 | |
7 | 3149 /* |
3150 * If we are reusing a window, we may change dir when | |
3151 * entering it (autocommands) so turn the tag filename | |
3152 * into a fullpath | |
3153 */ | |
3154 if (!curwin->w_p_pvw) | |
3155 { | |
3156 full_fname = FullName_save(fname, FALSE); | |
3157 fname = full_fname; | |
3158 | |
3159 /* | |
3160 * Make the preview window the current window. | |
3161 * Open a preview window when needed. | |
3162 */ | |
816 | 3163 prepare_tagpreview(TRUE); |
7 | 3164 } |
3165 } | |
3166 | |
682 | 3167 /* If it was a CTRL-W CTRL-] command split window now. For ":tab tag" |
3168 * open a new tab page. */ | |
3169 if (postponed_split || cmdmod.tab != 0) | |
7 | 3170 { |
3171 win_split(postponed_split > 0 ? postponed_split : 0, | |
3172 postponed_split_flags); | |
2583 | 3173 RESET_BINDING(curwin); |
7 | 3174 } |
3175 #endif | |
3176 | |
3177 if (keep_help) | |
3178 { | |
3179 /* A :ta from a help file will keep the b_help flag set. For ":ptag" | |
3180 * we need to use the flag from the window where we came from. */ | |
3181 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 3182 if (g_do_tagpreview != 0) |
7 | 3183 keep_help_flag = curwin_save->w_buffer->b_help; |
3184 else | |
3185 #endif | |
3186 keep_help_flag = curbuf->b_help; | |
3187 } | |
3188 getfile_result = getfile(0, fname, NULL, TRUE, (linenr_T)0, forceit); | |
3189 keep_help_flag = FALSE; | |
3190 | |
3191 if (getfile_result <= 0) /* got to the right file */ | |
3192 { | |
3193 curwin->w_set_curswant = TRUE; | |
3194 #ifdef FEAT_WINDOWS | |
3195 postponed_split = 0; | |
3196 #endif | |
3197 | |
3198 save_secure = secure; | |
3199 secure = 1; | |
3200 #ifdef HAVE_SANDBOX | |
3201 ++sandbox; | |
3202 #endif | |
3203 save_magic = p_magic; | |
3204 p_magic = FALSE; /* always execute with 'nomagic' */ | |
3205 #ifdef FEAT_SEARCH_EXTRA | |
3206 /* Save value of no_hlsearch, jumping to a tag is not a real search */ | |
3207 save_no_hlsearch = no_hlsearch; | |
3208 #endif | |
3209 | |
3210 /* | |
3211 * If 'cpoptions' contains 't', store the search pattern for the "n" | |
3212 * command. If 'cpoptions' does not contain 't', the search pattern | |
3213 * is not stored. | |
3214 */ | |
3215 if (vim_strchr(p_cpo, CPO_TAGPAT) != NULL) | |
3216 search_options = 0; | |
3217 else | |
3218 search_options = SEARCH_KEEP; | |
3219 | |
3220 /* | |
3221 * If the command is a search, try here. | |
3222 * | |
3223 * Reset 'smartcase' for the search, since the search pattern was not | |
3224 * typed by the user. | |
3225 * Only use do_search() when there is a full search command, without | |
3226 * anything following. | |
3227 */ | |
3228 str = pbuf; | |
3229 if (pbuf[0] == '/' || pbuf[0] == '?') | |
3230 str = skip_regexp(pbuf + 1, pbuf[0], FALSE, NULL) + 1; | |
3231 if (str > pbuf_end - 1) /* search command with nothing following */ | |
3232 { | |
3233 save_p_ws = p_ws; | |
3234 save_p_ic = p_ic; | |
3235 save_p_scs = p_scs; | |
3236 p_ws = TRUE; /* need 'wrapscan' for backward searches */ | |
3237 p_ic = FALSE; /* don't ignore case now */ | |
3238 p_scs = FALSE; | |
3239 #if 0 /* disabled for now */ | |
3240 #ifdef FEAT_CMDHIST | |
3241 /* put pattern in search history */ | |
3242 add_to_history(HIST_SEARCH, pbuf + 1, TRUE, pbuf[0]); | |
3243 #endif | |
3244 #endif | |
3245 save_lnum = curwin->w_cursor.lnum; | |
3246 curwin->w_cursor.lnum = 0; /* start search before first line */ | |
1521 | 3247 if (do_search(NULL, pbuf[0], pbuf + 1, (long)1, |
3248 search_options, NULL)) | |
7 | 3249 retval = OK; |
3250 else | |
3251 { | |
3252 int found = 1; | |
3253 int cc; | |
3254 | |
3255 /* | |
3256 * try again, ignore case now | |
3257 */ | |
3258 p_ic = TRUE; | |
3259 if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1, | |
1521 | 3260 search_options, NULL)) |
7 | 3261 { |
3262 /* | |
3263 * Failed to find pattern, take a guess: "^func (" | |
3264 */ | |
3265 found = 2; | |
3266 (void)test_for_static(&tagp); | |
3267 cc = *tagp.tagname_end; | |
3268 *tagp.tagname_end = NUL; | |
3269 sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname); | |
1521 | 3270 if (!do_search(NULL, '/', pbuf, (long)1, |
3271 search_options, NULL)) | |
7 | 3272 { |
3273 /* Guess again: "^char * \<func (" */ | |
3274 sprintf((char *)pbuf, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(", | |
3275 tagp.tagname); | |
3276 if (!do_search(NULL, '/', pbuf, (long)1, | |
1521 | 3277 search_options, NULL)) |
7 | 3278 found = 0; |
3279 } | |
3280 *tagp.tagname_end = cc; | |
3281 } | |
3282 if (found == 0) | |
3283 { | |
3284 EMSG(_("E434: Can't find tag pattern")); | |
3285 curwin->w_cursor.lnum = save_lnum; | |
3286 } | |
3287 else | |
3288 { | |
3289 /* | |
3290 * Only give a message when really guessed, not when 'ic' | |
3291 * is set and match found while ignoring case. | |
3292 */ | |
3293 if (found == 2 || !save_p_ic) | |
3294 { | |
3295 MSG(_("E435: Couldn't find tag, just guessing!")); | |
3296 if (!msg_scrolled && msg_silent == 0) | |
3297 { | |
3298 out_flush(); | |
3299 ui_delay(1000L, TRUE); | |
3300 } | |
3301 } | |
3302 retval = OK; | |
3303 } | |
3304 } | |
3305 p_ws = save_p_ws; | |
3306 p_ic = save_p_ic; | |
3307 p_scs = save_p_scs; | |
3308 | |
3309 /* A search command may have positioned the cursor beyond the end | |
3310 * of the line. May need to correct that here. */ | |
3311 check_cursor(); | |
3312 } | |
3313 else | |
3314 { | |
3315 curwin->w_cursor.lnum = 1; /* start command in line 1 */ | |
3316 do_cmdline_cmd(pbuf); | |
3317 retval = OK; | |
3318 } | |
3319 | |
3320 /* | |
3321 * When the command has done something that is not allowed make sure | |
3322 * the error message can be seen. | |
3323 */ | |
3324 if (secure == 2) | |
3325 wait_return(TRUE); | |
3326 secure = save_secure; | |
3327 p_magic = save_magic; | |
3328 #ifdef HAVE_SANDBOX | |
3329 --sandbox; | |
3330 #endif | |
3331 #ifdef FEAT_SEARCH_EXTRA | |
3332 /* restore no_hlsearch when keeping the old search pattern */ | |
3333 if (search_options) | |
5458 | 3334 { |
3335 SET_NO_HLSEARCH(save_no_hlsearch); | |
3336 } | |
7 | 3337 #endif |
3338 | |
3339 /* Return OK if jumped to another file (at least we found the file!). */ | |
3340 if (getfile_result == -1) | |
3341 retval = OK; | |
3342 | |
3343 if (retval == OK) | |
3344 { | |
3345 /* | |
3346 * For a help buffer: Put the cursor line at the top of the window, | |
3347 * the help subject will be below it. | |
3348 */ | |
3349 if (curbuf->b_help) | |
3350 set_topline(curwin, curwin->w_cursor.lnum); | |
3351 #ifdef FEAT_FOLDING | |
3352 if ((fdo_flags & FDO_TAG) && old_KeyTyped) | |
3353 foldOpenCursor(); | |
3354 #endif | |
3355 } | |
3356 | |
3357 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2713 | 3358 if (g_do_tagpreview != 0 |
3359 && curwin != curwin_save && win_valid(curwin_save)) | |
7 | 3360 { |
3361 /* Return cursor to where we were */ | |
3362 validate_cursor(); | |
3363 redraw_later(VALID); | |
3364 win_enter(curwin_save, TRUE); | |
3365 } | |
3366 #endif | |
3367 | |
3368 --RedrawingDisabled; | |
3369 } | |
3370 else | |
3371 { | |
3372 --RedrawingDisabled; | |
3373 #ifdef FEAT_WINDOWS | |
3374 if (postponed_split) /* close the window */ | |
3375 { | |
3376 win_close(curwin, FALSE); | |
3377 postponed_split = 0; | |
3378 } | |
3379 #endif | |
3380 } | |
3381 | |
3382 erret: | |
3383 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
3384 g_do_tagpreview = 0; /* For next time */ | |
3385 #endif | |
3386 if (tagp.fname_end != NULL) | |
3387 *tagp.fname_end = csave; | |
3388 vim_free(pbuf); | |
3389 vim_free(tofree_fname); | |
3390 vim_free(full_fname); | |
3391 | |
3392 return retval; | |
3393 } | |
3394 | |
3395 /* | |
3396 * If "expand" is TRUE, expand wildcards in fname. | |
3397 * If 'tagrelative' option set, change fname (name of file containing tag) | |
3398 * according to tag_fname (name of tag file containing fname). | |
3399 * Returns a pointer to allocated memory (or NULL when out of memory). | |
3400 */ | |
3401 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3402 expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) |
7 | 3403 { |
3404 char_u *p; | |
3405 char_u *retval; | |
3406 char_u *expanded_fname = NULL; | |
3407 expand_T xpc; | |
3408 | |
3409 /* | |
3410 * Expand file name (for environment variables) when needed. | |
3411 */ | |
3412 if (expand && mch_has_wildcard(fname)) | |
3413 { | |
3414 ExpandInit(&xpc); | |
3415 xpc.xp_context = EXPAND_FILES; | |
3416 expanded_fname = ExpandOne(&xpc, (char_u *)fname, NULL, | |
3417 WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); | |
3418 if (expanded_fname != NULL) | |
3419 fname = expanded_fname; | |
3420 } | |
3421 | |
3422 if ((p_tr || curbuf->b_help) | |
3423 && !vim_isAbsName(fname) | |
3424 && (p = gettail(tag_fname)) != tag_fname) | |
3425 { | |
3426 retval = alloc(MAXPATHL); | |
3427 if (retval != NULL) | |
3428 { | |
3429 STRCPY(retval, tag_fname); | |
418 | 3430 vim_strncpy(retval + (p - tag_fname), fname, |
3431 MAXPATHL - (p - tag_fname) - 1); | |
7 | 3432 /* |
3433 * Translate names like "src/a/../b/file.c" into "src/b/file.c". | |
3434 */ | |
3435 simplify_filename(retval); | |
3436 } | |
3437 } | |
3438 else | |
3439 retval = vim_strsave(fname); | |
3440 | |
3441 vim_free(expanded_fname); | |
3442 | |
3443 return retval; | |
3444 } | |
3445 | |
3446 /* | |
3447 * Converts a file name into a canonical form. It simplifies a file name into | |
3448 * its simplest form by stripping out unneeded components, if any. The | |
3449 * resulting file name is simplified in place and will either be the same | |
3450 * length as that supplied, or shorter. | |
3451 */ | |
3452 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3453 simplify_filename(char_u *filename) |
7 | 3454 { |
3455 #ifndef AMIGA /* Amiga doesn't have "..", it uses "/" */ | |
3456 int components = 0; | |
3457 char_u *p, *tail, *start; | |
3458 int stripping_disabled = FALSE; | |
3459 int relative = TRUE; | |
3460 | |
3461 p = filename; | |
3462 #ifdef BACKSLASH_IN_FILENAME | |
3463 if (p[1] == ':') /* skip "x:" */ | |
3464 p += 2; | |
3465 #endif | |
3466 | |
3467 if (vim_ispathsep(*p)) | |
3468 { | |
3469 relative = FALSE; | |
3470 do | |
3471 ++p; | |
3472 while (vim_ispathsep(*p)); | |
3473 } | |
3474 start = p; /* remember start after "c:/" or "/" or "///" */ | |
3475 | |
3476 do | |
3477 { | |
3478 /* At this point "p" is pointing to the char following a single "/" | |
3479 * or "p" is at the "start" of the (absolute or relative) path name. */ | |
3480 #ifdef VMS | |
3481 /* VMS allows device:[path] - don't strip the [ in directory */ | |
3482 if ((*p == '[' || *p == '<') && p > filename && p[-1] == ':') | |
3483 { | |
3484 /* :[ or :< composition: vms directory component */ | |
3485 ++components; | |
3486 p = getnextcomp(p + 1); | |
3487 } | |
3488 /* allow remote calls as host"user passwd"::device:[path] */ | |
3489 else if (p[0] == ':' && p[1] == ':' && p > filename && p[-1] == '"' ) | |
3490 { | |
3491 /* ":: composition: vms host/passwd component */ | |
3492 ++components; | |
3493 p = getnextcomp(p + 2); | |
3494 } | |
3495 else | |
3496 #endif | |
3497 if (vim_ispathsep(*p)) | |
1620 | 3498 STRMOVE(p, p + 1); /* remove duplicate "/" */ |
7 | 3499 else if (p[0] == '.' && (vim_ispathsep(p[1]) || p[1] == NUL)) |
3500 { | |
3501 if (p == start && relative) | |
3502 p += 1 + (p[1] != NUL); /* keep single "." or leading "./" */ | |
3503 else | |
3504 { | |
3505 /* Strip "./" or ".///". If we are at the end of the file name | |
3506 * and there is no trailing path separator, either strip "/." if | |
3507 * we are after "start", or strip "." if we are at the beginning | |
3508 * of an absolute path name . */ | |
3509 tail = p + 1; | |
3510 if (p[1] != NUL) | |
3511 while (vim_ispathsep(*tail)) | |
39 | 3512 mb_ptr_adv(tail); |
7 | 3513 else if (p > start) |
3514 --p; /* strip preceding path separator */ | |
1620 | 3515 STRMOVE(p, tail); |
7 | 3516 } |
3517 } | |
3518 else if (p[0] == '.' && p[1] == '.' && | |
3519 (vim_ispathsep(p[2]) || p[2] == NUL)) | |
3520 { | |
3521 /* Skip to after ".." or "../" or "..///". */ | |
3522 tail = p + 2; | |
3523 while (vim_ispathsep(*tail)) | |
39 | 3524 mb_ptr_adv(tail); |
7 | 3525 |
3526 if (components > 0) /* strip one preceding component */ | |
3527 { | |
3528 int do_strip = FALSE; | |
3529 char_u saved_char; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
3530 stat_T st; |
7 | 3531 |
3532 /* Don't strip for an erroneous file name. */ | |
3533 if (!stripping_disabled) | |
3534 { | |
3535 /* If the preceding component does not exist in the file | |
3536 * system, we strip it. On Unix, we don't accept a symbolic | |
3537 * link that refers to a non-existent file. */ | |
3538 saved_char = p[-1]; | |
3539 p[-1] = NUL; | |
3540 #ifdef UNIX | |
3541 if (mch_lstat((char *)filename, &st) < 0) | |
3542 #else | |
3543 if (mch_stat((char *)filename, &st) < 0) | |
3544 #endif | |
3545 do_strip = TRUE; | |
3546 p[-1] = saved_char; | |
3547 | |
3548 --p; | |
3549 /* Skip back to after previous '/'. */ | |
39 | 3550 while (p > start && !after_pathsep(start, p)) |
3551 mb_ptr_back(start, p); | |
7 | 3552 |
3553 if (!do_strip) | |
3554 { | |
3555 /* If the component exists in the file system, check | |
3556 * that stripping it won't change the meaning of the | |
3557 * file name. First get information about the | |
3558 * unstripped file name. This may fail if the component | |
3559 * to strip is not a searchable directory (but a regular | |
3560 * file, for instance), since the trailing "/.." cannot | |
3561 * be applied then. We don't strip it then since we | |
3562 * don't want to replace an erroneous file name by | |
3563 * a valid one, and we disable stripping of later | |
3564 * components. */ | |
3565 saved_char = *tail; | |
3566 *tail = NUL; | |
3567 if (mch_stat((char *)filename, &st) >= 0) | |
3568 do_strip = TRUE; | |
3569 else | |
3570 stripping_disabled = TRUE; | |
3571 *tail = saved_char; | |
3572 #ifdef UNIX | |
3573 if (do_strip) | |
3574 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
3575 stat_T new_st; |
7 | 3576 |
3577 /* On Unix, the check for the unstripped file name | |
3578 * above works also for a symbolic link pointing to | |
3579 * a searchable directory. But then the parent of | |
3580 * the directory pointed to by the link must be the | |
3581 * same as the stripped file name. (The latter | |
3582 * exists in the file system since it is the | |
3583 * component's parent directory.) */ | |
3584 if (p == start && relative) | |
3585 (void)mch_stat(".", &new_st); | |
3586 else | |
3587 { | |
3588 saved_char = *p; | |
3589 *p = NUL; | |
3590 (void)mch_stat((char *)filename, &new_st); | |
3591 *p = saved_char; | |
3592 } | |
3593 | |
3594 if (new_st.st_ino != st.st_ino || | |
3595 new_st.st_dev != st.st_dev) | |
3596 { | |
3597 do_strip = FALSE; | |
3598 /* We don't disable stripping of later | |
3599 * components since the unstripped path name is | |
3600 * still valid. */ | |
3601 } | |
3602 } | |
3603 #endif | |
3604 } | |
3605 } | |
3606 | |
3607 if (!do_strip) | |
3608 { | |
3609 /* Skip the ".." or "../" and reset the counter for the | |
3610 * components that might be stripped later on. */ | |
3611 p = tail; | |
3612 components = 0; | |
3613 } | |
3614 else | |
3615 { | |
3616 /* Strip previous component. If the result would get empty | |
3617 * and there is no trailing path separator, leave a single | |
3618 * "." instead. If we are at the end of the file name and | |
3619 * there is no trailing path separator and a preceding | |
3620 * component is left after stripping, strip its trailing | |
3621 * path separator as well. */ | |
3622 if (p == start && relative && tail[-1] == '.') | |
3623 { | |
3624 *p++ = '.'; | |
3625 *p = NUL; | |
3626 } | |
3627 else | |
3628 { | |
3629 if (p > start && tail[-1] == '.') | |
3630 --p; | |
1620 | 3631 STRMOVE(p, tail); /* strip previous component */ |
7 | 3632 } |
3633 | |
3634 --components; | |
3635 } | |
3636 } | |
3637 else if (p == start && !relative) /* leading "/.." or "/../" */ | |
1620 | 3638 STRMOVE(p, tail); /* strip ".." or "../" */ |
7 | 3639 else |
3640 { | |
3641 if (p == start + 2 && p[-2] == '.') /* leading "./../" */ | |
3642 { | |
1620 | 3643 STRMOVE(p - 2, p); /* strip leading "./" */ |
7 | 3644 tail -= 2; |
3645 } | |
3646 p = tail; /* skip to char after ".." or "../" */ | |
3647 } | |
3648 } | |
3649 else | |
3650 { | |
3651 ++components; /* simple path component */ | |
3652 p = getnextcomp(p); | |
3653 } | |
3654 } while (*p != NUL); | |
3655 #endif /* !AMIGA */ | |
3656 } | |
3657 | |
3658 /* | |
3659 * Check if we have a tag for the buffer with name "buf_ffname". | |
3660 * This is a bit slow, because of the full path compare in fullpathcmp(). | |
3661 * Return TRUE if tag for file "fname" if tag file "tag_fname" is for current | |
3662 * file. | |
3663 */ | |
3664 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3665 test_for_current( |
7 | 3666 #ifdef FEAT_EMACS_TAGS |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3667 int is_etag, |
7 | 3668 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3669 char_u *fname, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3670 char_u *fname_end, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3671 char_u *tag_fname, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3672 char_u *buf_ffname) |
7 | 3673 { |
3674 int c; | |
3675 int retval = FALSE; | |
3676 char_u *fullname; | |
3677 | |
3678 if (buf_ffname != NULL) /* if the buffer has a name */ | |
3679 { | |
3680 #ifdef FEAT_EMACS_TAGS | |
3681 if (is_etag) | |
3682 c = 0; /* to shut up GCC */ | |
3683 else | |
3684 #endif | |
3685 { | |
3686 c = *fname_end; | |
3687 *fname_end = NUL; | |
3688 } | |
3689 fullname = expand_tag_fname(fname, tag_fname, TRUE); | |
3690 if (fullname != NULL) | |
3691 { | |
3692 retval = (fullpathcmp(fullname, buf_ffname, TRUE) & FPC_SAME); | |
3693 vim_free(fullname); | |
3694 } | |
3695 #ifdef FEAT_EMACS_TAGS | |
3696 if (!is_etag) | |
3697 #endif | |
3698 *fname_end = c; | |
3699 } | |
3700 | |
3701 return retval; | |
3702 } | |
3703 | |
3704 /* | |
3705 * Find the end of the tagaddress. | |
3706 * Return OK if ";\"" is following, FAIL otherwise. | |
3707 */ | |
3708 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3709 find_extra(char_u **pp) |
7 | 3710 { |
3711 char_u *str = *pp; | |
3712 | |
3713 /* Repeat for addresses separated with ';' */ | |
3714 for (;;) | |
3715 { | |
3716 if (VIM_ISDIGIT(*str)) | |
3717 str = skipdigits(str); | |
3718 else if (*str == '/' || *str == '?') | |
3719 { | |
3720 str = skip_regexp(str + 1, *str, FALSE, NULL); | |
3721 if (*str != **pp) | |
3722 str = NULL; | |
3723 else | |
3724 ++str; | |
3725 } | |
3726 else | |
3727 str = NULL; | |
3728 if (str == NULL || *str != ';' | |
3729 || !(VIM_ISDIGIT(str[1]) || str[1] == '/' || str[1] == '?')) | |
3730 break; | |
3731 ++str; /* skip ';' */ | |
3732 } | |
3733 | |
3734 if (str != NULL && STRNCMP(str, ";\"", 2) == 0) | |
3735 { | |
3736 *pp = str; | |
3737 return OK; | |
3738 } | |
3739 return FAIL; | |
3740 } | |
3741 | |
3742 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
3743 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3744 expand_tags( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3745 int tagnames, /* expand tag names */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3746 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3747 int *num_file, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3748 char_u ***file) |
7 | 3749 { |
3750 int i; | |
3751 int c; | |
3752 int tagnmflag; | |
3753 char_u tagnm[100]; | |
3754 tagptrs_T t_p; | |
3755 int ret; | |
3756 | |
3757 if (tagnames) | |
3758 tagnmflag = TAG_NAMES; | |
3759 else | |
3760 tagnmflag = 0; | |
3761 if (pat[0] == '/') | |
3762 ret = find_tags(pat + 1, num_file, file, | |
3763 TAG_REGEXP | tagnmflag | TAG_VERBOSE, | |
3764 TAG_MANY, curbuf->b_ffname); | |
3765 else | |
3766 ret = find_tags(pat, num_file, file, | |
3767 TAG_REGEXP | tagnmflag | TAG_VERBOSE | TAG_NOIC, | |
3768 TAG_MANY, curbuf->b_ffname); | |
3769 if (ret == OK && !tagnames) | |
3770 { | |
3771 /* Reorganize the tags for display and matching as strings of: | |
3772 * "<tagname>\0<kind>\0<filename>\0" | |
3773 */ | |
3774 for (i = 0; i < *num_file; i++) | |
3775 { | |
3776 parse_match((*file)[i], &t_p); | |
3777 c = (int)(t_p.tagname_end - t_p.tagname); | |
3778 mch_memmove(tagnm, t_p.tagname, (size_t)c); | |
3779 tagnm[c++] = 0; | |
3780 tagnm[c++] = (t_p.tagkind != NULL && *t_p.tagkind) | |
3781 ? *t_p.tagkind : 'f'; | |
3782 tagnm[c++] = 0; | |
3783 mch_memmove((*file)[i] + c, t_p.fname, t_p.fname_end - t_p.fname); | |
3784 (*file)[i][c + (t_p.fname_end - t_p.fname)] = 0; | |
3785 mch_memmove((*file)[i], tagnm, (size_t)c); | |
3786 } | |
3787 } | |
3788 return ret; | |
3789 } | |
3790 #endif | |
179 | 3791 |
3792 #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
|
3793 static int add_tag_field(dict_T *dict, char *field_name, char_u *start, char_u *end); |
179 | 3794 |
3795 /* | |
2185 | 3796 * Add a tag field to the dictionary "dict". |
3797 * Return OK or FAIL. | |
179 | 3798 */ |
3799 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3800 add_tag_field( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3801 dict_T *dict, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3802 char *field_name, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3803 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
|
3804 char_u *end) /* after the value; can be NULL */ |
179 | 3805 { |
2770 | 3806 char_u *buf; |
188 | 3807 int len = 0; |
2770 | 3808 int retval; |
179 | 3809 |
2185 | 3810 /* check that the field name doesn't exist yet */ |
3811 if (dict_find(dict, (char_u *)field_name, -1) != NULL) | |
3812 { | |
3813 if (p_verbose > 0) | |
3814 { | |
3815 verbose_enter(); | |
3816 smsg((char_u *)_("Duplicate field name: %s"), field_name); | |
3817 verbose_leave(); | |
3818 } | |
3819 return FAIL; | |
3820 } | |
2770 | 3821 buf = alloc(MAXPATHL); |
3822 if (buf == NULL) | |
3823 return FAIL; | |
188 | 3824 if (start != NULL) |
3825 { | |
211 | 3826 if (end == NULL) |
3827 { | |
3828 end = start + STRLEN(start); | |
3829 while (end > start && (end[-1] == '\r' || end[-1] == '\n')) | |
3830 --end; | |
3831 } | |
835 | 3832 len = (int)(end - start); |
2770 | 3833 if (len > MAXPATHL - 1) |
3834 len = MAXPATHL - 1; | |
418 | 3835 vim_strncpy(buf, start, len); |
188 | 3836 } |
179 | 3837 buf[len] = NUL; |
2770 | 3838 retval = dict_add_nr_str(dict, field_name, 0L, buf); |
3839 vim_free(buf); | |
3840 return retval; | |
179 | 3841 } |
3842 | |
3843 /* | |
3844 * Add the tags matching the specified pattern to the list "list" | |
3845 * as a dictionary | |
3846 */ | |
3847 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3848 get_tags(list_T *list, char_u *pat) |
179 | 3849 { |
3850 int num_matches, i, ret; | |
3851 char_u **matches, *p; | |
970 | 3852 char_u *full_fname; |
179 | 3853 dict_T *dict; |
3854 tagptrs_T tp; | |
3855 long is_static; | |
3856 | |
3857 ret = find_tags(pat, &num_matches, &matches, | |
3858 TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL); | |
3859 if (ret == OK && num_matches > 0) | |
3860 { | |
3861 for (i = 0; i < num_matches; ++i) | |
3862 { | |
188 | 3863 parse_match(matches[i], &tp); |
3864 is_static = test_for_static(&tp); | |
3865 | |
3866 /* Skip pseudo-tag lines. */ | |
3867 if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0) | |
3868 continue; | |
3869 | |
179 | 3870 if ((dict = dict_alloc()) == NULL) |
3871 ret = FAIL; | |
3872 if (list_append_dict(list, dict) == FAIL) | |
3873 ret = FAIL; | |
3874 | |
970 | 3875 full_fname = tag_full_fname(&tp); |
179 | 3876 if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL |
970 | 3877 || add_tag_field(dict, "filename", full_fname, |
3878 NULL) == FAIL | |
179 | 3879 || add_tag_field(dict, "cmd", tp.command, |
3880 tp.command_end) == FAIL | |
3881 || add_tag_field(dict, "kind", tp.tagkind, | |
3882 tp.tagkind_end) == FAIL | |
3883 || dict_add_nr_str(dict, "static", is_static, NULL) == FAIL) | |
3884 ret = FAIL; | |
3885 | |
970 | 3886 vim_free(full_fname); |
3887 | |
179 | 3888 if (tp.command_end != NULL) |
3889 { | |
3890 for (p = tp.command_end + 3; | |
3891 *p != NUL && *p != '\n' && *p != '\r'; ++p) | |
3892 { | |
3893 if (p == tp.tagkind || (p + 5 == tp.tagkind | |
3894 && STRNCMP(p, "kind:", 5) == 0)) | |
3895 /* skip "kind:<kind>" and "<kind>" */ | |
3896 p = tp.tagkind_end - 1; | |
3897 else if (STRNCMP(p, "file:", 5) == 0) | |
3898 /* skip "file:" (static tag) */ | |
3899 p += 4; | |
188 | 3900 else if (!vim_iswhite(*p)) |
179 | 3901 { |
3902 char_u *s, *n; | |
188 | 3903 int len; |
179 | 3904 |
799 | 3905 /* Add extra field as a dict entry. Fields are |
3906 * separated by Tabs. */ | |
179 | 3907 n = p; |
799 | 3908 while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') |
179 | 3909 ++p; |
835 | 3910 len = (int)(p - n); |
188 | 3911 if (*p == ':' && len > 0) |
3912 { | |
3913 s = ++p; | |
836 | 3914 while (*p != NUL && *p >= ' ') |
188 | 3915 ++p; |
3916 n[len] = NUL; | |
3917 if (add_tag_field(dict, (char *)n, s, p) == FAIL) | |
3918 ret = FAIL; | |
3919 n[len] = ':'; | |
3920 } | |
836 | 3921 else |
3922 /* Skip field without colon. */ | |
3923 while (*p != NUL && *p >= ' ') | |
3924 ++p; | |
1674 | 3925 if (*p == NUL) |
3926 break; | |
179 | 3927 } |
3928 } | |
3929 } | |
3930 | |
3931 vim_free(matches[i]); | |
3932 } | |
3933 vim_free(matches); | |
3934 } | |
3935 return ret; | |
3936 } | |
3937 #endif |