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