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