This commit is contained in:
James McCoy 2017-03-19 21:00:45 -04:00
parent 097d04ac71
commit a56615214d
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB

View File

@ -72,20 +72,18 @@ typedef struct {
regmatch_T regmatch; /* regexp program, may be NULL */
} pat_T;
/*
* The matching tags are first stored in one of the hash tables. In
* which one depends on the priority of the match.
* ht_match[] is used to find duplicates, ga_match[] to keep them in sequence.
* At the end, the matches from ga_match[] are concatenated, to make a list
* sorted on priority.
*/
#define MT_ST_CUR 0 /* static match in current file */
#define MT_GL_CUR 1 /* global match in current file */
#define MT_GL_OTH 2 /* global match in other file */
#define MT_ST_OTH 3 /* static match in other file */
#define MT_IC_OFF 4 /* add for icase match */
#define MT_RE_OFF 8 /* add for regexp match */
#define MT_MASK 7 /* mask for printing priority */
// The matching tags are first stored in one of the hash tables. In
// which one depends on the priority of the match.
// ht_match[] is used to find duplicates, ga_match[] to keep them in sequence.
// At the end, the matches from ga_match[] are concatenated, to make a list
// sorted on priority.
#define MT_ST_CUR 0 // static match in current file
#define MT_GL_CUR 1 // global match in current file
#define MT_GL_OTH 2 // global match in other file
#define MT_ST_OTH 3 // static match in other file
#define MT_IC_OFF 4 // add for icase match
#define MT_RE_OFF 8 // add for regexp match
#define MT_MASK 7 // mask for printing priority
#define MT_COUNT 16
static char *mt_names[MT_COUNT/2] =
@ -1124,14 +1122,14 @@ find_tags (
garray_T ga_match[MT_COUNT]; // stores matches in sequence
hashtab_T ht_match[MT_COUNT]; // stores matches by key
hash_T hash = 0;
int match_count = 0; /* number of matches found */
int match_count = 0; // number of matches found
char_u **matches;
int mtt;
int help_save;
int help_pri = 0;
char_u *help_lang_find = NULL; /* lang to be found */
char_u help_lang[3]; /* lang of current tags file */
char_u *saved_pat = NULL; /* copy of pat[] */
char_u *help_lang_find = NULL; // lang to be found
char_u help_lang[3]; // lang of current tags file
char_u *saved_pat = NULL; // copy of pat[]
bool is_txt = false;
pat_T orgpat; /* holds unconverted pattern info */
@ -1182,7 +1180,7 @@ find_tags (
*/
lbuf = xmalloc(lbuf_size);
tag_fname = xmalloc(MAXPATHL + 1);
for (mtt = 0; mtt < MT_COUNT; ++mtt) {
for (mtt = 0; mtt < MT_COUNT; mtt++) {
ga_init(&ga_match[mtt], sizeof(char_u *), 100);
hash_init(&ht_match[mtt]);
}
@ -1192,9 +1190,9 @@ find_tags (
/*
* Initialize a few variables
*/
if (help_only) /* want tags from help file */
curbuf->b_help = true; /* will be restored later */
else if (use_cscope) {
if (help_only) { // want tags from help file
curbuf->b_help = true; // will be restored later
} else if (use_cscope) {
// Make sure we don't mix help and cscope, confuses Coverity.
help_only = false;
curbuf->b_help = false;
@ -1264,13 +1262,14 @@ find_tags (
if (is_txt) {
STRCPY(help_lang, "en");
} else {
/* Prefer help tags according to 'helplang'. Put the
* two-letter language name in help_lang[]. */
// Prefer help tags according to 'helplang'. Put the
// two-letter language name in help_lang[].
i = (int)STRLEN(tag_fname);
if (i > 3 && tag_fname[i - 3] == '-')
if (i > 3 && tag_fname[i - 3] == '-') {
STRCPY(help_lang, tag_fname + i - 2);
else
} else {
STRCPY(help_lang, "en");
}
}
/* When searching for a specific language skip tags files
@ -1755,9 +1754,7 @@ parse_line:
match_re = TRUE;
}
/*
* If a match is found, add it to ht_match[] and ga_match[].
*/
// If a match is found, add it to ht_match[] and ga_match[].
if (match) {
int len = 0;
@ -1795,11 +1792,9 @@ parse_line:
mtt += MT_RE_OFF;
}
/*
* Add the found match in ht_match[mtt] and ga_match[mtt].
* Store the info we need later, which depends on the kind of
* tags we are dealing with.
*/
// Add the found match in ht_match[mtt] and ga_match[mtt].
// Store the info we need later, which depends on the kind of
// tags we are dealing with.
if (help_only) {
# define ML_EXTRA 3
// Append the help-heuristic number after the tagname, for
@ -1814,57 +1809,60 @@ parse_line:
STRCPY(p, tagp.tagname);
p[len] = '@';
STRCPY(p + len + 1, help_lang);
sprintf((char *)p + len + 1 + ML_EXTRA, "%06d",
help_heuristic(tagp.tagname,
match_re ? matchoff : 0, !match_no_ic)
+ help_pri);
snprintf((char *)p + len + 1 + ML_EXTRA, 10, "%06d",
help_heuristic(tagp.tagname,
match_re ? matchoff : 0, !match_no_ic)
+ help_pri);
*tagp.tagname_end = TAB;
} else if (name_only) {
if (get_it_again) {
char_u *temp_end = tagp.command;
if (*temp_end == '/')
if (*temp_end == '/') {
while (*temp_end && *temp_end != '\r'
&& *temp_end != '\n'
&& *temp_end != '$')
&& *temp_end != '$') {
temp_end++;
}
}
if (tagp.command + 2 < temp_end) {
len = (int)(temp_end - tagp.command - 2);
mfp = xmalloc(len + 2);
STRLCPY(mfp, tagp.command + 2, len + 1);
} else
} else {
mfp = NULL;
get_it_again = FALSE;
}
get_it_again = false;
} else {
len = (int)(tagp.tagname_end - tagp.tagname);
mfp = xmalloc(sizeof(char_u) + len + 1);
STRLCPY(mfp, tagp.tagname, len + 1);
/* if wanted, re-read line to get long form too */
if (State & INSERT)
// if wanted, re-read line to get long form too
if (State & INSERT) {
get_it_again = p_sft;
}
}
} else {
#define TAG_SEP 0x01
size_t tag_fname_len = STRLEN(tag_fname);
/* Save the tag in a buffer.
* Use 0x01 to separate fields (Can't use NUL, because the
* hash key is terminated by NUL).
* Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf>
* other tag: <mtt><tag_fname><NUL><NUL><lbuf>
* without Emacs tags: <mtt><tag_fname><NUL><lbuf>
* Here <mtt> is the "mtt" value plus 1 to avoid NUL.
*/
// Save the tag in a buffer.
// Use 0x01 to separate fields (Can't use NUL, because the
// hash key is terminated by NUL).
// Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf>
// other tag: <mtt><tag_fname><NUL><NUL><lbuf>
// without Emacs tags: <mtt><tag_fname><NUL><lbuf>
// Here <mtt> is the "mtt" value plus 1 to avoid NUL.
len = (int)tag_fname_len + (int)STRLEN(lbuf) + 3;
mfp = xmalloc(sizeof(char_u) + len + 1);
p = mfp;
p[0] = mtt + 1;
STRCPY(p + 1, tag_fname);
#ifdef BACKSLASH_IN_FILENAME
/* Ignore differences in slashes, avoid adding
* both path/file and path\file. */
// Ignore differences in slashes, avoid adding
// both path/file and path\file.
slash_adjust(p + 1);
#endif
p[tag_fname_len + 1] = TAG_SEP;
@ -1881,10 +1879,11 @@ parse_line:
// the part matters for comparing, more bytes may follow
// after it. E.g. help tags store the priority after the
// NUL.
if (use_cscope)
if (use_cscope) {
hash++;
else
} else {
hash = hash_hash(mfp);
}
hi = hash_lookup(&ht_match[mtt], (const char *)mfp,
STRLEN(mfp), hash);
if (HASHITEM_EMPTY(hi)) {
@ -1892,10 +1891,11 @@ parse_line:
ga_grow(&ga_match[mtt], 1);
((char_u **)(ga_match[mtt].ga_data))
[ga_match[mtt].ga_len++] = mfp;
++match_count;
} else
match_count++;
} else {
// duplicate tag, drop it
xfree(mfp);
}
}
}
if (use_cscope && eof)
@ -1969,7 +1969,7 @@ findtag_end:
else
matches = NULL;
match_count = 0;
for (mtt = 0; mtt < MT_COUNT; ++mtt) {
for (mtt = 0; mtt < MT_COUNT; mtt++) {
for (i = 0; i < ga_match[mtt].ga_len; i++) {
mfp = ((char_u **)(ga_match[mtt].ga_data))[i];
if (matches == NULL) {