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.c102
1 files changed, 52 insertions, 50 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 24dc86e034..7bc1af9004 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() */
@@ -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 */
@@ -2835,21 +2835,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 +2866,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 +3153,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 +3483,7 @@ static long bt_regexec_both(char_u *line,
/* Be paranoid... */
if (prog == NULL || line == NULL) {
- IEMSG(_(e_null));
+ iemsg(_(e_null));
goto theend;
}
@@ -4729,7 +4730,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 +4768,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 +4816,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 +5174,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 +5196,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));
@@ -5580,7 +5581,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 +5631,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 +5812,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 +6446,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 +6513,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 */
@@ -6687,7 +6689,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 +6943,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 +7229,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 +7263,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 +7302,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 +7328,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 +7425,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;