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