vim-patch:8.0.0733: can only add entries to one list in the quickfix stack

Problem:    Can only add entries to one list in the quickfix stack.
Solution:   Move state variables from qf_list_T to qf_list_T. (Yegappan
            Lakshmanan)
a7df8c70c8
This commit is contained in:
Jan Edmund Lazo
2018-09-05 22:17:35 -04:00
parent 5de6f97408
commit bb519fb261

View File

@@ -91,6 +91,14 @@ typedef struct qf_list_S {
char_u *qf_title; ///< title derived from the command that created
///< the error list or set by setqflist
typval_T *qf_ctx; ///< context set by setqflist/setloclist
struct dir_stack_T *qf_dir_stack;
char_u *qf_directory;
struct dir_stack_T *qf_file_stack;
char_u *qf_currfile;
bool qf_multiline;
bool qf_multiignore;
bool qf_multiscan;
} qf_list_T;
/// Quickfix/Location list stack definition
@@ -106,15 +114,6 @@ struct qf_info_S {
int qf_listcount; /* current number of lists */
int qf_curlist; /* current error list */
qf_list_T qf_lists[LISTCOUNT];
int qf_dir_curlist; ///< error list for qf_dir_stack
struct dir_stack_T *qf_dir_stack;
char_u *qf_directory;
struct dir_stack_T *qf_file_stack;
char_u *qf_currfile;
bool qf_multiline;
bool qf_multiignore;
bool qf_multiscan;
};
static qf_info_T ql_info; /* global quickfix list */
@@ -223,9 +222,8 @@ int qf_init(win_T *wp, char_u *efile, char_u *errorformat, int newlist,
qi = ll_get_or_alloc_list(wp);
}
return qf_init_ext(qi, efile, curbuf, NULL, errorformat, newlist,
(linenr_T)0, (linenr_T)0,
qf_title, enc);
return qf_init_ext(qi, qi->qf_curlist, efile, curbuf, NULL, errorformat,
newlist, (linenr_T)0, (linenr_T)0, qf_title, enc);
}
// Maximum number of bytes allowed per line while reading an errorfile.
@@ -712,8 +710,8 @@ static int qf_get_nextline(qfstate_T *state)
/// Parse a line and get the quickfix fields.
/// Return the QF_ status.
static int qf_parse_line(qf_info_T *qi, char_u *linebuf, size_t linelen,
efm_T *fmt_first, qffields_T *fields)
static int qf_parse_line(qf_info_T *qi, int qf_idx, char_u *linebuf,
size_t linelen, efm_T *fmt_first, qffields_T *fields)
{
efm_T *fmt_ptr;
size_t len;
@@ -721,7 +719,7 @@ static int qf_parse_line(qf_info_T *qi, char_u *linebuf, size_t linelen,
int idx = 0;
char_u *tail = NULL;
regmatch_T regmatch;
qf_list_T *qfl = &qi->qf_lists[qf_idx];
// Always ignore case when looking for a matching error.
regmatch.rm_ic = true;
@@ -740,12 +738,12 @@ static int qf_parse_line(qf_info_T *qi, char_u *linebuf, size_t linelen,
restofline:
for (; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) {
idx = fmt_ptr->prefix;
if (qi->qf_multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL) {
if (qfl->qf_multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL) {
continue;
}
fields->namebuf[0] = NUL;
fields->pattern[0] = NUL;
if (!qi->qf_multiscan) {
if (!qfl->qf_multiscan) {
fields->errmsg[0] = NUL;
}
fields->lnum = 0;
@@ -759,7 +757,7 @@ restofline:
int r = vim_regexec(&regmatch, linebuf, (colnr_T)0);
fmt_ptr->prog = regmatch.regprog;
if (r) {
if ((idx == 'C' || idx == 'Z') && !qi->qf_multiline) {
if ((idx == 'C' || idx == 'Z') && !qfl->qf_multiline) {
continue;
}
if (vim_strchr((char_u *)"EWI", idx) != NULL) {
@@ -809,7 +807,7 @@ restofline:
}
fields->type = *regmatch.startp[i];
}
if (fmt_ptr->flags == '+' && !qi->qf_multiscan) { // %+
if (fmt_ptr->flags == '+' && !qfl->qf_multiscan) { // %+
if (linelen >= fields->errmsglen) {
// linelen + null terminator
fields->errmsg = xrealloc(fields->errmsg, linelen + 1);
@@ -877,7 +875,7 @@ restofline:
break;
}
}
qi->qf_multiscan = false;
qfl->qf_multiscan = false;
if (fmt_ptr == NULL || idx == 'D' || idx == 'X') {
if (fmt_ptr != NULL) {
@@ -886,13 +884,13 @@ restofline:
EMSG(_("E379: Missing or empty directory name"));
return QF_FAIL;
}
qi->qf_directory = qf_push_dir(fields->namebuf, &qi->qf_dir_stack,
false);
if (qi->qf_directory == NULL) {
qfl->qf_directory = qf_push_dir(fields->namebuf, &qfl->qf_dir_stack,
false);
if (qfl->qf_directory == NULL) {
return QF_FAIL;
}
} else if (idx == 'X') { // leave directory
qi->qf_directory = qf_pop_dir(&qi->qf_dir_stack);
qfl->qf_directory = qf_pop_dir(&qfl->qf_dir_stack);
}
}
fields->namebuf[0] = NUL; // no match found, remove file name
@@ -906,7 +904,7 @@ restofline:
// copy whole line to error message
STRLCPY(fields->errmsg, linebuf, linelen + 1);
if (fmt_ptr == NULL) {
qi->qf_multiline = qi->qf_multiignore = false;
qfl->qf_multiline = qfl->qf_multiignore = false;
}
} else {
// honor %> item
@@ -915,12 +913,12 @@ restofline:
}
if (vim_strchr((char_u *)"AEWI", idx) != NULL) {
qi->qf_multiline = true; // start of a multi-line message
qi->qf_multiignore = false; // reset continuation
qfl->qf_multiline = true; // start of a multi-line message
qfl->qf_multiignore = false; // reset continuation
} else if (vim_strchr((char_u *)"CZ", idx)
!= NULL) { // continuation of multi-line msg
if (!qi->qf_multiignore) {
qfline_T *qfprev = qi->qf_lists[qi->qf_curlist].qf_last;
if (!qfl->qf_multiignore) {
qfline_T *qfprev = qfl->qf_last;
if (qfprev == NULL) {
return QF_FAIL;
}
@@ -945,15 +943,15 @@ restofline:
}
qfprev->qf_viscol = fields->use_viscol;
if (!qfprev->qf_fnum) {
qfprev->qf_fnum = qf_get_fnum(qi, qi->qf_directory,
*fields->namebuf || qi->qf_directory
qfprev->qf_fnum = qf_get_fnum(qi, qf_idx, qfl->qf_directory,
*fields->namebuf || qfl->qf_directory
? fields->namebuf
: qi->qf_currfile && fields->valid
? qi->qf_currfile : 0);
: qfl->qf_currfile && fields->valid
? qfl->qf_currfile : 0);
}
}
if (idx == 'Z') {
qi->qf_multiline = qi->qf_multiignore = false;
qfl->qf_multiline = qfl->qf_multiignore = false;
}
line_breakcheck();
@@ -963,23 +961,23 @@ restofline:
fields->valid = false;
if (*fields->namebuf == NUL || os_path_exists(fields->namebuf)) {
if (*fields->namebuf && idx == 'P') {
qi->qf_currfile = qf_push_dir(fields->namebuf, &qi->qf_file_stack,
true);
qfl->qf_currfile = qf_push_dir(fields->namebuf, &qfl->qf_file_stack,
true);
} else if (idx == 'Q') {
qi->qf_currfile = qf_pop_dir(&qi->qf_file_stack);
qfl->qf_currfile = qf_pop_dir(&qfl->qf_file_stack);
}
*fields->namebuf = NUL;
if (tail && *tail) {
STRMOVE(IObuff, skipwhite(tail));
qi->qf_multiscan = true;
qfl->qf_multiscan = true;
goto restofline;
}
}
}
if (fmt_ptr->flags == '-') { // generally exclude this line
if (qi->qf_multiline) {
if (qfl->qf_multiline) {
// also exclude continuation lines
qi->qf_multiignore = true;
qfl->qf_multiignore = true;
}
return QF_IGNORE_LINE;
}
@@ -999,6 +997,7 @@ restofline:
static int
qf_init_ext(
qf_info_T *qi,
int qf_idx,
char_u *efile,
buf_T *buf,
typval_T *tv,
@@ -1041,17 +1040,20 @@ qf_init_ext(
goto qf_init_end;
}
if (newlist || qi->qf_curlist == qi->qf_listcount) {
if (newlist || qf_idx == qi->qf_listcount) {
// make place for a new list
qf_new_list(qi, qf_title);
qf_idx = qi->qf_curlist;
} else {
// Adding to existing list, use last entry.
adding = true;
if (qi->qf_lists[qi->qf_curlist].qf_count > 0) {
old_last = qi->qf_lists[qi->qf_curlist].qf_last;
if (qi->qf_lists[qf_idx].qf_count > 0) {
old_last = qi->qf_lists[qf_idx].qf_last;
}
}
qf_list_T *qfl = &qi->qf_lists[qf_idx];
// Use the local value of 'errorformat' if it's set.
if (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL) {
efm = buf->b_p_efm;
@@ -1059,18 +1061,6 @@ qf_init_ext(
efm = errorformat;
}
// If we are not adding or adding to another list: clear the state.
if (newlist || qi->qf_curlist != qi->qf_dir_curlist) {
qi->qf_dir_curlist = qi->qf_curlist;
qf_clean_dir_stack(&qi->qf_dir_stack);
qi->qf_directory = NULL;
qf_clean_dir_stack(&qi->qf_file_stack);
qi->qf_currfile = NULL;
qi->qf_multiline = false;
qi->qf_multiignore = false;
qi->qf_multiscan = false;
}
// If the errorformat didn't change between calls, then reuse the previously
// parsed values.
if (last_efm == NULL || (STRCMP(last_efm, efm) != 0)) {
@@ -1120,8 +1110,8 @@ qf_init_ext(
break;
}
status = qf_parse_line(qi, state.linebuf, state.linelen, fmt_first,
&fields);
status = qf_parse_line(qi, qf_idx, state.linebuf, state.linelen,
fmt_first, &fields);
if (status == QF_FAIL) {
goto error2;
}
@@ -1130,11 +1120,11 @@ qf_init_ext(
}
if (qf_add_entry(qi,
qi->qf_curlist,
qi->qf_directory,
(*fields.namebuf || qi->qf_directory)
? fields.namebuf : ((qi->qf_currfile && fields.valid)
? qi->qf_currfile : (char_u *)NULL),
qf_idx,
qfl->qf_directory,
(*fields.namebuf || qfl->qf_directory)
? fields.namebuf : ((qfl->qf_currfile && fields.valid)
? qfl->qf_currfile : (char_u *)NULL),
0,
fields.errmsg,
fields.lnum,
@@ -1149,25 +1139,25 @@ qf_init_ext(
line_breakcheck();
}
if (state.fd == NULL || !ferror(state.fd)) {
if (qi->qf_lists[qi->qf_curlist].qf_index == 0) {
if (qfl->qf_index == 0) {
/* no valid entry found */
qi->qf_lists[qi->qf_curlist].qf_ptr =
qi->qf_lists[qi->qf_curlist].qf_start;
qi->qf_lists[qi->qf_curlist].qf_index = 1;
qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE;
qfl->qf_ptr = qfl->qf_start;
qfl->qf_index = 1;
qfl->qf_nonevalid = true;
} else {
qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
if (qi->qf_lists[qi->qf_curlist].qf_ptr == NULL)
qi->qf_lists[qi->qf_curlist].qf_ptr =
qi->qf_lists[qi->qf_curlist].qf_start;
qfl->qf_nonevalid = false;
if (qfl->qf_ptr == NULL) {
qfl->qf_ptr = qfl->qf_start;
}
}
/* return number of matches */
retval = qi->qf_lists[qi->qf_curlist].qf_count;
retval = qfl->qf_count;
goto qf_init_end;
}
EMSG(_(e_readerrf));
error2:
if (!adding) {
// Error when creating a new list. Free the new list
qf_free(qi, qi->qf_curlist);
qi->qf_listcount--;
if (qi->qf_curlist > 0) {
@@ -1183,7 +1173,9 @@ qf_init_end:
xfree(fields.pattern);
xfree(state.growbuf);
qf_update_buffer(qi, old_last);
if (qf_idx == qi->qf_curlist) {
qf_update_buffer(qi, old_last);
}
if (state.vc.vc_type != CONV_NONE) {
convert_setup(&state.vc, NULL, NULL);
@@ -1305,7 +1297,7 @@ static int qf_add_entry(qf_info_T *qi, int qf_idx, char_u *dir, char_u *fname,
(qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
}
} else {
qfp->qf_fnum = qf_get_fnum(qi, dir, fname);
qfp->qf_fnum = qf_get_fnum(qi, qf_idx, dir, fname);
}
qfp->qf_text = vim_strsave(mesg);
qfp->qf_lnum = lnum;
@@ -1488,7 +1480,8 @@ void copy_loclist(win_T *from, win_T *to)
// Get buffer number for file "directory/fname".
// Also sets the b_has_qf_entry flag.
static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname)
static int qf_get_fnum(qf_info_T *qi, int qf_idx, char_u *directory,
char_u *fname)
{
char_u *ptr = NULL;
char_u *bufname;
@@ -1511,7 +1504,7 @@ static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname)
// directory change.
if (!os_path_exists(ptr)) {
xfree(ptr);
directory = qf_guess_filepath(qi, fname);
directory = qf_guess_filepath(qi, qf_idx, fname);
if (directory) {
ptr = (char_u *)concat_fnames((char *)directory, (char *)fname, true);
} else {
@@ -1661,18 +1654,19 @@ static void qf_clean_dir_stack(struct dir_stack_T **stackptr)
* Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb.
* qf_guess_filepath will return NULL.
*/
static char_u *qf_guess_filepath(qf_info_T *qi, char_u *filename)
static char_u *qf_guess_filepath(qf_info_T *qi, int qf_idx, char_u *filename)
{
struct dir_stack_T *ds_ptr;
struct dir_stack_T *ds_tmp;
char_u *fullname;
qf_list_T *qfl = &qi->qf_lists[qf_idx];
// no dirs on the stack - there's nothing we can do
if (qi->qf_dir_stack == NULL) {
if (qfl->qf_dir_stack == NULL) {
return NULL;
}
ds_ptr = qi->qf_dir_stack->next;
ds_ptr = qfl->qf_dir_stack->next;
fullname = NULL;
while (ds_ptr) {
xfree(fullname);
@@ -1688,9 +1682,9 @@ static char_u *qf_guess_filepath(qf_info_T *qi, char_u *filename)
xfree(fullname);
// clean up all dirs we already left
while (qi->qf_dir_stack->next != ds_ptr) {
ds_tmp = qi->qf_dir_stack->next;
qi->qf_dir_stack->next = qi->qf_dir_stack->next->next;
while (qfl->qf_dir_stack->next != ds_ptr) {
ds_tmp = qfl->qf_dir_stack->next;
qfl->qf_dir_stack->next = qfl->qf_dir_stack->next->next;
xfree(ds_tmp->dirname);
xfree(ds_tmp);
}
@@ -2415,11 +2409,12 @@ static void qf_free_items(qf_info_T *qi, int idx)
qfline_T *qfp;
qfline_T *qfpnext;
bool stop = false;
qf_list_T *qfl = &qi->qf_lists[idx];
while (qi->qf_lists[idx].qf_count && qi->qf_lists[idx].qf_start != NULL) {
qfp = qi->qf_lists[idx].qf_start;
while (qfl->qf_count && qfl->qf_start != NULL) {
qfp = qfl->qf_start;
qfpnext = qfp->qf_next;
if (qi->qf_lists[idx].qf_title != NULL && !stop) {
if (qfl->qf_title != NULL && !stop) {
xfree(qfp->qf_text);
stop = (qfp == qfpnext);
xfree(qfp->qf_pattern);
@@ -2428,40 +2423,41 @@ static void qf_free_items(qf_info_T *qi, int idx)
// Somehow qf_count may have an incorrect value, set it to 1
// to avoid crashing when it's wrong.
// TODO(vim): Avoid qf_count being incorrect.
qi->qf_lists[idx].qf_count = 1;
qfl->qf_count = 1;
}
}
qi->qf_lists[idx].qf_start = qfpnext;
qi->qf_lists[idx].qf_count--;
qfl->qf_start = qfpnext;
qfl->qf_count--;
}
qi->qf_lists[idx].qf_start = NULL;
qi->qf_lists[idx].qf_ptr = NULL;
qi->qf_lists[idx].qf_index = 0;
qi->qf_lists[idx].qf_start = NULL;
qi->qf_lists[idx].qf_last = NULL;
qi->qf_lists[idx].qf_ptr = NULL;
qi->qf_lists[idx].qf_nonevalid = true;
qfl->qf_start = NULL;
qfl->qf_ptr = NULL;
qfl->qf_index = 0;
qfl->qf_start = NULL;
qfl->qf_last = NULL;
qfl->qf_ptr = NULL;
qfl->qf_nonevalid = true;
qf_clean_dir_stack(&qi->qf_dir_stack);
qi->qf_directory = NULL;
qf_clean_dir_stack(&qi->qf_file_stack);
qi->qf_currfile = NULL;
qi->qf_multiline = false;
qi->qf_multiignore = false;
qi->qf_multiscan = false;
qf_clean_dir_stack(&qfl->qf_dir_stack);
qfl->qf_directory = NULL;
qf_clean_dir_stack(&qfl->qf_file_stack);
qfl->qf_currfile = NULL;
qfl->qf_multiline = false;
qfl->qf_multiignore = false;
qfl->qf_multiscan = false;
}
/// Free error list "idx". Frees all the entries in the quickfix list,
/// associated context information and the title.
static void qf_free(qf_info_T *qi, int idx)
{
qf_list_T *qfl = &qi->qf_lists[idx];
qf_free_items(qi, idx);
xfree(qi->qf_lists[idx].qf_title);
qi->qf_lists[idx].qf_title = NULL;
tv_free(qi->qf_lists[idx].qf_ctx);
qi->qf_lists[idx].qf_ctx = NULL;
xfree(qfl->qf_title);
qfl->qf_title = NULL;
tv_free(qfl->qf_ctx);
qfl->qf_ctx = NULL;
}
/*
@@ -4603,7 +4599,7 @@ void ex_cbuffer(exarg_T *eap)
qf_title = IObuff;
}
if (qf_init_ext(qi, NULL, buf, NULL, p_efm,
if (qf_init_ext(qi, qi->qf_curlist, NULL, buf, NULL, p_efm,
(eap->cmdidx != CMD_caddbuffer
&& eap->cmdidx != CMD_laddbuffer),
eap->line1, eap->line2, qf_title, NULL) > 0) {
@@ -4668,7 +4664,7 @@ void ex_cexpr(exarg_T *eap)
if (eval0(eap->arg, &tv, NULL, true) != FAIL) {
if ((tv.v_type == VAR_STRING && tv.vval.v_string != NULL)
|| tv.v_type == VAR_LIST) {
if (qf_init_ext(qi, NULL, NULL, &tv, p_efm,
if (qf_init_ext(qi, qi->qf_curlist, NULL, NULL, &tv, p_efm,
(eap->cmdidx != CMD_caddexpr
&& eap->cmdidx != CMD_laddexpr),
(linenr_T)0, (linenr_T)0, *eap->cmdlinep, NULL) > 0) {