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:
147
src/quickfix.c
147
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
|
static char_u *
|
||||||
efm_to_regpat(
|
fmtpat_to_regpat(
|
||||||
char_u *efm,
|
char_u *efmp,
|
||||||
int len,
|
|
||||||
efm_T *fmt_ptr,
|
efm_T *fmt_ptr,
|
||||||
char_u *regpat,
|
int idx,
|
||||||
|
int round,
|
||||||
|
char_u *ptr,
|
||||||
char_u *errmsg)
|
char_u *errmsg)
|
||||||
{
|
{
|
||||||
char_u *ptr;
|
|
||||||
char_u *efmp;
|
|
||||||
char_u *srcptr;
|
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])
|
if (fmt_ptr->addr[idx])
|
||||||
{
|
{
|
||||||
|
/* Each errorformat pattern can occur only once */
|
||||||
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);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ((idx
|
if ((idx && idx < 6
|
||||||
&& idx < 6
|
&& vim_strchr((char_u *)"DXOPQ", fmt_ptr->prefix) != NULL)
|
||||||
&& vim_strchr((char_u *)"DXOPQ",
|
|
||||||
fmt_ptr->prefix) != NULL)
|
|
||||||
|| (idx == 6
|
|| (idx == 6
|
||||||
&& vim_strchr((char_u *)"OPQ",
|
&& vim_strchr((char_u *)"OPQ", fmt_ptr->prefix) == NULL))
|
||||||
fmt_ptr->prefix) == NULL))
|
|
||||||
{
|
{
|
||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E373: Unexpected %%%c in format string"), *efmp);
|
_("E373: Unexpected %%%c in format string"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
fmt_ptr->addr[idx] = (char_u)++round;
|
fmt_ptr->addr[idx] = (char_u)++round;
|
||||||
*ptr++ = '\\';
|
*ptr++ = '\\';
|
||||||
@@ -321,9 +301,23 @@ efm_to_regpat(
|
|||||||
}
|
}
|
||||||
*ptr++ = '\\';
|
*ptr++ = '\\';
|
||||||
*ptr++ = ')';
|
*ptr++ = ')';
|
||||||
|
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
else if (*efmp == '*')
|
|
||||||
|
/*
|
||||||
|
* 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 (*++efmp == '[' || *efmp == '\\')
|
||||||
{
|
{
|
||||||
if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */
|
if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */
|
||||||
@@ -339,7 +333,7 @@ efm_to_regpat(
|
|||||||
if (efmp == efm + len)
|
if (efmp == efm + len)
|
||||||
{
|
{
|
||||||
EMSG(_("E374: Missing ] in format string"));
|
EMSG(_("E374: Missing ] in format string"));
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,17 +348,22 @@ efm_to_regpat(
|
|||||||
sprintf((char *)errmsg,
|
sprintf((char *)errmsg,
|
||||||
_("E375: Unsupported %%%c in format string"), *efmp);
|
_("E375: Unsupported %%%c in format string"), *efmp);
|
||||||
EMSG(errmsg);
|
EMSG(errmsg);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*pefmp = efmp;
|
||||||
|
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
|
|
||||||
*ptr++ = *efmp; /* regexp magic characters */
|
/*
|
||||||
else if (*efmp == '#')
|
* Analyze/parse an errorformat prefix.
|
||||||
*ptr++ = '*';
|
*/
|
||||||
else if (*efmp == '>')
|
static int
|
||||||
fmt_ptr->conthere = TRUE;
|
efm_analyze_prefix(char_u **pefmp, efm_T *fmt_ptr, char_u *errmsg)
|
||||||
else if (efmp == efm + 1) /* analyse prefix */
|
|
||||||
{
|
{
|
||||||
|
char_u *efmp = *pefmp;
|
||||||
|
|
||||||
if (vim_strchr((char_u *)"+-", *efmp) != NULL)
|
if (vim_strchr((char_u *)"+-", *efmp) != NULL)
|
||||||
fmt_ptr->flags = *efmp++;
|
fmt_ptr->flags = *efmp++;
|
||||||
if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL)
|
if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL)
|
||||||
@@ -374,8 +373,68 @@ efm_to_regpat(
|
|||||||
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);
|
||||||
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@@ -761,6 +761,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 */
|
||||||
|
/**/
|
||||||
|
10,
|
||||||
/**/
|
/**/
|
||||||
9,
|
9,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user