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