forked from aniani/vim
patch 7.4.1964
Problem: The quickfix init function is too big. Solution: Factor out parsing 'errorformat' to a separate function. (Yegappan Lakshmanan)
This commit is contained in:
362
src/quickfix.c
362
src/quickfix.c
@@ -205,74 +205,6 @@ qf_grow_linebuf(char_u **growbuf, int *growbufsiz, int newsz, int *allocsz)
|
|||||||
return *growbuf;
|
return *growbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the errorfile "efile" into memory, line by line, building the error
|
|
||||||
* list.
|
|
||||||
* Alternative: when "efile" is NULL read errors from buffer "buf".
|
|
||||||
* Alternative: when "tv" is not NULL get errors from the string or list.
|
|
||||||
* Always use 'errorformat' from "buf" if there is a local value.
|
|
||||||
* Then "lnumfirst" and "lnumlast" specify the range of lines to use.
|
|
||||||
* Set the title of the list to "qf_title".
|
|
||||||
* Return -1 for error, number of errors for success.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
qf_init_ext(
|
|
||||||
qf_info_T *qi,
|
|
||||||
char_u *efile,
|
|
||||||
buf_T *buf,
|
|
||||||
typval_T *tv,
|
|
||||||
char_u *errorformat,
|
|
||||||
int newlist, /* TRUE: start a new error list */
|
|
||||||
linenr_T lnumfirst, /* first line number to use */
|
|
||||||
linenr_T lnumlast, /* last line number to use */
|
|
||||||
char_u *qf_title)
|
|
||||||
{
|
|
||||||
char_u *namebuf;
|
|
||||||
char_u *errmsg;
|
|
||||||
int errmsglen;
|
|
||||||
char_u *pattern;
|
|
||||||
char_u *fmtstr = NULL;
|
|
||||||
char_u *growbuf = NULL;
|
|
||||||
int growbuflen;
|
|
||||||
int growbufsiz = 0;
|
|
||||||
char_u *linebuf = NULL;
|
|
||||||
int linelen = 0;
|
|
||||||
int discard;
|
|
||||||
int col = 0;
|
|
||||||
char_u use_viscol = FALSE;
|
|
||||||
int type = 0;
|
|
||||||
int valid;
|
|
||||||
linenr_T buflnum = lnumfirst;
|
|
||||||
long lnum = 0L;
|
|
||||||
int enr = 0;
|
|
||||||
FILE *fd = NULL;
|
|
||||||
#ifdef FEAT_WINDOWS
|
|
||||||
qfline_T *old_last = NULL;
|
|
||||||
#endif
|
|
||||||
char_u *efmp;
|
|
||||||
efm_T *fmt_first = NULL;
|
|
||||||
efm_T *fmt_last = NULL;
|
|
||||||
efm_T *fmt_ptr;
|
|
||||||
efm_T *fmt_start = NULL;
|
|
||||||
char_u *efm;
|
|
||||||
char_u *ptr;
|
|
||||||
char_u *srcptr;
|
|
||||||
int len;
|
|
||||||
int i;
|
|
||||||
int round;
|
|
||||||
int idx = 0;
|
|
||||||
int multiline = FALSE;
|
|
||||||
int multiignore = FALSE;
|
|
||||||
int multiscan = FALSE;
|
|
||||||
int retval = -1; /* default: return error flag */
|
|
||||||
char_u *directory = NULL;
|
|
||||||
char_u *currfile = NULL;
|
|
||||||
char_u *tail = NULL;
|
|
||||||
char_u *p_buf = NULL;
|
|
||||||
char_u *p_str = NULL;
|
|
||||||
listitem_T *p_li = NULL;
|
|
||||||
struct dir_stack_T *file_stack = NULL;
|
|
||||||
regmatch_T regmatch;
|
|
||||||
static struct fmtpattern
|
static struct fmtpattern
|
||||||
{
|
{
|
||||||
char_u convchar;
|
char_u convchar;
|
||||||
@@ -291,78 +223,27 @@ qf_init_ext(
|
|||||||
{'s', ".\\+"}
|
{'s', ".\\+"}
|
||||||
};
|
};
|
||||||
|
|
||||||
namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf);
|
/*
|
||||||
errmsglen = CMDBUFFSIZE + 1;
|
* Converts a 'errorformat' string to regular expression pattern
|
||||||
errmsg = alloc_id(errmsglen, aid_qf_errmsg);
|
*/
|
||||||
pattern = alloc_id(CMDBUFFSIZE + 1, aid_qf_pattern);
|
static int
|
||||||
if (namebuf == NULL || errmsg == NULL || pattern == NULL)
|
efm_to_regpat(
|
||||||
goto qf_init_end;
|
char_u *efm,
|
||||||
|
int len,
|
||||||
if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL)
|
efm_T *fmt_ptr,
|
||||||
|
char_u *regpat,
|
||||||
|
char_u *errmsg)
|
||||||
{
|
{
|
||||||
EMSG2(_(e_openerrf), efile);
|
char_u *ptr;
|
||||||
goto qf_init_end;
|
char_u *efmp;
|
||||||
}
|
char_u *srcptr;
|
||||||
|
int round;
|
||||||
if (newlist || qi->qf_curlist == qi->qf_listcount)
|
int idx = 0;
|
||||||
/* make place for a new list */
|
|
||||||
qf_new_list(qi, qf_title);
|
|
||||||
#ifdef FEAT_WINDOWS
|
|
||||||
else if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
|
|
||||||
{
|
|
||||||
/* Adding to existing list, use last entry. */
|
|
||||||
old_last = qi->qf_lists[qi->qf_curlist].qf_last;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Each part of the format string is copied and modified from errorformat to
|
|
||||||
* regex prog. Only a few % characters are allowed.
|
|
||||||
*/
|
|
||||||
/* Use the local value of 'errorformat' if it's set. */
|
|
||||||
if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL)
|
|
||||||
efm = buf->b_p_efm;
|
|
||||||
else
|
|
||||||
efm = errorformat;
|
|
||||||
/*
|
|
||||||
* Get some space to modify the format string into.
|
|
||||||
*/
|
|
||||||
i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2);
|
|
||||||
for (round = FMT_PATTERNS; round > 0; )
|
|
||||||
i += (int)STRLEN(fmt_pat[--round].pattern);
|
|
||||||
#ifdef COLON_IN_FILENAME
|
|
||||||
i += 12; /* "%f" can become twelve chars longer */
|
|
||||||
#else
|
|
||||||
i += 2; /* "%f" can become two chars longer */
|
|
||||||
#endif
|
|
||||||
if ((fmtstr = alloc(i)) == NULL)
|
|
||||||
goto error2;
|
|
||||||
|
|
||||||
while (efm[0] != NUL)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Allocate a new eformat structure and put it at the end of the list
|
|
||||||
*/
|
|
||||||
fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T));
|
|
||||||
if (fmt_ptr == NULL)
|
|
||||||
goto error2;
|
|
||||||
if (fmt_first == NULL) /* first one */
|
|
||||||
fmt_first = fmt_ptr;
|
|
||||||
else
|
|
||||||
fmt_last->next = fmt_ptr;
|
|
||||||
fmt_last = fmt_ptr;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Isolate one part in the 'errorformat' option
|
|
||||||
*/
|
|
||||||
for (len = 0; efm[len] != NUL && efm[len] != ','; ++len)
|
|
||||||
if (efm[len] == '\\' && efm[len + 1] != NUL)
|
|
||||||
++len;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build regexp pattern from current 'errorformat' option
|
* Build regexp pattern from current 'errorformat' option
|
||||||
*/
|
*/
|
||||||
ptr = fmtstr;
|
ptr = regpat;
|
||||||
*ptr++ = '^';
|
*ptr++ = '^';
|
||||||
round = 0;
|
round = 0;
|
||||||
for (efmp = efm; efmp < efm + len; ++efmp)
|
for (efmp = efm; efmp < efm + len; ++efmp)
|
||||||
@@ -380,7 +261,7 @@ qf_init_ext(
|
|||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E372: Too many %%%c in format string"), *efmp);
|
_("E372: Too many %%%c in format string"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
goto error2;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((idx
|
if ((idx
|
||||||
&& idx < 6
|
&& idx < 6
|
||||||
@@ -393,7 +274,7 @@ qf_init_ext(
|
|||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E373: Unexpected %%%c in format string"), *efmp);
|
_("E373: Unexpected %%%c in format string"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
goto error2;
|
return -1;
|
||||||
}
|
}
|
||||||
fmt_ptr->addr[idx] = (char_u)++round;
|
fmt_ptr->addr[idx] = (char_u)++round;
|
||||||
*ptr++ = '\\';
|
*ptr++ = '\\';
|
||||||
@@ -454,7 +335,7 @@ qf_init_ext(
|
|||||||
if (efmp == efm + len)
|
if (efmp == efm + len)
|
||||||
{
|
{
|
||||||
EMSG(_("E374: Missing ] in format string"));
|
EMSG(_("E374: Missing ] in format string"));
|
||||||
goto error2;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,7 +350,7 @@ qf_init_ext(
|
|||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E375: Unsupported %%%c in format string"), *efmp);
|
_("E375: Unsupported %%%c in format string"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
goto error2;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
|
else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
|
||||||
@@ -489,7 +370,7 @@ qf_init_ext(
|
|||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E376: Invalid %%%c in format string prefix"), *efmp);
|
_("E376: Invalid %%%c in format string prefix"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
goto error2;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -497,7 +378,7 @@ qf_init_ext(
|
|||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E377: Invalid %%%c in format string"), *efmp);
|
_("E377: Invalid %%%c in format string"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
goto error2;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* copy normal character */
|
else /* copy normal character */
|
||||||
@@ -512,19 +393,204 @@ qf_init_ext(
|
|||||||
}
|
}
|
||||||
*ptr++ = '$';
|
*ptr++ = '$';
|
||||||
*ptr = NUL;
|
*ptr = NUL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_efm_list(efm_T **efm_first)
|
||||||
|
{
|
||||||
|
efm_T *efm_ptr;
|
||||||
|
|
||||||
|
for (efm_ptr = *efm_first; efm_ptr != NULL; efm_ptr = *efm_first)
|
||||||
|
{
|
||||||
|
*efm_first = efm_ptr->next;
|
||||||
|
vim_regfree(efm_ptr->prog);
|
||||||
|
vim_free(efm_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse 'errorformat' option */
|
||||||
|
static efm_T *
|
||||||
|
parse_efm_option(char_u *efm)
|
||||||
|
{
|
||||||
|
char_u *errmsg = NULL;
|
||||||
|
int errmsglen;
|
||||||
|
efm_T *fmt_ptr = NULL;
|
||||||
|
efm_T *fmt_first = NULL;
|
||||||
|
efm_T *fmt_last = NULL;
|
||||||
|
char_u *fmtstr = NULL;
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
int round;
|
||||||
|
|
||||||
|
errmsglen = CMDBUFFSIZE + 1;
|
||||||
|
errmsg = alloc_id(errmsglen, aid_qf_errmsg);
|
||||||
|
if (errmsg == NULL)
|
||||||
|
goto parse_efm_end;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get some space to modify the format string into.
|
||||||
|
*/
|
||||||
|
i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2);
|
||||||
|
for (round = FMT_PATTERNS; round > 0; )
|
||||||
|
i += (int)STRLEN(fmt_pat[--round].pattern);
|
||||||
|
#ifdef COLON_IN_FILENAME
|
||||||
|
i += 12; /* "%f" can become twelve chars longer */
|
||||||
|
#else
|
||||||
|
i += 2; /* "%f" can become two chars longer */
|
||||||
|
#endif
|
||||||
|
if ((fmtstr = alloc(i)) == NULL)
|
||||||
|
goto parse_efm_error;
|
||||||
|
|
||||||
|
while (efm[0] != NUL)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Allocate a new eformat structure and put it at the end of the list
|
||||||
|
*/
|
||||||
|
fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T));
|
||||||
|
if (fmt_ptr == NULL)
|
||||||
|
goto parse_efm_error;
|
||||||
|
if (fmt_first == NULL) /* first one */
|
||||||
|
fmt_first = fmt_ptr;
|
||||||
|
else
|
||||||
|
fmt_last->next = fmt_ptr;
|
||||||
|
fmt_last = fmt_ptr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Isolate one part in the 'errorformat' option
|
||||||
|
*/
|
||||||
|
for (len = 0; efm[len] != NUL && efm[len] != ','; ++len)
|
||||||
|
if (efm[len] == '\\' && efm[len + 1] != NUL)
|
||||||
|
++len;
|
||||||
|
|
||||||
|
if (efm_to_regpat(efm, len, fmt_ptr, fmtstr, errmsg) == -1)
|
||||||
|
goto parse_efm_error;
|
||||||
if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL)
|
if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL)
|
||||||
goto error2;
|
goto parse_efm_error;
|
||||||
/*
|
/*
|
||||||
* Advance to next part
|
* Advance to next part
|
||||||
*/
|
*/
|
||||||
efm = skip_to_option_part(efm + len); /* skip comma and spaces */
|
efm = skip_to_option_part(efm + len); /* skip comma and spaces */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt_first == NULL) /* nothing found */
|
if (fmt_first == NULL) /* nothing found */
|
||||||
{
|
|
||||||
EMSG(_("E378: 'errorformat' contains no pattern"));
|
EMSG(_("E378: 'errorformat' contains no pattern"));
|
||||||
goto error2;
|
|
||||||
|
goto parse_efm_end;
|
||||||
|
|
||||||
|
parse_efm_error:
|
||||||
|
free_efm_list(&fmt_first);
|
||||||
|
|
||||||
|
parse_efm_end:
|
||||||
|
vim_free(fmtstr);
|
||||||
|
vim_free(errmsg);
|
||||||
|
|
||||||
|
return fmt_first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read the errorfile "efile" into memory, line by line, building the error
|
||||||
|
* list.
|
||||||
|
* Alternative: when "efile" is NULL read errors from buffer "buf".
|
||||||
|
* Alternative: when "tv" is not NULL get errors from the string or list.
|
||||||
|
* Always use 'errorformat' from "buf" if there is a local value.
|
||||||
|
* Then "lnumfirst" and "lnumlast" specify the range of lines to use.
|
||||||
|
* Set the title of the list to "qf_title".
|
||||||
|
* Return -1 for error, number of errors for success.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
qf_init_ext(
|
||||||
|
qf_info_T *qi,
|
||||||
|
char_u *efile,
|
||||||
|
buf_T *buf,
|
||||||
|
typval_T *tv,
|
||||||
|
char_u *errorformat,
|
||||||
|
int newlist, /* TRUE: start a new error list */
|
||||||
|
linenr_T lnumfirst, /* first line number to use */
|
||||||
|
linenr_T lnumlast, /* last line number to use */
|
||||||
|
char_u *qf_title)
|
||||||
|
{
|
||||||
|
char_u *namebuf;
|
||||||
|
char_u *errmsg;
|
||||||
|
int errmsglen;
|
||||||
|
char_u *pattern;
|
||||||
|
char_u *growbuf = NULL;
|
||||||
|
int growbuflen;
|
||||||
|
int growbufsiz = 0;
|
||||||
|
char_u *linebuf = NULL;
|
||||||
|
int linelen = 0;
|
||||||
|
int discard;
|
||||||
|
int col = 0;
|
||||||
|
char_u use_viscol = FALSE;
|
||||||
|
int type = 0;
|
||||||
|
int valid;
|
||||||
|
linenr_T buflnum = lnumfirst;
|
||||||
|
long lnum = 0L;
|
||||||
|
int enr = 0;
|
||||||
|
FILE *fd = NULL;
|
||||||
|
#ifdef FEAT_WINDOWS
|
||||||
|
qfline_T *old_last = NULL;
|
||||||
|
#endif
|
||||||
|
efm_T *fmt_first = NULL;
|
||||||
|
efm_T *fmt_ptr;
|
||||||
|
efm_T *fmt_start = NULL;
|
||||||
|
char_u *efm;
|
||||||
|
char_u *ptr;
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
int idx = 0;
|
||||||
|
int multiline = FALSE;
|
||||||
|
int multiignore = FALSE;
|
||||||
|
int multiscan = FALSE;
|
||||||
|
int retval = -1; /* default: return error flag */
|
||||||
|
char_u *directory = NULL;
|
||||||
|
char_u *currfile = NULL;
|
||||||
|
char_u *tail = NULL;
|
||||||
|
char_u *p_buf = NULL;
|
||||||
|
char_u *p_str = NULL;
|
||||||
|
listitem_T *p_li = NULL;
|
||||||
|
struct dir_stack_T *file_stack = NULL;
|
||||||
|
regmatch_T regmatch;
|
||||||
|
|
||||||
|
namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf);
|
||||||
|
errmsglen = CMDBUFFSIZE + 1;
|
||||||
|
errmsg = alloc_id(errmsglen, aid_qf_errmsg);
|
||||||
|
pattern = alloc_id(CMDBUFFSIZE + 1, aid_qf_pattern);
|
||||||
|
if (namebuf == NULL || errmsg == NULL || pattern == NULL)
|
||||||
|
goto qf_init_end;
|
||||||
|
|
||||||
|
if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL)
|
||||||
|
{
|
||||||
|
EMSG2(_(e_openerrf), efile);
|
||||||
|
goto qf_init_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newlist || qi->qf_curlist == qi->qf_listcount)
|
||||||
|
/* make place for a new list */
|
||||||
|
qf_new_list(qi, qf_title);
|
||||||
|
#ifdef FEAT_WINDOWS
|
||||||
|
else if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
|
||||||
|
{
|
||||||
|
/* Adding to existing list, use last entry. */
|
||||||
|
old_last = qi->qf_lists[qi->qf_curlist].qf_last;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Each part of the format string is copied and modified from errorformat to
|
||||||
|
* regex prog. Only a few % characters are allowed.
|
||||||
|
*/
|
||||||
|
/* Use the local value of 'errorformat' if it's set. */
|
||||||
|
if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL)
|
||||||
|
efm = buf->b_p_efm;
|
||||||
|
else
|
||||||
|
efm = errorformat;
|
||||||
|
|
||||||
|
fmt_first = parse_efm_option(efm);
|
||||||
|
if (fmt_first == NULL) /* nothing found */
|
||||||
|
goto error2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* got_int is reset here, because it was probably set when killing the
|
* got_int is reset here, because it was probably set when killing the
|
||||||
* ":make" command, but we still want to read the errorfile then.
|
* ":make" command, but we still want to read the errorfile then.
|
||||||
@@ -1046,19 +1112,13 @@ error2:
|
|||||||
qf_init_ok:
|
qf_init_ok:
|
||||||
if (fd != NULL)
|
if (fd != NULL)
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first)
|
free_efm_list(&fmt_first);
|
||||||
{
|
|
||||||
fmt_first = fmt_ptr->next;
|
|
||||||
vim_regfree(fmt_ptr->prog);
|
|
||||||
vim_free(fmt_ptr);
|
|
||||||
}
|
|
||||||
qf_clean_dir_stack(&dir_stack);
|
qf_clean_dir_stack(&dir_stack);
|
||||||
qf_clean_dir_stack(&file_stack);
|
qf_clean_dir_stack(&file_stack);
|
||||||
qf_init_end:
|
qf_init_end:
|
||||||
vim_free(namebuf);
|
vim_free(namebuf);
|
||||||
vim_free(errmsg);
|
vim_free(errmsg);
|
||||||
vim_free(pattern);
|
vim_free(pattern);
|
||||||
vim_free(fmtstr);
|
|
||||||
vim_free(growbuf);
|
vim_free(growbuf);
|
||||||
|
|
||||||
#ifdef FEAT_WINDOWS
|
#ifdef FEAT_WINDOWS
|
||||||
|
@@ -753,6 +753,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1964,
|
||||||
/**/
|
/**/
|
||||||
1963,
|
1963,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user