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