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