aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/regexp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r--src/nvim/regexp.c139
1 files changed, 71 insertions, 68 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 24dc86e034..bec3bc9648 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -461,15 +461,15 @@ static int toggle_Magic(int x)
*/
#define UCHARAT(p) ((int)*(char_u *)(p))
-/* Used for an error (down from) vim_regcomp(): give the error message, set
- * rc_did_emsg and return NULL */
-#define EMSG_RET_NULL(m) return (EMSG(m), rc_did_emsg = true, (void *)NULL)
-#define IEMSG_RET_NULL(m) return (IEMSG(m), rc_did_emsg = true, (void *)NULL)
-#define EMSG_RET_FAIL(m) return (EMSG(m), rc_did_emsg = true, FAIL)
+// Used for an error (down from) vim_regcomp(): give the error message, set
+// rc_did_emsg and return NULL
+#define EMSG_RET_NULL(m) return (emsg(m), rc_did_emsg = true, (void *)NULL)
+#define IEMSG_RET_NULL(m) return (iemsg(m), rc_did_emsg = true, (void *)NULL)
+#define EMSG_RET_FAIL(m) return (emsg(m), rc_did_emsg = true, FAIL)
#define EMSG2_RET_NULL(m, c) \
- return (EMSG2((m), (c) ? "" : "\\"), rc_did_emsg = true, (void *)NULL)
+ return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, (void *)NULL)
#define EMSG2_RET_FAIL(m, c) \
- return (EMSG2((m), (c) ? "" : "\\"), rc_did_emsg = true, FAIL)
+ return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, FAIL)
#define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_( \
"E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)
@@ -715,9 +715,9 @@ static int reg_magic; /* magicness of the pattern: */
#define MAGIC_ON 3 /* "\m" or 'magic' */
#define MAGIC_ALL 4 /* "\v" very magic */
-static int reg_string; /* matching with a string instead of a buffer
- line */
-static int reg_strict; /* "[abc" is illegal */
+static int reg_string; // matching with a string instead of a buffer
+ // line
+static int reg_strict; // "[abc" is illegal
/*
* META contains all characters that may be magic, except '^' and '$'.
@@ -741,10 +741,10 @@ static char_u META_flags[] = {
1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
};
-static int curchr; /* currently parsed character */
-/* Previous character. Note: prevchr is sometimes -1 when we are not at the
- * start, eg in /[ ^I]^ the pattern was never found even if it existed,
- * because ^ was taken to be magic -- webb */
+static int curchr; // currently parsed character
+// Previous character. Note: prevchr is sometimes -1 when we are not at the
+// start, eg in /[ ^I]^ the pattern was never found even if it existed,
+// because ^ was taken to be magic -- webb
static int prevchr;
static int prevprevchr; /* previous-previous character */
static int nextchr; /* used for ungetchr() */
@@ -783,7 +783,7 @@ static int get_equi_class(char_u **pp)
char_u *p = *pp;
if (p[1] == '=' && p[2] != NUL) {
- l = (*mb_ptr2len)(p + 2);
+ l = utfc_ptr2len(p + 2);
if (p[l + 2] == '=' && p[l + 3] == ']') {
c = utf_ptr2char(p + 2);
*pp += l + 4;
@@ -1144,7 +1144,7 @@ static char_u *skip_anyof(char_u *p)
if (*p == ']' || *p == '-')
++p;
while (*p != NUL && *p != ']') {
- if ((l = (*mb_ptr2len)(p)) > 1) {
+ if ((l = utfc_ptr2len(p)) > 1) {
p += l;
} else if (*p == '-') {
p++;
@@ -1237,7 +1237,7 @@ static int seen_endbrace(int refnum)
}
if (*p == NUL) {
- EMSG(_("E65: Illegal back reference"));
+ emsg(_("E65: Illegal back reference"));
rc_did_emsg = true;
return false;
}
@@ -1767,7 +1767,7 @@ static char_u *regpiece(int *flagp)
else
sprintf((char *)IObuff, _("E62: Nested %s%c"),
reg_magic == MAGIC_ALL ? "" : "\\", no_Magic(peekchr()));
- EMSG_RET_NULL(IObuff);
+ EMSG_RET_NULL((char *)IObuff);
}
return ret;
@@ -1929,7 +1929,7 @@ static char_u *regatom(int *flagp)
sprintf((char *)IObuff, _("E64: %s%c follows nothing"),
(c == '*' ? reg_magic >= MAGIC_ON : reg_magic == MAGIC_ALL)
? "" : "\\", c);
- EMSG_RET_NULL(IObuff);
+ EMSG_RET_NULL((char *)IObuff);
/* NOTREACHED */
case Magic('~'): /* previous substitute pattern */
@@ -2255,8 +2255,8 @@ collection:
if (startc > endc) {
EMSG_RET_NULL(_(e_reverse_range));
}
- if ((*mb_char2len)(startc) > 1
- || (*mb_char2len)(endc) > 1) {
+ if (utf_char2len(startc) > 1
+ || utf_char2len(endc) > 1) {
// Limit to a range of 256 chars
if (endc > startc + 256) {
EMSG_RET_NULL(_(e_large_class));
@@ -2509,8 +2509,9 @@ do_multibyte:
/* Need to get composing character too. */
for (;; ) {
l = utf_ptr2len(regparse);
- if (!UTF_COMPOSINGLIKE(regparse, regparse + l))
+ if (!utf_composinglike(regparse, regparse + l)) {
break;
+ }
regmbc(utf_ptr2char(regparse));
skipchr();
}
@@ -2835,21 +2836,22 @@ static int peekchr(void)
curchr = Magic(curchr);
break;
case '*':
- /* * is not magic as the very first character, eg "?*ptr", when
- * after '^', eg "/^*ptr" and when after "\(", "\|", "\&". But
- * "\(\*" is not magic, thus must be magic if "after_slash" */
+ // * is not magic as the very first character, eg "?*ptr", when
+ // after '^', eg "/^*ptr" and when after "\(", "\|", "\&". But
+ // "\(\*" is not magic, thus must be magic if "after_slash"
if (reg_magic >= MAGIC_ON
&& !at_start
&& !(prev_at_start && prevchr == Magic('^'))
&& (after_slash
|| (prevchr != Magic('(')
&& prevchr != Magic('&')
- && prevchr != Magic('|'))))
+ && prevchr != Magic('|')))) {
curchr = Magic('*');
+ }
break;
case '^':
- /* '^' is only magic as the very first character and if it's after
- * "\(", "\|", "\&' or "\n" */
+ // '^' is only magic as the very first character and if it's after
+ // "\(", "\|", "\&' or "\n"
if (reg_magic >= MAGIC_OFF
&& (at_start
|| reg_magic == MAGIC_ALL
@@ -2865,8 +2867,8 @@ static int peekchr(void)
}
break;
case '$':
- /* '$' is only magic as the very last char and if it's in front of
- * either "\|", "\)", "\&", or "\n" */
+ // '$' is only magic as the very last char and if it's in front of
+ // either "\|", "\)", "\&", or "\n"
if (reg_magic >= MAGIC_OFF) {
char_u *p = regparse + 1;
bool is_magic_all = (reg_magic == MAGIC_ALL);
@@ -3152,7 +3154,7 @@ static int read_limits(long *minval, long *maxval)
if (*regparse != '}') {
sprintf((char *)IObuff, _("E554: Syntax error in %s{...}"),
reg_magic == MAGIC_ALL ? "" : "\\");
- EMSG_RET_FAIL(IObuff);
+ EMSG_RET_FAIL((char *)IObuff);
}
/*
@@ -3482,7 +3484,7 @@ static long bt_regexec_both(char_u *line,
/* Be paranoid... */
if (prog == NULL || line == NULL) {
- IEMSG(_(e_null));
+ iemsg(_(e_null));
goto theend;
}
@@ -3584,7 +3586,7 @@ static long bt_regexec_both(char_u *line,
if (rex.line[col] == NUL) {
break;
}
- col += (*mb_ptr2len)(rex.line + col);
+ col += utfc_ptr2len(rex.line + col);
// Check for timeout once in a twenty times to avoid overhead.
if (tm != NULL && ++tm_count == 20) {
tm_count = 0;
@@ -4126,7 +4128,7 @@ static bool regmatch(
break;
case PRINT:
- if (!vim_isprintc(PTR2CHAR(rex.input))) {
+ if (!vim_isprintc(utf_ptr2char(rex.input))) {
status = RA_NOMATCH;
} else {
ADVANCE_REGINPUT();
@@ -4134,7 +4136,7 @@ static bool regmatch(
break;
case SPRINT:
- if (ascii_isdigit(*rex.input) || !vim_isprintc(PTR2CHAR(rex.input))) {
+ if (ascii_isdigit(*rex.input) || !vim_isprintc(utf_ptr2char(rex.input))) {
status = RA_NOMATCH;
} else {
ADVANCE_REGINPUT();
@@ -4293,7 +4295,7 @@ static bool regmatch(
// Check for following composing character, unless %C
// follows (skips over all composing chars).
if (status != RA_NOMATCH
- && UTF_COMPOSINGLIKE(rex.input, rex.input + len)
+ && utf_composinglike(rex.input, rex.input + len)
&& !rex.reg_icombine
&& OP(next) != RE_COMPOSING) {
// raaron: This code makes a composing character get
@@ -4325,7 +4327,7 @@ static bool regmatch(
const char_u *opnd = OPERAND(scan);
// Safety check (just in case 'encoding' was changed since
// compiling the program).
- if ((len = (*mb_ptr2len)(opnd)) < 2) {
+ if ((len = utfc_ptr2len(opnd)) < 2) {
status = RA_NOMATCH;
break;
}
@@ -4729,7 +4731,7 @@ static bool regmatch(
* follows. The code is below. Parameters are stored in
* a regstar_T on the regstack. */
if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) {
- EMSG(_(e_maxmempat));
+ emsg(_(e_maxmempat));
status = RA_FAIL;
} else {
ga_grow(&regstack, sizeof(regstar_T));
@@ -4767,7 +4769,7 @@ static bool regmatch(
case NOBEHIND:
/* Need a bit of room to store extra positions. */
if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) {
- EMSG(_(e_maxmempat));
+ emsg(_(e_maxmempat));
status = RA_FAIL;
} else {
ga_grow(&regstack, sizeof(regbehind_T));
@@ -4815,7 +4817,7 @@ static bool regmatch(
break;
default:
- IEMSG(_(e_re_corr));
+ iemsg(_(e_re_corr));
#ifdef REGEXP_DEBUG
printf("Illegal op code %d\n", op);
#endif
@@ -5173,7 +5175,7 @@ static bool regmatch(
* We get here only if there's trouble -- normally "case END" is
* the terminating point.
*/
- IEMSG(_(e_re_corr));
+ iemsg(_(e_re_corr));
#ifdef REGEXP_DEBUG
printf("Premature EOL\n");
#endif
@@ -5195,7 +5197,7 @@ static regitem_T *regstack_push(regstate_T state, char_u *scan)
regitem_T *rp;
if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) {
- EMSG(_(e_maxmempat));
+ emsg(_(e_maxmempat));
return NULL;
}
ga_grow(&regstack, sizeof(regitem_T));
@@ -5268,7 +5270,7 @@ regrepeat (
case SIDENT:
case SIDENT + ADD_NL:
while (count < maxcount) {
- if (vim_isIDc(PTR2CHAR(scan)) && (testval || !ascii_isdigit(*scan))) {
+ if (vim_isIDc(utf_ptr2char(scan)) && (testval || !ascii_isdigit(*scan))) {
MB_PTR_ADV(scan);
} else if (*scan == NUL) {
if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline
@@ -5325,7 +5327,7 @@ regrepeat (
case SFNAME:
case SFNAME + ADD_NL:
while (count < maxcount) {
- if (vim_isfilec(PTR2CHAR(scan)) && (testval || !ascii_isdigit(*scan))) {
+ if (vim_isfilec(utf_ptr2char(scan)) && (testval || !ascii_isdigit(*scan))) {
MB_PTR_ADV(scan);
} else if (*scan == NUL) {
if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline
@@ -5363,7 +5365,7 @@ regrepeat (
if (got_int) {
break;
}
- } else if (vim_isprintc(PTR2CHAR(scan)) == 1
+ } else if (vim_isprintc(utf_ptr2char(scan)) == 1
&& (testval || !ascii_isdigit(*scan))) {
MB_PTR_ADV(scan);
} else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) {
@@ -5391,7 +5393,7 @@ do_class:
if (got_int) {
break;
}
- } else if ((l = (*mb_ptr2len)(scan)) > 1) {
+ } else if ((l = utfc_ptr2len(scan)) > 1) {
if (testval != 0) {
break;
}
@@ -5506,12 +5508,12 @@ do_class:
/* Safety check (just in case 'encoding' was changed since
* compiling the program). */
- if ((len = (*mb_ptr2len)(opnd)) > 1) {
+ if ((len = utfc_ptr2len(opnd)) > 1) {
if (rex.reg_ic) {
cf = utf_fold(utf_ptr2char(opnd));
}
- while (count < maxcount && (*mb_ptr2len)(scan) >= len) {
- for (i = 0; i < len; ++i) {
+ while (count < maxcount && utfc_ptr2len(scan) >= len) {
+ for (i = 0; i < len; i++) {
if (opnd[i] != scan[i]) {
break;
}
@@ -5580,7 +5582,7 @@ do_class:
break;
default: // Oh dear. Called inappropriately.
- IEMSG(_(e_re_corr));
+ iemsg(_(e_re_corr));
#ifdef REGEXP_DEBUG
printf("Called regrepeat with op code %d\n", OP(p));
#endif
@@ -5630,7 +5632,7 @@ static int prog_magic_wrong(void)
}
if (UCHARAT(((bt_regprog_T *)prog)->program) != REGMAGIC) {
- EMSG(_(e_re_corr));
+ emsg(_(e_re_corr));
return true;
}
return false;
@@ -5811,8 +5813,8 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e
if (bytelen != NULL)
*bytelen = 0;
for (;; ) {
- /* Since getting one line may invalidate the other, need to make copy.
- * Slow! */
+ // Since getting one line may invalidate the other, need to make copy.
+ // Slow!
if (rex.line != reg_tofree) {
len = (int)STRLEN(rex.line);
if (reg_tofree == NULL || len >= (int)reg_tofreelen) {
@@ -6445,9 +6447,9 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n)
return result;
}
-/***************************************************************
-* regsub stuff *
-***************************************************************/
+////////////////////////////////////////////////////////////////
+// regsub stuff //
+////////////////////////////////////////////////////////////////
/* This stuff below really confuses cc on an SGI -- webb */
@@ -6512,9 +6514,10 @@ char_u *regtilde(char_u *source, int magic)
memmove(tmpsub, newsub, (size_t)len);
/* interpret tilde */
memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);
- /* copy postfix */
- if (!magic)
- ++p; /* back off \ */
+ // copy postfix
+ if (!magic) {
+ p++; // back off backslash
+ }
STRCPY(tmpsub + len + prevlen, p + 1);
if (newsub != source) /* already allocated newsub */
@@ -6530,7 +6533,7 @@ char_u *regtilde(char_u *source, int magic)
if (*p == '\\' && p[1]) { // skip escaped characters
p++;
}
- p += (*mb_ptr2len)(p) - 1;
+ p += utfc_ptr2len(p) - 1;
}
}
@@ -6687,7 +6690,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
// Be paranoid...
if ((source == NULL && expr == NULL) || dest == NULL) {
- EMSG(_(e_null));
+ emsg(_(e_null));
return 0;
}
if (prog_magic_wrong())
@@ -6941,7 +6944,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
}
} else if (*s == NUL) { // we hit NUL.
if (copy) {
- IEMSG(_(e_re_damg));
+ iemsg(_(e_re_damg));
}
goto exit;
} else {
@@ -7227,7 +7230,7 @@ regprog_T *vim_regcomp(char_u *expr_arg, int re_flags)
regname[newengine]);
#endif
} else {
- EMSG(_(
+ emsg(_(
"E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be used "));
regexp_engine = AUTOMATIC_ENGINE;
}
@@ -7261,7 +7264,7 @@ regprog_T *vim_regcomp(char_u *expr_arg, int re_flags)
fprintf(f, "Syntax error in \"%s\"\n", expr);
fclose(f);
} else
- EMSG2("(NFA) Could not open \"%s\" to write !!!",
+ semsg("(NFA) Could not open \"%s\" to write !!!",
BT_REGEXP_DEBUG_LOG_NAME);
}
#endif
@@ -7300,8 +7303,8 @@ static void report_re_switch(char_u *pat)
{
if (p_verbose > 0) {
verbose_enter();
- MSG_PUTS(_("Switching to backtracking RE engine for pattern: "));
- MSG_PUTS(pat);
+ msg_puts(_("Switching to backtracking RE engine for pattern: "));
+ msg_puts((char *)pat);
verbose_leave();
}
}
@@ -7326,7 +7329,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col,
// Cannot use the same prog recursively, it contains state.
if (rmp->regprog->re_in_use) {
- EMSG(_(e_recursive));
+ emsg(_(e_recursive));
return false;
}
rmp->regprog->re_in_use = true;
@@ -7423,7 +7426,7 @@ long vim_regexec_multi(
// Cannot use the same prog recursively, it contains state.
if (rmp->regprog->re_in_use) {
- EMSG(_(e_recursive));
+ emsg(_(e_recursive));
return false;
}
rmp->regprog->re_in_use = true;