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