aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/syntax.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
commit1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch)
treecd08258054db80bb9a11b1061bb091c70b76926a /src/nvim/syntax.c
parenteaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.gz
rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.bz2
rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.zip
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'src/nvim/syntax.c')
-rw-r--r--src/nvim/syntax.c283
1 files changed, 131 insertions, 152 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 49b63ad324..11282ea170 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -1,19 +1,18 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
// syntax.c: code for syntax highlighting
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include "nvim/ascii.h"
+#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
+#include "nvim/cmdexpand_defs.h"
#include "nvim/drawscreen.h"
#include "nvim/eval.h"
#include "nvim/eval/typval_defs.h"
@@ -21,30 +20,31 @@
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/fold.h"
+#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/gettext.h"
#include "nvim/globals.h"
#include "nvim/hashtab.h"
-#include "nvim/highlight_defs.h"
+#include "nvim/highlight.h"
#include "nvim/highlight_group.h"
#include "nvim/indent_c.h"
-#include "nvim/macros.h"
+#include "nvim/macros_defs.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/option_defs.h"
+#include "nvim/option_vars.h"
#include "nvim/optionstr.h"
#include "nvim/os/input.h"
#include "nvim/path.h"
-#include "nvim/pos.h"
+#include "nvim/pos_defs.h"
#include "nvim/profile.h"
#include "nvim/regexp.h"
#include "nvim/runtime.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
-#include "nvim/types.h"
-#include "nvim/vim.h"
+#include "nvim/types_defs.h"
+#include "nvim/vim_defs.h"
static bool did_syntax_onoff = false;
@@ -58,7 +58,13 @@ static bool did_syntax_onoff = false;
#define SPO_LC_OFF 6 // leading context offset
#define SPO_COUNT 7
-static char e_illegal_arg[] = N_("E390: Illegal argument: %s");
+static const char e_illegal_arg[] = N_("E390: Illegal argument: %s");
+static const char e_contains_argument_not_accepted_here[]
+ = N_("E395: Contains argument not accepted here");
+static const char e_invalid_cchar_value[]
+ = N_("E844: Invalid cchar value");
+static const char e_trailing_char_after_rsb_str_str[]
+ = N_("E890: Trailing char after ']': %s]%s");
// The patterns that are being searched for are stored in a syn_pattern.
// A match item consists of one pattern.
@@ -114,7 +120,7 @@ typedef struct state_item {
int si_end_idx; // group ID for end pattern or zero
int si_ends; // if match ends before si_m_endpos
int si_attr; // attributes in this state
- long si_flags; // HL_HAS_EOL flag in this state, and
+ int si_flags; // HL_HAS_EOL flag in this state, and
// HL_SKIP* for si_next_list
int si_seqnr; // sequence number
int si_cchar; // substitution character for conceal
@@ -231,8 +237,6 @@ static keyentry_T dumkey;
#define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char *)&dumkey)))
#define HI2KE(hi) HIKEY2KE((hi)->hi_key)
-// -V:HI2KE:782
-
// To reduce the time spent in keepend(), remember at which level in the state
// stack the first item with "keepend" is present. When "-1", there is no
// "keepend" on the stack.
@@ -257,7 +261,7 @@ static lpos_T next_match_m_endpos; // position for end of next match
static lpos_T next_match_h_startpos; // pos. for highl. start of next match
static lpos_T next_match_h_endpos; // pos. for highl. end of next match
static int next_match_idx; // index of matched item
-static long next_match_flags; // flags for next match
+static int next_match_flags; // flags for next match
static lpos_T next_match_eos_pos; // end of start pattn (start region)
static lpos_T next_match_eoe_pos; // pos. for end of end pattern
static int next_match_end_idx; // ID of group for end pattn or zero
@@ -304,11 +308,10 @@ void syn_set_timeout(proftime_T *tm)
// window.
void syntax_start(win_T *wp, linenr_T lnum)
{
- synstate_T *p;
synstate_T *last_valid = NULL;
synstate_T *last_min_valid = NULL;
- synstate_T *sp, *prev = NULL;
- linenr_T parsed_lnum;
+ synstate_T *sp;
+ synstate_T *prev = NULL;
linenr_T first_stored;
int dist;
static varnumber_T changedtick = 0; // remember the last change ID
@@ -359,7 +362,7 @@ void syntax_start(win_T *wp, linenr_T lnum)
// Only do this if lnum is not before and not to far beyond a saved state.
if (INVALID_STATE(&current_state) && syn_block->b_sst_array != NULL) {
// Find last valid saved state before start_lnum.
- for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) {
+ for (synstate_T *p = syn_block->b_sst_first; p != NULL; p = p->sst_next) {
if (p->sst_lnum > lnum) {
break;
}
@@ -423,7 +426,7 @@ void syntax_start(win_T *wp, linenr_T lnum)
if (sp != NULL
&& sp->sst_lnum == current_lnum
&& syn_stack_equal(sp)) {
- parsed_lnum = current_lnum;
+ linenr_T parsed_lnum = current_lnum;
prev = sp;
while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) {
if (sp->sst_lnum <= lnum) {
@@ -503,7 +506,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
int found_flags = 0;
int found_match_idx = 0;
linenr_T found_current_lnum = 0;
- int found_current_col= 0;
+ int found_current_col = 0;
lpos_T found_m_endpos;
colnr_T prev_current_col;
@@ -619,7 +622,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
for (current_lnum = lnum; current_lnum < end_lnum; current_lnum++) {
syn_start_line();
- for (;;) {
+ while (true) {
had_sync_point = syn_finish_line(true);
// When a sync point has been found, remember where, and
// continue to look for another one, further on in the line.
@@ -721,7 +724,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
static void save_chartab(char *chartab)
{
- if (syn_block->b_syn_isk == empty_option) {
+ if (syn_block->b_syn_isk == empty_string_option) {
return;
}
@@ -731,7 +734,7 @@ static void save_chartab(char *chartab)
static void restore_chartab(char *chartab)
{
- if (syn_win->w_s->b_syn_isk != empty_option) {
+ if (syn_win->w_s->b_syn_isk != empty_string_option) {
memmove(syn_buf->b_chartab, chartab, (size_t)32);
}
}
@@ -750,7 +753,7 @@ static int syn_match_linecont(linenr_T lnum)
regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
regmatch.regprog = syn_block->b_syn_linecont_prog;
- int r = syn_regexec(&regmatch, lnum, (colnr_T)0,
+ int r = syn_regexec(&regmatch, lnum, 0,
IF_SYN_TIME(&syn_block->b_syn_linecont_time));
syn_block->b_syn_linecont_prog = regmatch.regprog;
@@ -874,13 +877,11 @@ static void syn_update_ends(bool startofline)
static void syn_stack_free_block(synblock_T *block)
{
- synstate_T *p;
-
if (block->b_sst_array == NULL) {
return;
}
- for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
+ for (synstate_T *p = block->b_sst_first; p != NULL; p = p->sst_next) {
clear_syn_state(p);
}
XFREE_CLEAR(block->b_sst_array);
@@ -907,9 +908,6 @@ void syn_stack_free_all(synblock_T *block)
// Also used to allocate b_sst_array[] for the first time.
static void syn_stack_alloc(void)
{
- synstate_T *to, *from;
- synstate_T *sstp;
-
int len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2;
if (len < SST_MIN_ENTRIES) {
len = SST_MIN_ENTRIES;
@@ -937,12 +935,12 @@ static void syn_stack_alloc(void)
}
assert(len >= 0);
- sstp = xcalloc((size_t)len, sizeof(synstate_T));
+ synstate_T *sstp = xcalloc((size_t)len, sizeof(synstate_T));
- to = sstp - 1;
+ synstate_T *to = sstp - 1;
if (syn_block->b_sst_array != NULL) {
// Move the states from the old array to the new one.
- for (from = syn_block->b_sst_first; from != NULL;
+ for (synstate_T *from = syn_block->b_sst_first; from != NULL;
from = from->sst_next) {
to++;
*to = *from;
@@ -988,16 +986,13 @@ void syn_stack_apply_changes(buf_T *buf)
static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf)
{
- synstate_T *p, *prev, *np;
- linenr_T n;
-
- prev = NULL;
- for (p = block->b_sst_first; p != NULL;) {
+ synstate_T *prev = NULL;
+ for (synstate_T *p = block->b_sst_first; p != NULL;) {
if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) {
- n = p->sst_lnum + buf->b_mod_xlines;
+ linenr_T n = p->sst_lnum + buf->b_mod_xlines;
if (n <= buf->b_mod_bot) {
// this state is inside the changed area, remove it
- np = p->sst_next;
+ synstate_T *np = p->sst_next;
if (prev == NULL) {
block->b_sst_first = np;
} else {
@@ -1034,7 +1029,7 @@ static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf)
/// @return true if at least one entry was freed.
static bool syn_stack_cleanup(void)
{
- synstate_T *p, *prev;
+ synstate_T *prev;
disptick_T tick;
int dist;
bool retval = false;
@@ -1056,7 +1051,7 @@ static bool syn_stack_cleanup(void)
tick = syn_block->b_sst_lasttick;
bool above = false;
prev = syn_block->b_sst_first;
- for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) {
+ for (synstate_T *p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) {
if (prev->sst_lnum + dist > p->sst_lnum) {
if (p->sst_tick > syn_block->b_sst_lasttick) {
if (!above || p->sst_tick < tick) {
@@ -1072,7 +1067,7 @@ static bool syn_stack_cleanup(void)
// Go through the list to make the entries for the oldest tick at an
// interval of several lines.
prev = syn_block->b_sst_first;
- for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) {
+ for (synstate_T *p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) {
if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) {
// Move this entry from used list to free list
prev->sst_next = p->sst_next;
@@ -1098,10 +1093,8 @@ static void syn_stack_free_entry(synblock_T *block, synstate_T *p)
// Returns NULL when there is no entry or the first entry is after "lnum".
static synstate_T *syn_stack_find_entry(linenr_T lnum)
{
- synstate_T *p, *prev;
-
- prev = NULL;
- for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) {
+ synstate_T *prev = NULL;
+ for (synstate_T *p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) {
if (p->sst_lnum == lnum) {
return p;
}
@@ -1201,7 +1194,7 @@ static synstate_T *store_current_state(void)
}
for (i = 0; i < sp->sst_stacksize; i++) {
bp[i].bs_idx = CUR_STATE(i).si_idx;
- bp[i].bs_flags = (int)CUR_STATE(i).si_flags;
+ bp[i].bs_flags = CUR_STATE(i).si_flags;
bp[i].bs_seqnr = CUR_STATE(i).si_seqnr;
bp[i].bs_cchar = CUR_STATE(i).si_cchar;
bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch);
@@ -1218,7 +1211,6 @@ static synstate_T *store_current_state(void)
// Copy a state stack from "from" in b_sst_array[] to current_state;
static void load_current_state(synstate_T *from)
{
- int i;
bufstate_T *bp;
clear_current_state();
@@ -1231,7 +1223,7 @@ static void load_current_state(synstate_T *from)
} else {
bp = from->sst_union.sst_stack;
}
- for (i = 0; i < from->sst_stacksize; i++) {
+ for (int i = 0; i < from->sst_stacksize; i++) {
CUR_STATE(i).si_idx = bp[i].bs_idx;
CUR_STATE(i).si_flags = bp[i].bs_flags;
CUR_STATE(i).si_seqnr = bp[i].bs_seqnr;
@@ -1263,7 +1255,6 @@ static void load_current_state(synstate_T *from)
static bool syn_stack_equal(synstate_T *sp)
{
bufstate_T *bp;
- reg_extmatch_T *six, *bsx;
// First a quick check if the stacks have the same size end nextlist.
if (sp->sst_stacksize != current_state.ga_len
@@ -1289,8 +1280,8 @@ static bool syn_stack_equal(synstate_T *sp)
}
// When the extmatch pointers are different, the strings in them can
// still be the same. Check if the extmatch references are equal.
- bsx = bp[i].bs_extmatch;
- six = CUR_STATE(i).si_extmatch;
+ reg_extmatch_T *bsx = bp[i].bs_extmatch;
+ reg_extmatch_T *six = CUR_STATE(i).si_extmatch;
// If one of the extmatch pointers is NULL the states are different.
if (bsx == NULL || six == NULL) {
break;
@@ -1501,10 +1492,11 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con
lpos_T eos_pos; // end-of-start match (start region)
lpos_T eoe_pos; // end-of-end pattern
int end_idx; // group ID for end pattern
- stateitem_T *cur_si, *sip = NULL;
+ stateitem_T *cur_si;
+ stateitem_T *sip = NULL;
int startcol;
int endcol;
- long flags;
+ int flags;
int cchar;
int16_t *next_list;
bool found_match; // found usable match
@@ -1877,7 +1869,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con
current_attr = sip->si_attr;
current_id = sip->si_id;
current_trans_id = sip->si_trans_id;
- current_flags = (int)sip->si_flags;
+ current_flags = sip->si_flags;
current_seqnr = sip->si_seqnr;
current_sub_char = sip->si_cchar;
break;
@@ -2071,7 +2063,7 @@ static void check_state_ends(void)
int had_extend;
cur_si = &CUR_STATE(current_state.ga_len - 1);
- for (;;) {
+ while (true) {
if (cur_si->si_ends
&& (cur_si->si_m_endpos.lnum < current_lnum
|| (cur_si->si_m_endpos.lnum == current_lnum
@@ -2107,7 +2099,7 @@ static void check_state_ends(void)
// handle next_list, unless at end of line and no "skipnl" or
// "skipempty"
current_next_list = cur_si->si_next_list;
- current_next_flags = (int)cur_si->si_flags;
+ current_next_flags = cur_si->si_flags;
if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))
&& syn_getcurline()[current_col] == NUL) {
current_next_list = NULL;
@@ -2355,12 +2347,10 @@ static void pop_current_state(void)
/// @param end_endpos return: end of end pattern match
/// @param end_idx return: group ID for end pat. match, or 0
/// @param start_ext submatches from the start pattern
-static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos,
- long *flagsp, lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext)
+static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, int *flagsp,
+ lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext)
{
- colnr_T matchcol;
- synpat_T *spp, *spp_skip;
- int start_idx;
+ synpat_T *spp_skip;
int best_idx;
regmmatch_T regmatch;
regmmatch_T best_regmatch; // startpos/endpos of best match
@@ -2377,14 +2367,14 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
// Check for being called with a START pattern.
// Can happen with a match that continues to the next line, because it
// contained a region.
- spp = &(SYN_ITEMS(syn_block)[idx]);
+ synpat_T *spp = &(SYN_ITEMS(syn_block)[idx]);
if (spp->sp_type != SPTYPE_START) {
*hl_endpos = *startpos;
return;
}
// Find the SKIP or first END pattern after the last START pattern.
- for (;;) {
+ while (true) {
spp = &(SYN_ITEMS(syn_block)[idx]);
if (spp->sp_type != SPTYPE_START) {
break;
@@ -2404,14 +2394,14 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
unref_extmatch(re_extmatch_in);
re_extmatch_in = ref_extmatch(start_ext);
- matchcol = startpos->col; // start looking for a match at sstart
- start_idx = idx; // remember the first END pattern.
+ colnr_T matchcol = startpos->col; // start looking for a match at sstart
+ int start_idx = idx; // remember the first END pattern.
best_regmatch.startpos[0].col = 0; // avoid compiler warning
// use syntax iskeyword option
save_chartab(buf_chartab);
- for (;;) {
+ while (true) {
// Find end pattern that matches first after "matchcol".
best_idx = -1;
for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; idx++) {
@@ -2470,7 +2460,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
break;
}
- line = ml_get_buf(syn_buf, startpos->lnum, false);
+ line = ml_get_buf(syn_buf, startpos->lnum);
int line_len = (int)strlen(line);
// take care of an empty match or negative offset
@@ -2606,7 +2596,7 @@ static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp
if (result->lnum > syn_buf->b_ml.ml_line_count) {
col = 0;
} else if (off != 0) {
- base = ml_get_buf(syn_buf, result->lnum, false);
+ base = ml_get_buf(syn_buf, result->lnum);
p = base + col;
if (off > 0) {
while (off-- > 0 && *p != NUL) {
@@ -2648,10 +2638,10 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s
if (result->lnum > syn_buf->b_ml.ml_line_count) {
// a "\n" at the end of the pattern may take us below the last line
result->lnum = syn_buf->b_ml.ml_line_count;
- col = (int)strlen(ml_get_buf(syn_buf, result->lnum, false));
+ col = (int)strlen(ml_get_buf(syn_buf, result->lnum));
}
if (off != 0) {
- base = ml_get_buf(syn_buf, result->lnum, false);
+ base = ml_get_buf(syn_buf, result->lnum);
p = base + col;
if (off > 0) {
while (off-- && *p != NUL) {
@@ -2670,7 +2660,7 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s
/// Get current line in syntax buffer.
static char *syn_getcurline(void)
{
- return ml_get_buf(syn_buf, current_lnum, false);
+ return ml_get_buf(syn_buf, current_lnum);
}
// Call vim_regexec() to find a match with "rmp" in "syn_buf".
@@ -2693,7 +2683,7 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T
}
rmp->rmm_maxcol = (colnr_T)syn_buf->b_p_smc;
- long r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, syn_tm, &timed_out);
+ int r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, syn_tm, &timed_out);
if (l_syn_time_on) {
pt = profile_end(pt);
@@ -2708,7 +2698,7 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T
}
if (timed_out && !syn_win->w_s->b_syn_slow) {
syn_win->w_s->b_syn_slow = true;
- msg(_("'redrawtime' exceeded, syntax highlighting disabled"));
+ msg(_("'redrawtime' exceeded, syntax highlighting disabled"), 0);
}
if (r > 0) {
@@ -2730,7 +2720,7 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T
/// @param cur_si item at the top of the stack
/// @param ccharp conceal substitution char
static int check_keyword_id(char *const line, const int startcol, int *const endcolp,
- long *const flagsp, int16_t **const next_listp,
+ int *const flagsp, int16_t **const next_listp,
stateitem_T *const cur_si, int *const ccharp)
{
// Find first character after the keyword. First character was already
@@ -2811,9 +2801,9 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing)
next = skiptowhite(arg);
if (*arg == NUL) {
if (curwin->w_s->b_syn_conceal) {
- msg("syntax conceal on");
+ msg("syntax conceal on", 0);
} else {
- msg("syntax conceal off");
+ msg("syntax conceal off", 0);
}
} else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) {
curwin->w_s->b_syn_conceal = true;
@@ -2838,9 +2828,9 @@ static void syn_cmd_case(exarg_T *eap, int syncing)
next = skiptowhite(arg);
if (*arg == NUL) {
if (curwin->w_s->b_syn_ic) {
- msg("syntax case ignore");
+ msg("syntax case ignore", 0);
} else {
- msg("syntax case match");
+ msg("syntax case match", 0);
}
} else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) {
curwin->w_s->b_syn_ic = false;
@@ -2865,9 +2855,9 @@ static void syn_cmd_foldlevel(exarg_T *eap, int syncing)
if (*arg == NUL) {
switch (curwin->w_s->b_syn_foldlevel) {
case SYNFLD_START:
- msg("syntax foldlevel start"); break;
+ msg("syntax foldlevel start", 0); break;
case SYNFLD_MINIMUM:
- msg("syntax foldlevel minimum"); break;
+ msg("syntax foldlevel minimum", 0); break;
default:
break;
}
@@ -2904,11 +2894,11 @@ static void syn_cmd_spell(exarg_T *eap, int syncing)
next = skiptowhite(arg);
if (*arg == NUL) {
if (curwin->w_s->b_syn_spell == SYNSPL_TOP) {
- msg("syntax spell toplevel");
+ msg("syntax spell toplevel", 0);
} else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) {
- msg("syntax spell notoplevel");
+ msg("syntax spell notoplevel", 0);
} else {
- msg("syntax spell default");
+ msg("syntax spell default", 0);
}
} else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) {
curwin->w_s->b_syn_spell = SYNSPL_TOP;
@@ -2939,11 +2929,11 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing)
arg = skipwhite(arg);
if (*arg == NUL) {
msg_puts("\n");
- if (curwin->w_s->b_syn_isk != empty_option) {
+ if (curwin->w_s->b_syn_isk != empty_string_option) {
msg_puts("syntax iskeyword ");
- msg_outtrans(curwin->w_s->b_syn_isk);
+ msg_outtrans(curwin->w_s->b_syn_isk, 0);
} else {
- msg_outtrans(_("syntax iskeyword not set"));
+ msg_outtrans(_("syntax iskeyword not set"), 0);
}
} else {
if (STRNICMP(arg, "clear", 5) == 0) {
@@ -3230,7 +3220,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing)
}
if (!syntax_present(curwin)) {
- msg(_(msg_no_items));
+ msg(_(msg_no_items), 0);
return;
}
@@ -3422,7 +3412,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only)
msg_putchar(' ');
if (spp->sp_sync_idx >= 0) {
msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s)
- [spp->sp_sync_idx].sp_syn.id - 1));
+ [spp->sp_sync_idx].sp_syn.id - 1), 0);
} else {
msg_puts("NONE");
}
@@ -3435,15 +3425,13 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only)
(void)syn_list_header(did_header, 0, id, true);
msg_puts_attr("links to", attr);
msg_putchar(' ');
- msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1));
+ msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1), 0);
}
}
static void syn_list_flags(struct name_list *nlist, int flags, int attr)
{
- int i;
-
- for (i = 0; nlist[i].flag != 0; i++) {
+ for (int i = 0; nlist[i].flag != 0; i++) {
if (flags & nlist[i].flag) {
msg_puts_attr(nlist[i].name, attr);
msg_putchar(' ');
@@ -3458,7 +3446,7 @@ static void syn_list_cluster(int id)
// slight hack: roughly duplicate the guts of syn_list_header()
msg_putchar('\n');
- msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name);
+ msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name, 0);
if (msg_col >= endcol) { // output at least one space
endcol = msg_col + 1;
@@ -3495,9 +3483,9 @@ static void put_id_list(const char *const name, const int16_t *const list, const
int scl_id = *p - SYNID_CLUSTER;
msg_putchar('@');
- msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name);
+ msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name, 0);
} else {
- msg_outtrans(highlight_group_name(*p - 1));
+ msg_outtrans(highlight_group_name(*p - 1), 0);
}
if (p[1]) {
msg_putchar(',');
@@ -3517,9 +3505,9 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const
msg_puts_attr("matchgroup", attr);
msg_putchar('=');
if (last_matchgroup == 0) {
- msg_outtrans("NONE");
+ msg_outtrans("NONE", 0);
} else {
- msg_outtrans(highlight_group_name(last_matchgroup - 1));
+ msg_outtrans(highlight_group_name(last_matchgroup - 1), 0);
}
msg_putchar(' ');
}
@@ -3536,7 +3524,7 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const
}
}
msg_putchar(sepchars[i]);
- msg_outtrans(spp->sp_pattern);
+ msg_outtrans(spp->sp_pattern, 0);
msg_putchar(sepchars[i]);
// output any pattern options
@@ -3550,7 +3538,7 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const
msg_putchar(','); // Separate with commas.
}
msg_puts(spo_name_tab[i]);
- const long n = spp->sp_offsets[i];
+ const int n = spp->sp_offsets[i];
if (i != SPO_LC_OFF) {
if (spp->sp_off_flags & mask) {
msg_putchar('s');
@@ -3646,7 +3634,7 @@ static bool syn_list_keywords(const int id, const hashtab_T *const ht, bool did_
prev_skipempty = (kp->flags & HL_SKIPEMPTY);
}
}
- msg_outtrans((char *)kp->keyword);
+ msg_outtrans(kp->keyword, 0);
}
}
}
@@ -3677,7 +3665,7 @@ static void syn_clear_keyword(int id, hashtab_T *ht)
if (kp_next == NULL) {
hash_remove(ht, hi);
} else {
- hi->hi_key = (char *)KE2HIKEY(kp_next);
+ hi->hi_key = KE2HIKEY(kp_next);
}
} else {
kp_prev->ke_next = kp_next;
@@ -3732,9 +3720,9 @@ static void add_keyword(char *const name, const int id, const int flags,
{
char name_folded[MAXKEYWLEN + 1];
const char *const name_ic = (curwin->w_s->b_syn_ic)
- ? str_foldcase(name, (int)strlen(name), name_folded,
- sizeof(name_folded))
- : name;
+ ? str_foldcase(name, (int)strlen(name), name_folded,
+ sizeof(name_folded))
+ : name;
keyentry_T *const kp = xmalloc(offsetof(keyentry_T, keyword) + strlen(name_ic) + 1);
STRCPY(kp->keyword, name_ic);
@@ -3750,9 +3738,9 @@ static void add_keyword(char *const name, const int id, const int flags,
const hash_T hash = hash_hash(kp->keyword);
hashtab_T *const ht = (curwin->w_s->b_syn_ic)
- ? &curwin->w_s->b_keywtab_ic
- : &curwin->w_s->b_keywtab;
- hashitem_T *const hi = hash_lookup(ht, (const char *)kp->keyword,
+ ? &curwin->w_s->b_keywtab_ic
+ : &curwin->w_s->b_keywtab;
+ hashitem_T *const hi = hash_lookup(ht, kp->keyword,
strlen(kp->keyword), hash);
// even though it looks like only the kp->keyword member is
@@ -3766,7 +3754,7 @@ static void add_keyword(char *const name, const int id, const int flags,
} else {
// keyword already exists, prepend to list
kp->ke_next = HI2KE(hi);
- hi->hi_key = (char *)KE2HIKEY(kp);
+ hi->hi_key = KE2HIKEY(kp);
}
}
@@ -3803,7 +3791,6 @@ static char *get_group_name(char *arg, char **name_end)
/// Return NULL for any error;
static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, int skip)
{
- char *gname_start, *gname;
int syn_id;
int len = 0;
char *p;
@@ -3841,7 +3828,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
opt->flags |= HL_CONCEAL;
}
- for (;;) {
+ while (true) {
// This is used very often when a large number of keywords is defined.
// Need to skip quickly when no option name is found.
// Also avoid tolower(), it's slow.
@@ -3877,7 +3864,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
if (flagtab[fidx].argtype == 1) {
if (!opt->has_cont_list) {
- emsg(_("E395: contains argument not accepted here"));
+ emsg(_(e_contains_argument_not_accepted_here));
return NULL;
}
if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) {
@@ -3895,8 +3882,8 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
// cchar=?
*conceal_char = utf_ptr2char(arg + 6);
arg += utfc_ptr2len(arg + 6) - 1;
- if (!vim_isprintc_strict(*conceal_char)) {
- emsg(_("E844: invalid cchar value"));
+ if (!vim_isprintc(*conceal_char)) {
+ emsg(_(e_invalid_cchar_value));
return NULL;
}
arg = skipwhite(arg + 7);
@@ -3910,12 +3897,12 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
emsg(_("E393: group[t]here not accepted here"));
return NULL;
}
- gname_start = arg;
+ char *gname_start = arg;
arg = skiptowhite(arg);
if (gname_start == arg) {
return NULL;
}
- gname = xstrnsave(gname_start, (size_t)(arg - gname_start));
+ char *gname = xstrnsave(gname_start, (size_t)(arg - gname_start));
if (strcmp(gname, "NONE") == 0) {
*opt->sync_idx = NONE_IDX;
} else {
@@ -3976,7 +3963,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
int sgl_id = 1;
char *group_name_end;
char *rest;
- char *errormsg = NULL;
+ const char *errormsg = NULL;
int prev_toplvl_grp;
int prev_syn_inc_tag;
bool source = false;
@@ -4029,7 +4016,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
prev_toplvl_grp = curwin->w_s->b_syn_topgrp;
curwin->w_s->b_syn_topgrp = sgl_id;
if (source
- ? do_source(eap->arg, false, DOSO_NONE) == FAIL
+ ? do_source(eap->arg, false, DOSO_NONE, NULL) == FAIL
: source_runtime(eap->arg, DIP_ALL) == FAIL) {
semsg(_(e_notopen), eap->arg);
}
@@ -4114,8 +4101,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
}
if (p[1] == ']') {
if (p[2] != NUL) {
- semsg(_("E890: trailing char after ']': %s]%s"),
- kw, &p[2]);
+ semsg(_(e_trailing_char_after_rsb_str_str), kw, &p[2]);
goto error;
}
kw = p + 1;
@@ -4400,8 +4386,8 @@ static void syn_cmd_region(exarg_T *eap, int syncing)
SYN_ITEMS(curwin->w_s)[idx] = *(ppp->pp_synp);
SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing;
SYN_ITEMS(curwin->w_s)[idx].sp_type =
- (item == ITEM_START) ? SPTYPE_START :
- (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END;
+ (item == ITEM_START) ? SPTYPE_START
+ : (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END;
SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags;
SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = (int16_t)syn_id;
SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag =
@@ -4678,7 +4664,7 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing)
}
scl_id -= SYNID_CLUSTER;
- for (;;) {
+ while (true) {
if (STRNICMP(rest, "add", 3) == 0
&& (ascii_iswhite(rest[3]) || rest[3] == '=')) {
opt_len = 3;
@@ -4736,17 +4722,15 @@ static void init_syn_patterns(void)
/// @return a pointer to the next argument, or NULL in case of an error.
static char *get_syn_pattern(char *arg, synpat_T *ci)
{
- char *end;
int *p;
int idx;
- char *cpo_save;
// need at least three chars
if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) {
return NULL;
}
- end = skip_regexp(arg + 1, *arg, true);
+ char *end = skip_regexp(arg + 1, *arg, true);
if (*end != *arg) { // end delimiter not found
semsg(_("E401: Pattern delimiter not found: %s"), arg);
return NULL;
@@ -4755,8 +4739,8 @@ static char *get_syn_pattern(char *arg, synpat_T *ci)
ci->sp_pattern = xstrnsave(arg + 1, (size_t)(end - arg) - 1);
// Make 'cpoptions' empty, to avoid the 'l' flag
- cpo_save = p_cpo;
- p_cpo = empty_option;
+ char *cpo_save = p_cpo;
+ p_cpo = empty_string_option;
ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC);
p_cpo = cpo_save;
@@ -4913,7 +4897,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
// Make 'cpoptions' empty, to avoid the 'l' flag
cpo_save = p_cpo;
- p_cpo = empty_option;
+ p_cpo = empty_string_option;
curwin->w_s->b_syn_linecont_prog =
vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC);
p_cpo = cpo_save;
@@ -5047,7 +5031,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list,
regmatch.rm_ic = true;
id = 0;
for (int i = highlight_num_groups(); --i >= 0;) {
- if (vim_regexec(&regmatch, highlight_group_name(i), (colnr_T)0)) {
+ if (vim_regexec(&regmatch, highlight_group_name(i), 0)) {
if (round == 2) {
// Got more items than expected; can happen
// when adding items that match:
@@ -5057,7 +5041,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list,
xfree(retval);
round = 1;
} else {
- retval[count] = (int16_t)(i + 1); // -V522
+ retval[count] = (int16_t)(i + 1);
}
}
count++;
@@ -5145,7 +5129,6 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in
{
int retval;
int16_t *scl_list;
- int16_t item;
int16_t id = ssp->id;
static int depth = 0;
int r;
@@ -5181,7 +5164,7 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in
// If the first item is "ALLBUT", return true if "id" is NOT in the
// contains list. We also require that "id" is at the same ":syn include"
// level as the list.
- item = *list;
+ int16_t item = *list;
if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) {
if (item < SYNID_TOP) {
// ALL or ALLBUT: accept all groups in the same file
@@ -5291,16 +5274,13 @@ void ex_syntax(exarg_T *eap)
void ex_ownsyntax(exarg_T *eap)
{
- char *old_value;
- char *new_value;
-
if (curwin->w_s == &curwin->w_buffer->b_s) {
curwin->w_s = xcalloc(1, sizeof(synblock_T));
hash_init(&curwin->w_s->b_keywtab);
hash_init(&curwin->w_s->b_keywtab_ic);
// TODO(vim): Keep the spell checking as it was.
curwin->w_p_spell = false; // No spell checking
- // make sure option values are "empty_option" instead of NULL
+ // make sure option values are "empty_string_option" instead of NULL
clear_string_option(&curwin->w_s->b_p_spc);
clear_string_option(&curwin->w_s->b_p_spf);
clear_string_option(&curwin->w_s->b_p_spl);
@@ -5309,7 +5289,7 @@ void ex_ownsyntax(exarg_T *eap)
}
// Save value of b:current_syntax.
- old_value = get_var_value("b:current_syntax");
+ char *old_value = get_var_value("b:current_syntax");
if (old_value != NULL) {
old_value = xstrdup(old_value);
}
@@ -5318,7 +5298,7 @@ void ex_ownsyntax(exarg_T *eap)
apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, true, curbuf);
// Move value of b:current_syntax to w:current_syntax.
- new_value = get_var_value("b:current_syntax");
+ char *new_value = get_var_value("b:current_syntax");
if (new_value != NULL) {
set_internal_string_var("w:current_syntax", new_value);
}
@@ -5379,7 +5359,7 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
}
// (part of) subcommand already typed
- const char *p = (const char *)skiptowhite(arg);
+ const char *p = skiptowhite(arg);
if (*p == NUL) {
return;
}
@@ -5483,10 +5463,9 @@ int get_syntax_info(int *seqnrp)
int syn_get_concealed_id(win_T *wp, linenr_T lnum, colnr_T col)
{
int seqnr;
- int syntax_flags;
(void)syn_get_id(wp, lnum, col, false, NULL, false);
- syntax_flags = get_syntax_info(&seqnr);
+ int syntax_flags = get_syntax_info(&seqnr);
if (syntax_flags & HL_CONCEAL) {
return seqnr;
@@ -5595,7 +5574,7 @@ static void syntime_clear(void)
synpat_T *spp;
if (!syntax_present(curwin)) {
- msg(_(msg_no_items));
+ msg(_(msg_no_items), 0);
return;
}
for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; idx++) {
@@ -5633,7 +5612,7 @@ static int syn_compare_syntime(const void *v1, const void *v2)
static void syntime_report(void)
{
if (!syntax_present(curwin)) {
- msg(_(msg_no_items));
+ msg(_(msg_no_items), 0);
return;
}
@@ -5649,11 +5628,11 @@ static void syntime_report(void)
p = GA_APPEND_VIA_PTR(time_entry_T, &ga);
p->total = spp->sp_time.total;
total_total = profile_add(total_total, spp->sp_time.total);
- p->count = (int)spp->sp_time.count;
- p->match = (int)spp->sp_time.match;
- total_count += (int)spp->sp_time.count;
+ p->count = spp->sp_time.count;
+ p->match = spp->sp_time.match;
+ total_count += spp->sp_time.count;
p->slowest = spp->sp_time.slowest;
- proftime_T tm = profile_divide(spp->sp_time.total, (int)spp->sp_time.count);
+ proftime_T tm = profile_divide(spp->sp_time.total, spp->sp_time.count);
p->average = tm;
p->id = spp->sp_syn.id;
p->pattern = spp->sp_pattern;
@@ -5687,7 +5666,7 @@ static void syntime_report(void)
msg_puts(profile_msg(p->average));
msg_puts(" ");
msg_advance(50);
- msg_outtrans(highlight_group_name(p->id - 1));
+ msg_outtrans(highlight_group_name(p->id - 1), 0);
msg_puts(" ");
msg_advance(69);
@@ -5700,7 +5679,7 @@ static void syntime_report(void)
if (len > (int)strlen(p->pattern)) {
len = (int)strlen(p->pattern);
}
- msg_outtrans_len(p->pattern, len);
+ msg_outtrans_len(p->pattern, len, 0);
msg_puts("\n");
}
ga_clear(&ga);