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