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