mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.1.0010: efm_to_regpat() is too long
Problem: efm_to_regpat() is too long. Solution: Split off three functions. (Yegappan Lakshmanan, closes #2924)
This commit is contained in:
155
src/quickfix.c
155
src/quickfix.c
@@ -228,57 +228,37 @@ static struct fmtpattern
|
||||
};
|
||||
|
||||
/*
|
||||
* Converts a 'errorformat' string to regular expression pattern
|
||||
* Convert an errorformat pattern to a regular expression pattern.
|
||||
* See fmt_pat definition above for the list of supported patterns.
|
||||
*/
|
||||
static int
|
||||
efm_to_regpat(
|
||||
char_u *efm,
|
||||
int len,
|
||||
static char_u *
|
||||
fmtpat_to_regpat(
|
||||
char_u *efmp,
|
||||
efm_T *fmt_ptr,
|
||||
char_u *regpat,
|
||||
int idx,
|
||||
int round,
|
||||
char_u *ptr,
|
||||
char_u *errmsg)
|
||||
{
|
||||
char_u *ptr;
|
||||
char_u *efmp;
|
||||
char_u *srcptr;
|
||||
int round;
|
||||
int idx = 0;
|
||||
|
||||
/*
|
||||
* Build regexp pattern from current 'errorformat' option
|
||||
*/
|
||||
ptr = regpat;
|
||||
*ptr++ = '^';
|
||||
round = 0;
|
||||
for (efmp = efm; efmp < efm + len; ++efmp)
|
||||
{
|
||||
if (*efmp == '%')
|
||||
{
|
||||
++efmp;
|
||||
for (idx = 0; idx < FMT_PATTERNS; ++idx)
|
||||
if (fmt_pat[idx].convchar == *efmp)
|
||||
break;
|
||||
if (idx < FMT_PATTERNS)
|
||||
{
|
||||
if (fmt_ptr->addr[idx])
|
||||
{
|
||||
/* Each errorformat pattern can occur only once */
|
||||
sprintf((char *)errmsg,
|
||||
_("E372: Too many %%%c in format string"), *efmp);
|
||||
EMSG(errmsg);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
if ((idx
|
||||
&& idx < 6
|
||||
&& vim_strchr((char_u *)"DXOPQ",
|
||||
fmt_ptr->prefix) != NULL)
|
||||
if ((idx && idx < 6
|
||||
&& vim_strchr((char_u *)"DXOPQ", fmt_ptr->prefix) != NULL)
|
||||
|| (idx == 6
|
||||
&& vim_strchr((char_u *)"OPQ",
|
||||
fmt_ptr->prefix) == NULL))
|
||||
&& vim_strchr((char_u *)"OPQ", fmt_ptr->prefix) == NULL))
|
||||
{
|
||||
sprintf((char *)errmsg,
|
||||
_("E373: Unexpected %%%c in format string"), *efmp);
|
||||
EMSG(errmsg);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
fmt_ptr->addr[idx] = (char_u)++round;
|
||||
*ptr++ = '\\';
|
||||
@@ -321,9 +301,23 @@ efm_to_regpat(
|
||||
}
|
||||
*ptr++ = '\\';
|
||||
*ptr++ = ')';
|
||||
}
|
||||
else if (*efmp == '*')
|
||||
{
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a scanf like format in 'errorformat' to a regular expression.
|
||||
*/
|
||||
static char_u *
|
||||
scanf_fmt_to_regpat(
|
||||
char_u *efm,
|
||||
int len,
|
||||
char_u **pefmp,
|
||||
char_u *ptr,
|
||||
char_u *errmsg)
|
||||
{
|
||||
char_u *efmp = *pefmp;
|
||||
|
||||
if (*++efmp == '[' || *efmp == '\\')
|
||||
{
|
||||
if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */
|
||||
@@ -339,7 +333,7 @@ efm_to_regpat(
|
||||
if (efmp == efm + len)
|
||||
{
|
||||
EMSG(_("E374: Missing ] in format string"));
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,17 +348,22 @@ efm_to_regpat(
|
||||
sprintf((char *)errmsg,
|
||||
_("E375: Unsupported %%%c in format string"), *efmp);
|
||||
EMSG(errmsg);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
|
||||
*ptr++ = *efmp; /* regexp magic characters */
|
||||
else if (*efmp == '#')
|
||||
*ptr++ = '*';
|
||||
else if (*efmp == '>')
|
||||
fmt_ptr->conthere = TRUE;
|
||||
else if (efmp == efm + 1) /* analyse prefix */
|
||||
{
|
||||
|
||||
*pefmp = efmp;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Analyze/parse an errorformat prefix.
|
||||
*/
|
||||
static int
|
||||
efm_analyze_prefix(char_u **pefmp, efm_T *fmt_ptr, char_u *errmsg)
|
||||
{
|
||||
char_u *efmp = *pefmp;
|
||||
|
||||
if (vim_strchr((char_u *)"+-", *efmp) != NULL)
|
||||
fmt_ptr->flags = *efmp++;
|
||||
if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL)
|
||||
@@ -374,8 +373,68 @@ efm_to_regpat(
|
||||
sprintf((char *)errmsg,
|
||||
_("E376: Invalid %%%c in format string prefix"), *efmp);
|
||||
EMSG(errmsg);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
*pefmp = efmp;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts a 'errorformat' string to regular expression pattern
|
||||
*/
|
||||
static int
|
||||
efm_to_regpat(
|
||||
char_u *efm,
|
||||
int len,
|
||||
efm_T *fmt_ptr,
|
||||
char_u *regpat,
|
||||
char_u *errmsg)
|
||||
{
|
||||
char_u *ptr;
|
||||
char_u *efmp;
|
||||
int round;
|
||||
int idx = 0;
|
||||
|
||||
/*
|
||||
* Build regexp pattern from current 'errorformat' option
|
||||
*/
|
||||
ptr = regpat;
|
||||
*ptr++ = '^';
|
||||
round = 0;
|
||||
for (efmp = efm; efmp < efm + len; ++efmp)
|
||||
{
|
||||
if (*efmp == '%')
|
||||
{
|
||||
++efmp;
|
||||
for (idx = 0; idx < FMT_PATTERNS; ++idx)
|
||||
if (fmt_pat[idx].convchar == *efmp)
|
||||
break;
|
||||
if (idx < FMT_PATTERNS)
|
||||
{
|
||||
ptr = fmtpat_to_regpat(efmp, fmt_ptr, idx, round, ptr,
|
||||
errmsg);
|
||||
if (ptr == NULL)
|
||||
return -1;
|
||||
round++;
|
||||
}
|
||||
else if (*efmp == '*')
|
||||
{
|
||||
ptr = scanf_fmt_to_regpat(efm, len, &efmp, ptr, errmsg);
|
||||
if (ptr == NULL)
|
||||
return -1;
|
||||
}
|
||||
else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
|
||||
*ptr++ = *efmp; /* regexp magic characters */
|
||||
else if (*efmp == '#')
|
||||
*ptr++ = '*';
|
||||
else if (*efmp == '>')
|
||||
fmt_ptr->conthere = TRUE;
|
||||
else if (efmp == efm + 1) /* analyse prefix */
|
||||
{
|
||||
if (efm_analyze_prefix(&efmp, fmt_ptr, errmsg) == FAIL)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
10,
|
||||
/**/
|
||||
9,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user