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